Exemplo n.º 1
0
        /// <summary>
        /// Refills the player's tray.
        /// </summary>
        /// <param name="tileBag"> The tile bag to fill </param>
        public void DrawTilesToMax(TileBag tileBag)
        {
            // Get count of tiles in tile bar
            int currentTileCount = this.TileBar.Count;

            for (int i = currentTileCount; i < 7; i++)
            {
                Tile drawnTile = new Tile();
                drawnTile = tileBag.DrawRandomTileFromBag();
                if (drawnTile == null)
                {
                    return;
                }

                this.AddTileToBar(drawnTile);
            }
        }
        /// <summary>
        /// Initializes the game components
        /// </summary>
        private void Initialize()
        {
            // Initialize our variables
            this.tileBag          = new TileBag();
            this.placedTileSpaces = new List <Space>();

            // Initialize our dictionary
            this.dictionary = new List <string>();
            this.LoadDictionary();

            // Create an instance of the Spaces class
            this.spaces = new Space[SPACECOUNT];
            for (int i = 0; i < SPACECOUNT; i++)
            {
                // Set the Spaces
                Space tempSpace = new Space();
                tempSpace.SpaceGrid  = (Grid)this.FindName("spaceGrid" + i);
                tempSpace.XYPosition = tempSpace.SpaceGrid.TransformToAncestor(gameGrid).Transform(new Point(0, 0));
                this.spaces[i]       = tempSpace;
            }

            // Initialize the players
            this.players = new List <Player>();

            for (int playerCount = 1; playerCount <= Properties.Settings.Default.PlayerCount; playerCount++)
            {
                Player player = new Player(playerCount);

                // Populate our player's drawn tiles
                player.DrawTilesToMax(this.tileBag);

                // Add the player to the player list
                this.players.Add(player);

                Label scoreLabel = (Label)this.windowGrid.FindName("player" + player.Number + "Score");
                scoreLabel.Visibility = Visibility.Visible;
            }

            // Set the current player
            this.currentPlayer = this.players[0];
            this.ToggleTiles();
            this.isFirstTurn = true;
        }