public PlayerEvents ApplyGameRules(BoardResults boardResults, IPlayer player)
        {
            //Change Player state
            //Can I Move, if so increase number of moves
            if (boardResults.ValidMove)
            {
                player.AddMove();
            }
            else
            {
                //If not stay where i am
                player.ResetPosition();
            }
            //Did I hit a mine? If  so lose a life
            if (boardResults.HitAMine)
            {
                player.RemoveLive();
            }


            var currentState = new PlayerEvents
            {
                numberOfLives = player.NoOfLives,
                numberOfMoves = player.NoOfMoves,
                resultMessage = boardResults.Text
            };

            //Check to see if GameOver
            //Check if you still have lives or have reached the end
            if (
                player.NoOfLives == 0)
            {
                currentState.resultMessage   = "Out of Lives Ouch";
                currentState.resultPosition += "Dead ";
                currentState.GameOver        = true;
            }
            else if (boardResults.ReachedTheEnd)
            {
                currentState.resultMessage   = "You have made it safely out";
                currentState.resultPosition += "Free ";
                currentState.GameOver        = true;
            }
            else
            {
                if (boardResults.HitAMine)
                {
                    currentState.resultMessage += " You Hit A Mine! ";
                }
                currentState.resultPosition += "Position " +
                                               player.FriendlyPosition();
                currentState.GameOver = false;
            }

            return(currentState);
        }
Ejemplo n.º 2
0
        public BoardResults IsThisPositionValid(IPosition position)
        {
            //Is position valid on the board
            if (position.Vertical > 0 && position.Vertical <= board.VerticalAxis &&
                position.Horizontal >= 0 && position.Horizontal < board.HorizontalArray.Length)
            {
                return(new BoardResults("Valid Move",
                                        true,
                                        true,
                                        true));
            }

            if (position.Vertical <= 0 && position.Horizontal >= 0 && position.Horizontal < board.HorizontalArray.Length)
            {
                return(new BoardResults("Bottom Reached",
                                        true,
                                        false,
                                        false));
            }

            if (position.Vertical > board.VerticalAxis && position.Horizontal < board.HorizontalArray.Length && position.Horizontal >= 0)
            {
                return(new BoardResults("Top Reached",
                                        true,
                                        false,
                                        false));
            }
            if (position.Horizontal <= 0 && position.Vertical > 0 && position.Vertical <= board.VerticalAxis)
            {
                return(new BoardResults("Left Reached",
                                        false,
                                        true,
                                        false));
            }

            if (position.Horizontal == board.HorizontalArray.Length && position.Vertical > 0 && position.Vertical <= board.VerticalAxis)
            {
                var returnValue = new BoardResults("Reached The End",
                                                   false,
                                                   true,
                                                   true)
                {
                    ReachedTheEnd = true
                };


                return(returnValue);
            }


            throw new ArgumentException("Invalid Position passed that Board does not understand");
        }