示例#1
0
        public string Move(Movement movement)
        {
            var  message = new StringBuilder();
            bool hit     = false;
            bool valid   = false;
            var  point   = CalculateNewPosition(movement);

            if (IsValidMove(point))
            {
                valid = true;
                GameState.Moves++;
                GameState.Player.Position = point;
            }

            if (GameState.GameBoard.Squares.Any(square => square.Position.Equals(point) && square.HasMine))
            {
                hit = true;
                GameState.Player.RemoveLife();
                GameState.GameBoard.RemoveMine(point);
            }

            if (!valid)
            {
                message.AppendLine("Cannot move that way");
                return(message.ToString());
            }

            message.AppendLine(string.Format("Moved to: {0}", BoardSquare.ToDisplayPosition(GameState.Player.Position)));

            // valid move but hit
            if (hit)
            {
                GameState.Score--;
                message.AppendLine("Mine Hit!");
            }
            // valid move no hit increment score
            else
            {
                GameState.Score++;
            }

            message.AppendLine(string.Format("Lives: {0}", GameState.Player.Lives));
            message.AppendLine(string.Format("Moves: {0}", GameState.Moves));

            // check if player has reached the top of the board
            if (GameState.HasWon)
            {
                message.AppendLine();
                message.AppendLine("You Win!");
            }

            return(message.ToString());
        }
示例#2
0
 void PrintPlayerPosition()
 {
     Console.WriteLine();
     Console.WriteLine(string.Format("Player at position: {0}", BoardSquare.ToDisplayPosition(_gameController.PlayerPosition)));
 }