Exemple #1
0
        public async Task <Tuple <int, int> > TakeTurn(Player player)
        {
//            Quip(player.Name + " " + player.PlayerType() + " take your turn!");
            hexWanted = null;


            // Next, check to see if the player is the same as the last one
            if (player == _lastPlayer)
            {
                Quip("FOUL!  Taking a second turn!");
                GameEndsOnFoul();
            }

            if (_lastPlay == null)
            {
                Quip("Last play is null.");
            }
            hexWanted = await Task.Run(() => player.SelectHex(_lastPlay));

            if (hexWanted == null)
            {
                Quip("FOUL!  No hex was selected.  Player LOSES.");
                GameEndsOnFoul();
            }
            else
            {
                var success = Board.TakeHex(new Hex(hexWanted.Item1, hexWanted.Item2), CurrentPlayer().PlayerNumber);

                if (!success)
                {
                    Quip("FOUL!  Player tried to take a hex that was blocked!");
                    GameEndsOnFoul();
                }
                else
                {
                    if (CurrentPlayer().PlayerNumber == 1)
                    {
                        lastHexForPlayer1 = hexWanted;
                    }
                    else
                    {
                        lastHexForPlayer2 = hexWanted;
                    }

                    _lastPlay = hexWanted;
                    var playerMove = new Move
                    {
                        player = CurrentPlayer(),
                        hex    = hexWanted
                    };
                    AllGameMoves.Add(playerMove);
                    var moveArgs = new PlayerMadeMoveArgs
                    {
                        player = CurrentPlayer().PlayerNumber,
                        move   = new Tuple <int, int>(hexWanted.Item1, hexWanted.Item2)
                    };
                    //OnPlayerMadeMove(moveArgs);

                    LookForWinner();
                }
            }

            return(new Tuple <int, int>(hexWanted.Item1, hexWanted.Item2));
        }