Hey guys, I'm new to all this but basically I've been given the task to create a simple C# board game using the console screen.

The game consists of a 36 square board and 2 players (player 1 & player 2). Both the players take it in turns to roll a single die and the number displayed indicates how many space along the board they can move. Once a player passes the original starting point they are rewarded 1 point, the first player to receive 5 points wins. The console screen should display (for both player each time a die is rolled):
player1
rolled: (number rolled)
board position (new board position)
number of points: (number of laps currently achieved)

I've come up with how I think the program should work but I have come to a bit of a dead end in terms of coding it, any help would be great appreciated.

set player1globalposition = 0
set player2globalposition = 0
set turn = 0

i want to loop until player1globalposition >= 36*5 or player2globalposition >= 36*5

i want to increment the turn every time so turn = turn + 1

if turn mod 2 = 0 then

//must be player1's turn
display player1 + "Rolled: " + display roll
"New board position: " + display player1globalposition mod 36
"Completed board laps: " + display (player1globalposition/36).floor
player1globalposition = player1globlposition + roll

else

//must be player2's turn
display player2 + "Rolled: " + display roll
"New board position: " + display player2globalposition mod 36
"Completed board laps: " + display (player2globalposition/36).floor
player2globalposition = player2globlposition + roll

^then go back and loop for the next turn

disply winner

this seems like a nice "get to learn the logic" application...

it'll be a quick and easy one with experience, show some code and ill help... ill be doing one any1 which works, but you need to show some of your own effort.

the logic you mentioned above …

if you are familiar with classes, use a class it will simple out alot of extra trouble

ive completed the game, :) ill post my code if you need it, but i strongly suggest completing it yourself

ive added a few features, like using a class as well as u can give each player a name, etc.

also ive coded to re-use as much code …

:O really already? lol, yeah I'm just trying to code it all at the minute but if I get really stuck would you be kind enough to post it so I can work it out?

yea most definitely, but itll be quick to go through my code, ive coded it …

The better thing to do would be to let us know where you get stuck so we can help you *learn* specifics, rather than just getting a finished product and plugging that code into your project. I'm not saying that's exactly what you'll do, but it seems to be a …

## All 27 Replies

this seems like a nice "get to learn the logic" application...

it'll be a quick and easy one with experience, show some code and ill help... ill be doing one any1 which works, but you need to show some of your own effort.

the logic you mentioned above is ok, there are several ways of doing this, just find the best way for you, and code away.

This is the code I have so far:

``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Board_Game
{
class Program
{
static void Main(string[] args)
{
//Welcome screen & instructions.
Console.WriteLine("\n\t\t\t  *WELCOME*\n\t\tTO THE START 2 FINISH BOARD GAME\n\nInstructions: \n-Both players shall take it in turns to roll the dice.\n-The number rolled shall indicate how many spaces the player moves.\n-There are 36 spaces on the board.\n-Every time a player passes start they shall be awarded 1 point.\n-The first player to collect 5 points WINS! ");
int diceroll;

int player1_position = 0;
int player2_position = 0;
int turn = 0;

while (player1_position >= 36 * 5 || player2_position >= 36 * 5);
turn = turn + 1;

Console.Write("\nPress ENTER to roll the dice...");
Console.Clear();

Random random = new Random();
diceroll = random.Next(1, 6);

Console.WriteLine("You rolled a " + diceroll);

}
}
}``````

if you are familiar with classes, use a class it will simple out alot of extra trouble

ive completed the game, :) ill post my code if you need it, but i strongly suggest completing it yourself

ive added a few features, like using a class as well as u can give each player a name, etc.

also ive coded to re-use as much code as possible, which helps alot when using bigger apps

:O really already? lol, yeah I'm just trying to code it all at the minute but if I get really stuck would you be kind enough to post it so I can work it out?

:O really already? lol, yeah I'm just trying to code it all at the minute but if I get really stuck would you be kind enough to post it so I can work it out?

yea most definitely, but itll be quick to go through my code, ive coded it quite cleanly if i must say so myself lol

:D

The better thing to do would be to let us know where you get stuck so we can help you *learn* specifics, rather than just getting a finished product and plugging that code into your project. I'm not saying that's exactly what you'll do, but it seems to be a habit of many around this site.

The better thing to do would be to let us know where you get stuck so we can help you *learn* specifics, rather than just getting a finished product and plugging that code into your project. I'm not saying that's exactly what you'll do, but it seems to be a habit of many around this site.

i completely agree, :)

Yeah I'll let you guys know if/where I get stuck and hopefully you will be able to point out the error and help me to understand my mistake. Thanks for all your help so far thought guys.

This the code I have so far:

``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Board_Game
{
class Program
{
static void Main(string[] args)
{
//Welcom screen & instructions.
Console.WriteLine("\n\t\t\t  *WELCOME*\n\t\tTO THE START 2 FINISH BOARD GAME\n\nInstructions: \n-Both players shall take it in turns to roll the dice.\n-The number rolled shall indicate how many spaces the player moves.\n-There are 36 spaces on the board.\n-Every time a player passes start they shall be awarded 1 point.\n-The first player to collect 5 points WINS! ");
int diceroll;

int player1_position = 0;
int player2_position = 0;
int turn = 0;

while (player1_position >= 36 * 5 || player2_position >= 36 * 5);
turn = turn + 1;

if ((turn % 2) == 0)
{
Random random = new Random();
diceroll = random.Next(1, 6);
player1_position = player1_position + diceroll;

Console.WriteLine("\nPlayer 1 \nRolled: " + diceroll);
Console.WriteLine("New board position: " + player1_position);
Console.WriteLine("Completed board laps: " + player1_position / 36);
}

else

{
Random random = new Random();
diceroll = random.Next(1, 6);
player2_position = player2_position + diceroll;

Console.WriteLine("\nPlayer 2 \nRolled: " + diceroll);
Console.WriteLine("New board position: " + player2_position);
Console.WriteLine("Completed board laps: " + player2_position / 36);
}

}
}
}``````

The problem I'm having is that the program only executes once and displays only player 2s results and then terminates. I need some way of displaying both players results and then carrying on the loop till one of the players gain 5 points. Any ideas to where I'm going wrong or what I'm missing out?

``[B]while (player1_position >= 36 * 5 || player2_position >= 36 * 5);[/B]``

change the > around to <

like so

``while (player1_position [B]<[/B]= 36 * 5 || player2_position [B]<[/B]= 36 * 5);``

oh yeah cheers, I don't know why I was using greater than :S but now it only displays the game instructions and non of the players rolls, positions, laps etc. Any thoughts?

and another thing...

{ after your while condition eg

``````while (player1_position >= 36 * 5 || player2_position >= 36 * 5);
{``````

yea read my above post :P

It works! just need to get it to display the winner now.
Thank you ever so much for you're help. I think I'm going to save this as a back up once I've finished and then try rewriting it using classes like you suggested.

its a pleasure :)

I've just noticed something when executing the program, it doesn't stop once 1 of the players reaches 5 laps it waits till both player have reached 5, any thoughts to why this is?

change the || in your while statement to &&

any chance of you posting you version I'm getting a little confused with classes.

Ebay, does the compiler/IDE you're using have an integrated debugger?

I believe so, I'm using Visual studio 2008

I left the app at work, would you be able to wait till tomorrow?
sorry didnt think i was going to need it today

yeah no worries that's fine :)

Ah, good. For a lot of your issues you may find that just running your app in debug (F5 to stop at the first breakpoint or F10/F11 to step through from the beginning) will help you find those small errors. Learning the debugger is HUGE in development rather than just trying to guess what you did wrong from the output it gives you.

Ah cheers, I'll have a go at using that and see how I get on.

any chance you'd be kind enough to post your version with classes?

Here is the project, using classes, sorry for taking so long to post, i explained why in the pm :)

enjoy, mark as solved plz

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.