Skip to content

Commit

Permalink
Fixed bug which allowed program to carry on after player rolled tacti…
Browse files Browse the repository at this point in the history
…cs dice and went at or over board threshold.
  • Loading branch information
redleek committed Dec 7, 2014
1 parent 292ab38 commit 4e88c35
Showing 1 changed file with 42 additions and 10 deletions.
52 changes: 42 additions & 10 deletions TacticalSpaceCheeseRacer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct Player
};

// Define constants we will want to use throughout the program.
const int MAX_PLAYERS = 4;
const int MAX_PLAYERS = 5;
const int MIN_PLAYERS = 2;
const int BOARD_UP_BOUND = 64;
const int BOARD_LWR_BOUND = 0;
Expand Down Expand Up @@ -235,7 +235,7 @@ static void PrintAllPositions()
Console.WriteLine("Players and their positions:");
for (int playercount = 0; playercount < no_of_players; playercount++)
{
Console.WriteLine("{0}) {1} \t- {2}", playercount + 1, players[playercount].name, players[playercount].position);
Console.WriteLine("{0}) {1} \t\t- {2}", playercount + 1, players[playercount].name, players[playercount].position);
}
}

Expand Down Expand Up @@ -290,7 +290,25 @@ static void PlayerTurn(int playerno)
{
Console.WriteLine("Because you rolled a 6, you can throw the tactics dice for another player:");
PrintAllPositions();
TacticalRoll(ReadNumber("Please enter a player number: ", MAX_PLAYERS, MIN_PLAYERS) - 1);
TacticalRoll(ReadNumber("Please enter a player number: ", no_of_players, 1) - 1);
}
}

/// <summary>
/// Check if the current player has won the game/at or over the board limit.
/// </summary>
/// <param name="playerno">The number of the current player.</param>
/// <returns>Wether or not the player has won.</returns>
static bool CheckWin(int playerno)
{
if (players[playerno].position >= BOARD_UP_BOUND)
{
Console.WriteLine("{0} has won the game!", players[playerno].name);
return true;
}
else
{
return false;
}
}

Expand Down Expand Up @@ -362,7 +380,7 @@ static void Power5(int playerno)
do
{
PrintAllPositions();
int newposition = ReadNumber("Please enter a player number to swap to: ", no_of_players, 1) - 1;
int newposition = ReadNumber("Please enter a player number to move to: ", no_of_players, 1) - 1;
if (newposition == playerno)
{
Console.WriteLine("You cannot move to the position you are already on.");
Expand All @@ -384,7 +402,7 @@ static void Power6(int playerno)
do
{
PrintAllPositions();
int playerno2swap = ReadNumber("Please enter a player number to swap with: ", 4, 1) - 1;
int playerno2swap = ReadNumber("Please enter a player number to swap with: ", no_of_players, 1) - 1;
if (playerno2swap == playerno)
{
Console.WriteLine("You cannot swap position with yourself.");
Expand Down Expand Up @@ -473,12 +491,14 @@ static void Main(string[] args)
for (int playercount = 0; playercount < no_of_players; playercount++)
{
PlayerTurn(playercount);
// Check if the current player has won.
if (players[playercount].position >= BOARD_UP_BOUND)
// Check if the current player (or player we have rolled the six power for) has won.
for (int playercount2 = 0; playercount2 < no_of_players; playercount2++)
{
gamewon = true;
Console.WriteLine("{0} has won the game!", players[playercount].name);
break;
if (CheckWin(playercount2))
{
gamewon = true;
break;
}
}

// Check if the player is on a cheese square
Expand All @@ -499,6 +519,12 @@ static void Main(string[] args)
}
}

if (CheckWin(playercount))
{
gamewon = true;
break;
}

// Ask if the player wants to roll the tactics dice.
if (!players[playercount].tact_roll_used)
{
Expand All @@ -508,6 +534,12 @@ static void Main(string[] args)
}
}

if (CheckWin(playercount))
{
gamewon = true;
break;
}

// Reset for end of turn.
if (players[playercount].tact_roll_used)
{
Expand Down

0 comments on commit 4e88c35

Please sign in to comment.