I'm doing my first console application at school which is a Cheese Racer Game. Sixteen pieces of cheese are distributed on the board by up to 4 players. Two pieces of cheese cannot be placed on this same square, which is decided by another method which returns a bool. Here is what I have so far.
do
{
for (int i = 0; i < NoOfPlayers; i++)
{
string YourTurnCheese = "Your turn, " + players[i].Name + "!";
Console.SetCursorPosition((Console.WindowWidth - YourTurnCheese.Length) / 2, Console.CursorTop);
Console.WriteLine(YourTurnCheese);
do
{
string XCoordinate = "X Coordinate: ";
Console.SetCursorPosition((Console.WindowWidth - XCoordinate.Length) / 2, Console.CursorTop);
Console.Write(XCoordinate);
int.TryParse(Console.ReadLine(), out CheeseX);
if (CheeseX > 7 || CheeseX < 0)
Console.WriteLine("Please enter a number from 0 to 7");
else
break;
} while (true);
do
{
string YCoordinate = "Y Coordinate: ";
Console.SetCursorPosition((Console.WindowWidth - YCoordinate.Length) / 2, Console.CursorTop);
Console.Write(YCoordinate);
int.TryParse(Console.ReadLine(), out CheeseY);
if (CheeseY > 7 || CheeseY < 0)
Console.WriteLine("Please enter a number from 0 to 7");
else
break;
} while (true);
if (!TryToPlaceCheese(CheeseX, CheeseY))
{
string CheeseisHere = "There is already a piece of cheese at this location.";
Console.SetCursorPosition((Console.WindowWidth - CheeseisHere.Length) / 2, Console.CursorTop);
Console.WriteLine(CheeseisHere);
}
else
{
Board[CheeseX, CheeseY] = SquareState.gotCheese;
TotalCheesePlaced = (TotalCheesePlaced + 1);
}
}
} while (TotalCheesePlaced < 16);
I'm not sure how to make it reject empty input into the console. Also, when there is already a cheese piece on the location given, it states that, but moves onto the next player instead of looping back. Can I get some help with fixing that code please? I'm still pretty new to all of this so please be gentle :)
boolthat you're not checking - and, if it fails, it set the parameter value to one that falls within your valid range.i--; continue;insideif(!TryToPlaceCheese(CheeseX, CheeseY))