Exemple #1
0
        /// <summary>
        /// Play a move and check for victory
        /// </summary>
        /// <param name="move">The move to be played</param>
        /// <param name="player">The player to play the move</param>
        /// <returns>False if play was invalid</returns>
        private bool Play(Move move, Player player)
        {
            Contract.Requires(move != null, "move must not be null");
            // Check that the move is valid
            if (!move.SlotToPlay.OwnerTile.HasEmptySlotWithMatchingCube(move.CardToPlay, move.SlotToPlay))
            {
                Output("That card doesn't match a cube.");
                return false;
            }
            else
            {
                move.SlotToPlay.SetCard(move.CardToPlay);   // Put the card in the slot
                player.Hand.RemoveCard(move.CardToPlay);    // Remove it from their hand

                player.DealHand(ref deck, ref discardPile);  // Add appropriate amount of cards

                // Score the tiles
                for (int i = 0; i < tiles.Count; i++)
                    // Tile is full, score it
                    if (tiles[i].Full)
                    {
                        // Find the winner
                        CardSlot.Position result = tiles[i].Score(); // Above or below
                        Player winner;
                        // If the side above had the best score, robot wins
                        if (result == CardSlot.Position.Above)
                        {
                            winner = robot;
                        }
                        // If the side above had the best score, human wins
                        else if (result == CardSlot.Position.Below)
                        {
                            winner = human;
                        }
                        // If both scores were the same, the person to play that card wins
                        else
                        {
                            winner = WhoseTurn;
                        }
                        this.Invalidate();  // Draw the card played by the winner

                        InformationBox(winner + " won " + tiles[i] + "!", "Tile has been won"); // Let 'em know!

                        // Reset the tile
                        tiles[i].Flip();
                        winner.AddCubes(tiles[i].Cubes);
                        tiles[i].RemoveCubes();

                        // Refill the tile
                        // If we have run out of cubes, remove the tile.
                        if (!FillTile(tiles[i]))
                            tiles.Remove(tiles[i]);

                        // Discard the cards
                        List<Card> discardedCards = tiles[i].DiscardCards();
                        // Add them to the discard pile
                        foreach (Card c in discardedCards)
                            discardPile.Add(c);

                        // Give the winner a trophy if they deserve it
                        List<Trophy> trophiesWon = winner.ChanceAtVictory();
                        if (trophiesWon.Count > 0)
                            RemoveAvailableTrophies(trophiesWon);

                        // End game?
                        if (winner.Trophies.Count >= 3)
                        {
                            InformationBox(winner + " wins the game!", "Game over!");
                            LockGame();
                        }
                    }

                return true;
            }
        }