static void Main(string[] args) { Player[] players = new Player[NUM_PLAYERS]; for (int i = 0; i < NUM_PLAYERS; i++) { players[i] = getPlayerInfo(i); } string sort; do { sort = MethodLibraries.readString("Do you want to sort by name or by scores? (enter N or S): ").ToUpper(); } while (!(sort.Equals("N") || sort.Equals("S"))); if (sort.Equals("N")) { players = sortPlayersByName(players); } else { players = sortPlayersByScore(players); } for (int i = 0; i < NUM_PLAYERS; i++) { Console.WriteLine(players[i].Name + ": " + players[i].Score); } }
static void Main(string[] args) { string answer; do { answer = MethodLibraries.readString("Would you like to do the Countdown Calculator (A), the Reverse Countdown Calculator (B), or the Seconds to Calculator (C)? ").ToUpper(); } while (!(answer == "A" || answer == "B" || answer == "C")); switch (answer) { case "A": CountdownCalculator(); break; case "B": ReverseCountdownCalculator(); break; case "C": SecondsToCalculator(); break; default: break; } }
private static Player getPlayerInfo(int i) { Player player = new Player(); player.Name = MethodLibraries.readString($"Enter Player {i + 1}'s name: "); player.Score = MethodLibraries.readInt($"Enter Player {i + 1}'s score: ", 0, 500, "Score too large. Please enter a score between 0 and 500"); return(player); }
static void ResetGame() { numPlayers = MethodLibraries.readInt("How many players? ", 1, 4); players = new Player[numPlayers]; for (int i = 0; i < numPlayers; i++) { players[i].Name = MethodLibraries.readString("Enter a name for this player: "); players[i].X = 0; players[i].Y = 0; } }
static void CountdownCalculator() { Console.WriteLine("Countdown Timer Calculator by Wendy Breiding"); Console.WriteLine("Version 1.0"); int numHours = MethodLibraries.readInt("Enter the number of hours: ", 0, 23); int numMinutes = MethodLibraries.readInt("enter the number of minutes: ", 0, 59); int numSeconds = MethodLibraries.readInt("Enter the number of seconds: ", 0, 59); int result = numHours * 3600 + numMinutes * 60 + numSeconds; Console.WriteLine($"The total number of seconds is: {result}"); }
static void ReverseCountdownCalculator() { Console.WriteLine("Reverse Countdown Timer Calculator by Wendy Breiding"); Console.WriteLine("Version 1.0"); int numSeconds = MethodLibraries.readInt("Enter the number of seconds: ", 0, 999999); int resultHours = numSeconds / 3600; int remainingSeconds = numSeconds - resultHours * 3600; int resultMinutes = remainingSeconds / 60; remainingSeconds = remainingSeconds - resultMinutes * 60; Console.WriteLine($"This is equal to {resultHours} hours, {resultMinutes} minutes and {remainingSeconds} seconds"); }
static void SecondsToCalculator() { Console.WriteLine("Seconds to Calculator by Wendy Breiding"); Console.WriteLine("Version 1.0"); DateTime date; bool isValid; do { int hour = MethodLibraries.readInt("Enter the hour: ", 0, 23); int day = MethodLibraries.readInt("Enter the day: ", 1, 31); int month = MethodLibraries.readInt("Enter the month: ", 1, 12); int year = MethodLibraries.readInt("Enter the year: ", 2017, 9999); isValid = DateTime.TryParse($"{month}/{day}/{year} {hour}:00:00", out date); if (!isValid) { Console.WriteLine("You did not enter a valid date."); } } while (!isValid); int result = (int)date.Subtract(DateTime.Now).TotalSeconds; Console.WriteLine($"The total number of seconds is {result}."); }
private static void PlayerTurn(int PlayerNo) { int roll; if (TESTMODE) { roll = PresetDiceThrow(); } else { roll = RandomDiceThrow(); } Console.WriteLine($"{players[PlayerNo].Name} rolled a {roll}"); int[] position = { players[PlayerNo].X, players[PlayerNo].Y }; int direction = board[position[0], position[1]]; switch (direction) { case (int)directions.right: position[0] = position[0] + roll; while (RocketInSquare(position[0], position[1])) { Bounce(position); } if (position[0] <= 7 && position[1] <= 7) { players[PlayerNo].X = position[0]; players[PlayerNo].Y = position[1]; if (CheesePowerSquare(position[0], position[1])) { int bottomPosition; int CheesePowerAction = MethodLibraries.readInt("Do you want to Explode another players Engine (1) or Roll the Dice Again (2)? ", 1, 2); if (CheesePowerAction == 1) { int PlayerToExplode = MethodLibraries.readInt($"Which Player would you like to explore (0-{numPlayers - 1})? ", 0, numPlayers - 1); do { bottomPosition = MethodLibraries.readInt($"{players[PlayerToExplode].Name}, which position would you like to move to (0-7)? ", 0, 7); } while (RocketInSquare(0, bottomPosition)); players[PlayerToExplode].X = 0; players[PlayerToExplode].Y = bottomPosition; } else { PlayerTurn(PlayerNo); } } } else { Console.WriteLine($"{players[PlayerNo].Name} rolled off the board, so didn't move."); } break; case (int)directions.up: position[1] = position[1] + roll; while (RocketInSquare(position[0], position[1])) { Bounce(position); } if (position[0] <= 7 && position[1] <= 7) { players[PlayerNo].X = position[0]; players[PlayerNo].Y = position[1]; if (CheesePowerSquare(position[0], position[1])) { int bottomPosition; int CheesePowerAction = MethodLibraries.readInt("Do you want to Explode another players Engine (1) or Roll the Dice Again (2)? ", 1, 2); if (CheesePowerAction == 1) { int PlayerToExplode = MethodLibraries.readInt($"Which Player would you like to explore (0-{numPlayers - 1})? ", 0, numPlayers - 1); do { bottomPosition = MethodLibraries.readInt($"{players[PlayerToExplode].Name}, which position would you like to move to (0-7)? ", 0, 7); } while (RocketInSquare(0, bottomPosition)); players[PlayerToExplode].X = 0; players[PlayerToExplode].Y = bottomPosition; } else { PlayerTurn(PlayerNo); } } } break; case (int)directions.down: position[1] = position[1] - roll; while (RocketInSquare(position[0], position[1])) { Bounce(position); } if (position[0] <= 7 && position[1] <= 7) { players[PlayerNo].X = position[0]; players[PlayerNo].Y = position[1]; if (CheesePowerSquare(position[0], position[1])) { int bottomPosition; int CheesePowerAction = MethodLibraries.readInt("Do you want to Explode another players Engine (1) or Roll the Dice Again (2)? ", 1, 2); if (CheesePowerAction == 1) { int PlayerToExplode = MethodLibraries.readInt($"Which Player would you like to explore (0-{numPlayers - 1})? ", 0, numPlayers - 1); do { bottomPosition = MethodLibraries.readInt($"{players[PlayerToExplode].Name}, which position would you like to move to (0-7)? ", 0, 7); } while (RocketInSquare(0, bottomPosition)); players[PlayerToExplode].X = 0; players[PlayerToExplode].Y = bottomPosition; } else { PlayerTurn(PlayerNo); } } } break; case (int)directions.left: position[0] = position[0] - roll; while (RocketInSquare(position[0], position[1])) { Bounce(position); } if (position[0] <= 7 && position[1] <= 7) { players[PlayerNo].X = position[0]; players[PlayerNo].Y = position[1]; if (CheesePowerSquare(position[0], position[1])) { int bottomPosition; int CheesePowerAction = MethodLibraries.readInt("Do you want to Explode another players Engine (1) or Roll the Dice Again (2)? ", 1, 2); if (CheesePowerAction == 1) { int PlayerToExplode = MethodLibraries.readInt($"Which Player would you like to explore (0-{numPlayers - 1})? ", 0, numPlayers - 1); do { bottomPosition = MethodLibraries.readInt($"{players[PlayerToExplode].Name}, which position would you like to move to (0-7)? ", 0, 7); } while (RocketInSquare(0, bottomPosition)); players[PlayerToExplode].X = 0; players[PlayerToExplode].Y = bottomPosition; } else { PlayerTurn(PlayerNo); } } } break; default: //error Console.WriteLine($"Player {PlayerNo} did not move."); break; } if (position[0] == 7 && position[1] == 7) { gameOver = true; winner = PlayerNo; } }