public void IllegalMove() { // Create a game logic instance with a set [known] playing board layout. LandminesLogic landminesLogic = new LandminesLogic(createASetPlayingBoard()); // Try to move off the playing board. MoveResult moveResult = landminesLogic.MovePlayer(Move.L); Assert.AreEqual(Resource.IllegalMove, moveResult.Message); }
public void LooseASetGame() { // Create a game logic instance with a set [known] playing board layout. LandminesLogic landminesLogic = new LandminesLogic(createASetPlayingBoard()); // Loose a game. landminesLogic.MovePlayer(Move.R); landminesLogic.MovePlayer(Move.U); landminesLogic.MovePlayer(Move.L); landminesLogic.MovePlayer(Move.U); landminesLogic.MovePlayer(Move.U); MoveResult moveResult = landminesLogic.MovePlayer(Move.U); Assert.AreEqual(Resource.YouLose, moveResult.Message); }
static void Main(string[] args) { // Instantiate the landmines logic to play a game. LandminesLogic landminesLogic = new LandminesLogic(); bool gameOver = false; // Display start message to the user. Console.WriteLine(Resource.Welcome); Console.WriteLine(); do { // Display move message to the user. Console.Write(Resource.Move); // Get the move from the player. string moveStr = Console.ReadLine(); Move move; // Convert the input into a move instruction. if (Enum.TryParse<Move>(moveStr, true, out move)) { // Move the player. MoveResult moveResult = landminesLogic.MovePlayer(move); // Display message to the user. Console.WriteLine(moveResult.Message); Console.WriteLine(); // Is the game over? gameOver = moveResult.GameOver; } else { Console.WriteLine(Resource.InvalidInput); } } while (!gameOver); // Stop console from automatically closing. Console.ReadLine(); }