Ejemplo n.º 1
0
 private GameManager()
 {
     gameViewModel.GameResult = "Game Over";
     Player1 = new PlayerViewModel(1, "Player A")
     {
         EatPizzasMethod = EatPizzas,
         IsCurrentPlayer = false,
         IsVisible       = false
     };
     Player2 = new PlayerViewModel(2, "Player B")
     {
         EatPizzasMethod = EatPizzas,
         IsCurrentPlayer = false,
         IsVisible       = false
     };
 }
Ejemplo n.º 2
0
        public void NewGame(Boolean fullGame)
        {
            this.fullGame            = fullGame;
            gameViewModel.GameResult = String.Empty;
            gameViewModel.State      = GameModel.GameStates.Play;
            Player1 = new PlayerViewModel(1, "Player A")
            {
                EatPizzasMethod = EatPizzas,
                IsCurrentPlayer = true,
                IsVisible       = true
            };
            Player2 = new PlayerViewModel(2, "Player B")
            {
                EatPizzasMethod = EatPizzas,
                IsCurrentPlayer = false,
                IsVisible       = true
            };
            Random r = new Random(DateTime.Now.Millisecond);

            gameViewModel.NrOfPizzas = r.Next(5, 30);
        }
Ejemplo n.º 3
0
        public bool EatPizzas(Int32 numberOfEatenPizzas)
        {
            if (gameViewModel.State != GameModel.GameStates.Play)
            {
                return(false);
            }

            PlayerViewModel currentPlayer = Player1.IsCurrentPlayer ? Player1 : Player2;
            PlayerViewModel otherPlayer   = GetOtherPlayer(currentPlayer.PlayerId);

            if (!currentPlayer.IsCurrentPlayer || otherPlayer.IsCurrentPlayer)
            {
                return(false);
            }

            if (numberOfEatenPizzas > gameViewModel.NrOfPizzas)
            {
                return(false);
            }

            currentPlayer.LastNumberOfEatenPizzas = numberOfEatenPizzas;

            if (numberOfEatenPizzas == 0)
            {
                SwapPlayers(currentPlayer, otherPlayer);
                return(true);
            }

            gameViewModel.NrOfPizzas -= numberOfEatenPizzas;

            if (fullGame)
            {
                if (gameViewModel.NrOfPizzas == 0)
                {
                    gameViewModel.GameResult = "Winner is " + otherPlayer.PlayerName;
                    currentPlayer.State      = PlayerModel.States.Dead;
                    gameViewModel.State      = GameModel.GameStates.GameOver;
                    currentPlayer.IsVisible  = false;
                    otherPlayer.IsVisible    = false;
                    return(true);
                }
            }
            else
            {
                if (gameViewModel.NrOfPizzas == 0 || gameViewModel.NrOfPizzas == 1)
                {
                    gameViewModel.GameResult = "Winner is " + otherPlayer.PlayerName;
                    currentPlayer.State      = PlayerModel.States.Dead;
                    gameViewModel.State      = GameModel.GameStates.GameOver;
                    currentPlayer.IsVisible  = false;
                    otherPlayer.IsVisible    = false;
                    return(true);
                }
                else if (gameViewModel.NrOfPizzas == 2)
                {
                    gameViewModel.GameResult = "Winner is " + currentPlayer.PlayerName;
                    otherPlayer.State        = PlayerModel.States.Dead;
                    gameViewModel.State      = GameModel.GameStates.GameOver;
                    currentPlayer.IsVisible  = false;
                    otherPlayer.IsVisible    = false;
                    return(true);
                }
            }

            SwapPlayers(currentPlayer, otherPlayer);
            return(true);
        }