Пример #1
0
 public Tile(Player owner, String value)
 {
     Owner = owner;
     Name = value;
     Button.Text = Name;
     Button.Size = new Size(75, 60);
     Button.Enabled = false;
     hotel = StockCard.Type.None;
 }
Пример #2
0
 public void AddPlayer(Player p)
 {
     if (Players.Count >= 6)
     {
         throw new Exception("Too many players.");
     }
     else
     {
         PlayerOrder.Add(p.Name);
         Players.Add(p.Name, p);
     }
 }
Пример #3
0
        public void updateUI(Player p)
        {
            americaButton.Text = p.numStock(StockCard.Type.American).ToString() + " : " + gm.stockLeft(StockCard.Type.American)
                + " ($" + StockCard.getStockValue(StockCard.Type.American, gm.Board.getHotelChainLength(StockCard.Type.American)) + ")";

            fusionButton.Text = p.numStock(StockCard.Type.Fusion).ToString() + " : " + gm.stockLeft(StockCard.Type.Fusion)
                 + " ($" + StockCard.getStockValue(StockCard.Type.Fusion, gm.Board.getHotelChainLength(StockCard.Type.Fusion)) + ")";

            hydraButton.Text = p.numStock(StockCard.Type.Hydra).ToString() + " : " + gm.stockLeft(StockCard.Type.Hydra)
                 + " ($" + StockCard.getStockValue(StockCard.Type.Hydra, gm.Board.getHotelChainLength(StockCard.Type.Hydra)) + ")";

            phoenixButton.Text = p.numStock(StockCard.Type.Phoenix).ToString() + " : " + gm.stockLeft(StockCard.Type.Phoenix)
                 + " ($" + StockCard.getStockValue(StockCard.Type.Phoenix, gm.Board.getHotelChainLength(StockCard.Type.Phoenix)) + ")";

            quantumButton.Text = p.numStock(StockCard.Type.Quantum).ToString() + " : " + gm.stockLeft(StockCard.Type.Quantum)
                 + " ($" + StockCard.getStockValue(StockCard.Type.Quantum, gm.Board.getHotelChainLength(StockCard.Type.Quantum)) + ")";

            sacksonButton.Text = p.numStock(StockCard.Type.Sackson).ToString() + " : " + gm.stockLeft(StockCard.Type.Sackson)
                 + " ($" + StockCard.getStockValue(StockCard.Type.Sackson, gm.Board.getHotelChainLength(StockCard.Type.Sackson)) + ")";

            zetaButton.Text = p.numStock(StockCard.Type.Zeta).ToString() + " : " + gm.stockLeft(StockCard.Type.Zeta)
                 + " ($" + StockCard.getStockValue(StockCard.Type.Zeta, gm.Board.getHotelChainLength(StockCard.Type.Zeta)) + ")";

            ArrayList temp = gm.Board.GetHotelsOnBoard();
            foreach (StockCard.Type hotel in Enum.GetValues(typeof(StockCard.Type)))
            {
                if (hotel != StockCard.Type.None && !temp.Contains(hotel))
                {
                    hotelToButton(hotel).Enabled = false;
                }
                else if (hotel != StockCard.Type.None)
                {
                    hotelToButton(hotel).Enabled = true;
                }
            }

            enableSpecialButtons(p);

            cashlabel.Text = Constants.cashUILabel + p.Money.ToString();
            stockLeftLabel.Text = Constants.stockLeftUILabel + p.StockLeftToBuy;
            tilesLeftLabel.Text = Constants.tilesLeftUILabel + p.TilesLeftToPlay;

            gm.Board.disableAllTiles();
            TilesList.Items.Clear();
            foreach (Tile t in p.Tiles)
            {
                TilesList.Items.Add(t.Name);
                t.Button.Enabled = true;
            }
        }
Пример #4
0
        public PostMergerChoice(Player p, StockCard.Type overtakingHotel, StockCard.Type overtakenHotel)
        {
            InitializeComponent();
            player = p;
            overtaken = overtakenHotel;
            overtaking = overtakingHotel;

            //set up additional UI based on the player
            questionLabel.Text = p.Name + Constants.PostMergerChoiceUILabel;
            mergeLabel.Text = overtaking.ToString() + " has acquired " + overtaken.ToString() + ".";
            sell1Button.Text = "Sell one (1) " + overtaken.ToString() + " stock for $" +
                StockCard.getStockValue(overtaken, gm.Board.getHotelChainLength(overtaken)) + ".";
            sellAllButton.Text = "Sell all for $" + p.numStock(overtaken) * StockCard.getStockValue(overtaken, gm.Board.getHotelChainLength(overtaken)) + ".";
            trade2Button.Text = "Trade two (2) " + overtaken.ToString() + " stock for one (1) " + overtaking.ToString() + " stock.";
            updateUI();

            // add event listeners to the buttons
            sell1Button.Click += new EventHandler(sell1Button_Click);
            sellAllButton.Click += new EventHandler(sellAllButton_Click);
            trade2Button.Click += new EventHandler(trade2Button_Click);
        }
Пример #5
0
        private void enableSpecialButtons(Player p)
        {
            //Set up specials
            if (p.HasPlayedSpecial)
            {
                foreach (SpecialCard.Type t in Enum.GetValues(typeof(SpecialCard.Type)))
                {
                    SpecialCard.getButton(t).Enabled = false;
                }
            }
            else
            {

                if (p.hasSpecial(SpecialCard.Type.Buy5))
                { SpecialCard.getButton(SpecialCard.Type.Buy5).Enabled = true; }
                else
                { SpecialCard.getButton(SpecialCard.Type.Buy5).Enabled = false; }

                if (p.hasSpecial(SpecialCard.Type.Free3))
                { SpecialCard.getButton(SpecialCard.Type.Free3).Enabled = true; }
                else
                { SpecialCard.getButton(SpecialCard.Type.Free3).Enabled = false; }

                if (p.hasSpecial(SpecialCard.Type.Pick5))
                { SpecialCard.getButton(SpecialCard.Type.Pick5).Enabled = true; }
                else
                { SpecialCard.getButton(SpecialCard.Type.Pick5).Enabled = false; }

                if (p.hasSpecial(SpecialCard.Type.Play3))
                { SpecialCard.getButton(SpecialCard.Type.Play3).Enabled = true; }
                else
                { SpecialCard.getButton(SpecialCard.Type.Play3).Enabled = false; }

                if (p.hasSpecial(SpecialCard.Type.Trade2))
                { SpecialCard.getButton(SpecialCard.Type.Trade2).Enabled = true; }
                else
                { SpecialCard.getButton(SpecialCard.Type.Trade2).Enabled = false; }
            }
        }
Пример #6
0
        private ArrayList sortPlayersbyStock(StockCard.Type stock)
        {
            // uses a quicksort alogirthm
            ArrayList toReturn = new ArrayList();
            int[] keys = new int[Players.Count];
            Player[] values = new Player[Players.Count];

            int i = 0;
            foreach (Player p in Players.Values)
            {
                keys[i] = p.numStock(stock);
                values[i] = p;
                i++;
            }

            //sort arrays
            Array.Sort(keys, values);
            Array.Reverse(values);

            for (i = 0; i < Players.Count; i++)
            {
                toReturn.Add(values[i]);
            }

            return toReturn;
        }
Пример #7
0
        private void placeTile(Player p, Tile t)
        {
            Board.PlacedTiles.Add(t);
            t.Owner = null;
            t.Placed = true;

            //remove tile from player's stash
            p.takeTile(t);
            p.TilesLeftToPlay--;

            //update UI
            GameWindow.Instance.updateUI(p);
        }
Пример #8
0
        private bool FindDeadTiles(Player p)
        {
            ArrayList deadTiles = new ArrayList();
            foreach (Tile t in p.Tiles)
            {
                ArrayList neighbors = Board.GetNeighborsforTile(t);
                if (neighbors.Count == 0)
                { return false; }

                bool dead = true;
                foreach (Tile t2 in neighbors)
                {
                    if (!Board.isHotelSafe(t2.Hotel))
                    {
                        dead = false;
                        break;
                    }
                }

                if (dead)
                {
                    deadTiles.Add(t);
                }
            }

            foreach (Tile t in deadTiles)
            {
                placeTile(p, t);
                t.Button.BackColor = Color.Black;
            }

            if (deadTiles.Count > 0)
                return true;
            else return false;
        }
Пример #9
0
        internal void StartGame()
        {
            gameInProgress = true;

            // Add button listeners
            foreach (Tile t in Board.Tiles)
            {
                t.Button.Click += tileButton_Click;
            }
            foreach (Button b in GameWindow.Instance.Controls["stockgroupbox"].Controls)
            {
                b.Click += stockButton_Click;
            }

            // add event listeners to special card buttons
            SpecialCard.getButton(SpecialCard.Type.Buy5).Click += new EventHandler(Buy5Button_Click);
            SpecialCard.getButton(SpecialCard.Type.Free3).Click += new EventHandler(Free3Button_Click);
            SpecialCard.getButton(SpecialCard.Type.Pick5).Click += new EventHandler(Pick5Button_Click);
            SpecialCard.getButton(SpecialCard.Type.Play3).Click += new EventHandler(Play3Button_Click);
            SpecialCard.getButton(SpecialCard.Type.Trade2).Click += new EventHandler(Trade2Button_Click);

            GameWindow.Instance.Controls["doneButton"].Click += doneButton_Click;

            // Add players
            PlayerSelection playerSelection = new PlayerSelection();
            playerSelection.ShowDialog();

            // get players and have them draw a random tile
            Dictionary<Tile, Player> d = new Dictionary<Tile, Player>();
            foreach (String name in playerSelection.names)
            {
                Player p = new Player(name);
                //Just use the first tile the player drew as his pick to determine order
                d.Add((Tile)p.Tiles[0], p);
            }
            Tile[] tiles = new Tile[d.Count];
            d.Keys.CopyTo(tiles, 0);
            Array.Sort(tiles);
            //Array.Reverse(tiles);

            foreach (Tile tile in tiles)
            {
                AddPlayer(d[tile]);
                placeTile(d[tile], tile);
            }

            // add players to the UI
            foreach (int i in new Range(0, Players.Count - 1))
            {
                Player p = Players[(String)PlayerOrder[i % Players.Count]];
                p.Label.Location = new System.Drawing.Point(8, 19 + (i * 15));
                GameWindow.Instance.PlayersGroupBox.Controls.Add(p.Label);
            }

            doTurn(Players[(string)PlayerOrder[0]]);
        }
Пример #10
0
        internal void doTurn(Player p)
        {
            //Clean up previous player if necessary
            if (CurrentPlayer != null)
            {
                CurrentPlayer.NumTurns++;
                CurrentPlayer.Played3Free = false;
                CurrentPlayer.HasPlayedSpecial = false;
                CurrentPlayer.Label.Font = new System.Drawing.Font("Microsoft Sans Serif", 8f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            }

            if (!gameInProgress) // the game was declared over
            {
                FinishGame();
            }

            //set the player passed in as current player
            CurrentPlayer = p;

            // Check if game can be declared over
            if (IsGameDone())
            {
                if (MessageBox.Show("You can declare the game over. Would you like to do so?", "Declare Game?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    gameInProgress = false;
                }
            }

            //find dead tiles and play them
            while (FindDeadTiles(CurrentPlayer))
            {
                while (CurrentPlayer.Tiles.Count < 6)
                {
                    CurrentPlayer.drawRandomTile();
                }
            }

            // if it's the player's first turn, draw up to six tiles
            if (CurrentPlayer.NumTurns == 0)
            {
                while (CurrentPlayer.Tiles.Count < 6)
                {
                    CurrentPlayer.drawRandomTile();
                }
            }

            // Set current player's stock/tile allowances
            CurrentPlayer.TilesLeftToPlay = 1;
            CurrentPlayer.StockLeftToBuy = 3;

            //set up UI for player
            GameWindow.Instance.updateUI(CurrentPlayer);
        }
Пример #11
0
 static NetworkGameData GetNetworkGameData(Player p)
 {
     return null;
 }