/// <summary> /// Prints the field and game instructions to the console. /// </summary> /// <param name="field">The field that will be printed</param> public void RenderGameField(IPlayField field) { Console.Clear(); Console.WriteLine("Welcome to “Balloons Pops” game. " + "Please try to pop the balloons. \nUse 'top' to view the top scoreboard,\n" + "'restart' to start a new game and 'exit' to quit the game. \n"); Console.Write(" "); for (byte column = 0; column < field.GetLength(1); column++) { Console.Write(column + " "); } Console.Write("\n "); for (byte column = 0; column < field.GetLength(1) * 2 + 1; column++) { Console.Write("-"); } Console.WriteLine(); for (byte row = 0; row < field.GetLength(0); row++) { Console.Write(row + " | "); for (byte col = 0; col < field.GetLength(1); col++) { if (field[row, col] == 0) { Console.Write(" "); continue; } Console.Write(field[row, col] + " "); } Console.Write("| "); Console.WriteLine(); } Console.Write(" "); for (byte column = 0; column < field.GetLength(1) * 2 + 1; column++) { Console.Write("-"); } Console.WriteLine(); }
/// <summary> /// Method that checks if a given command represents a valid coordinate in the game field /// </summary> /// <param name="commandInput">String containing the command from user. /// If it is not a coordinate, the first letter is capital, the rest are lower case.</param> /// <param name="field">Parameter of type PlayField, representing the playfield of the game</param> /// <returns>Returns true if command is a valid coordinate and false, if it is not</returns> public bool CheckIfCommandIsCoordinate(string commandInput, IPlayField field) { string[] commandWords = commandInput.Split(new Char[]{' ', ',', '_', '.'}, StringSplitOptions.RemoveEmptyEntries); if (commandWords.Length == 2) { byte row = 0; byte col = 0; bool areCoordinates = byte.TryParse(commandWords[0], out row) && byte.TryParse(commandWords[1], out col); if (areCoordinates) { if (0 <= row && row < field.GetLength(0) && 0 <= col && col < field.GetLength(1)) { return true; } } } return false; }
public bool CheckIfCommandIsCoordinate(string commandInput, IPlayField field) { string[] commandWords = commandInput.Split(' '); if (commandWords.Length == 2) { byte row = 0; byte col = 0; bool areCoordinates = byte.TryParse(commandWords[0], out row) && byte.TryParse(commandWords[1], out col); if (areCoordinates) { if (0 <= row && row < field.GetLength(0) && 0 <= col && col < field.GetLength(1)) { return true; } else return false; } else { return false; } } return false; }