Skip to content

Commit

Permalink
Implemented the Six Power and optimised cheese square searching.
Browse files Browse the repository at this point in the history
  • Loading branch information
redleek committed Dec 7, 2014
1 parent 42305c5 commit 7fa30a9
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions TacticalSpaceCheeseRacer/Program.cs
Original file line number Diff line number Diff line change
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} - {2}", playercount + 1, players[playercount].name, players[playercount].position);
Console.WriteLine("{0}) {1}\t- {2}", playercount + 1, players[playercount].name, players[playercount].position);
}
}

Expand Down Expand Up @@ -284,6 +284,14 @@ static void PlayerTurn(int playerno)
Console.WriteLine("{0} rolled a {1}.", players[playerno].name, roll);
players[playerno].position += roll;
PrintPlayerPosition(playerno);

// Check if the dice roll was 6, if so, allow current player to throw the tactics dice for another player.
if (roll == 6)
{
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);
}
}

#region Tactical Dice Methods
Expand All @@ -309,7 +317,7 @@ static void Power2(int playerno)
if (players[playercount].position == current_player_position)
{
players[playercount].position = 0;
Console.WriteLine("{0} has had their engines exploded and are now back to square 0.", players[playercount].name);
Console.WriteLine("{0} has had his/her engines exploded and are now back to square 0.", players[playercount].name);
}
}
}
Expand All @@ -330,10 +338,6 @@ static void Power3(int playerno)
players[playercount].position = 0;
Console.WriteLine("{0} has had their engines exploded and are now back to square 0.", players[playercount].name);
}
else
{
continue;
}
}
}
}
Expand Down Expand Up @@ -400,7 +404,7 @@ static void Power6(int playerno)
/// </summary>
static void TacticalRoll(int playerno)
{
Console.Write("Press enter to roll the tactical dice...");
Console.Write("Press enter to roll the tactical dice... ");
Console.ReadLine();
int roll = 0;
#if DEBUG
Expand Down Expand Up @@ -480,6 +484,12 @@ static void Main(string[] args)
// Check if the player is on a cheese square
for (int item = 0; item < cheese_squares.Length; item++)
{
// Break out early if cheese square position is greater than player position.
if (cheese_squares[item] >= players[playercount].position)
{
break;
}

if (cheese_squares[item] == players[playercount].position)
{
Console.WriteLine("You have landed on a cheese square!");
Expand All @@ -504,7 +514,7 @@ static void Main(string[] args)
players[playercount].tact_roll_used = false;
}

Console.Write("Press enter to continue...");
Console.Write("Press enter to continue... ");
Console.ReadLine();
ResetConsole();
}
Expand Down

0 comments on commit 7fa30a9

Please sign in to comment.