示例#1
0
        public static void preliminarySetup(GUI gui)
        {
            PanelControls.setupFlag   = true;
            PlayerResources.gameState = new GameState(); //create brand new game

            //populate button list
            gui.buttonList = ButtonControls.populateButtons(gui);

            //set status bar
            gui.turnStatus.Text = "Turn: Player " + PlayerResources.gameState.currentPlayer;

            PlayerResources.gameState.currentPlayer = 1;

            //place players in corners
            InitialSetups.placePlayersInCorners(gui);
            ButtonControls.setCursorsForNextTurn(gui);
            PanelControls.setupFlag = false; //declare end of setup
            LoadSave.loadFlag       = false; //declare end of game load

            GamePlayerFunctions.availableAction = true;
            //update player credits

            //give all players an initial income of 2000 credits
            PlayerResources.gameState.initialIncome(2000);
            gui.creditsBox.Text = "" + PlayerResources.gameState.selectCurrentPlayer().goldCount;
            gui.infoBox.Text    = " Welcome. " + PlayerResources.gameState.player1.getName() + "'s \n turn.";
        }
        internal static bool availableAction = true;  //if false, the player will have to end their turn

        public static void genericButtonClickEvent(GUI gui, object sender, EventArgs e)
        {
            SoundEffectPlayer.playSoundEffect(Properties.Resources.button_press);

            //retrieve the button object that has been interacted with
            var    btn = sender as Button;
            int    index;           //the address of this button in the context of the game board
            string name = btn.Name; //the name of the button object

            //extract the integer number from the button name that corresponds to the game grid
            index = Convert.ToInt32(string.Join(null, System.Text.RegularExpressions.Regex.Split(name, "[^\\d]")));

            ButtonControls.setCursorsForNextTurn(gui);

            generalButtonClick(gui, btn, index); //generate button click based on the extracted index number
        }
        public static void advanceTurn(GUI gui)
        {
            //update scores
            PanelControls.updateScore(gui);

            //set the turn for the next player's move
            PlayerResources.gameState.toggleTurn();

            //set status bar information
            gui.turnStatus.Text = "Turn: Player " + PlayerResources.gameState.currentPlayer;

            ButtonControls.setCursorsForNextTurn(gui);

            if (PlayerResources.gameState.currentPlayer == 1 && GamePlayerFunctions.aiFlag == false)
            {
                gui.creditsBox.Text = PlayerResources.gameState.player1.goldCount.ToString();
            }

            GamePlayerFunctions.availableAction = true;

            gui.infoBox.ForeColor = System.Drawing.Color.Green;
            gui.infoBox.Text      = "Turn: " + PlayerResources.gameState.selectCurrentPlayer().getName();
        }
        /*
         * Simulates the "transaction" of a player taking a square on the board.
         * A choice can be made between the type of development.
         * Also supports an automated track for the computer AI
         * */
        public static void generalButtonClick(GUI gui, Button button, int index)
        {
            if (availableAction == false && PanelControls.setupFlag == false)
            {
                InformationDisplays.noMoreActionsText(gui.infoBox);
                return;
            }


            //if the player already owns this tile
            //they should not waste their turn re-taking it ;)
            if (PlayerResources.gameState.gameBoard.getBoard().ElementAt(index - 1).getOccupier() == PlayerResources.gameState.currentPlayer && LoadSave.loadFlag == false)
            {
                return;
            }

            //if the selection is an illegal move, prevent the move
            if (PlayerResources.gameState.verifyNeighbors(PlayerResources.gameState.selectCurrentPlayer(), index) == false && LoadSave.loadFlag == false)
            {
                return;
            }

            //if the selection is not unoccupied and belongs to another player, it cannot be taken
            if (PlayerResources.gameState.gameBoard.getBoard().ElementAt(index - 1).getOccupier() != 0)
            {
                return;
            }

            if (PanelControls.setupFlag == false && LoadSave.loadFlag == false && aiFlag == false)
            {
                //verify that player wants to take a tile for their turn
                DialogResult dialogResult = MessageBox.Show("Buy Selected Tile?", "City of Remnants", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.No)
                {
                    SoundEffectPlayer.playSoundEffect(Properties.Resources.cancel_option);
                    return;
                }
            }

            SoundEffectPlayer.playSoundEffect(Properties.Resources.ok_option);


            if (PanelControls.setupFlag == false && aiFlag == false)
            {
                //choose cost of develop to determine yield of square
                MessageBoxManager.OK     = "Racket";
                MessageBoxManager.Cancel = "Front";
                MessageBoxManager.Register();

                //verify that player wants to take a tile for their turn
                DialogResult dialogResult2 = MessageBox.Show("Choose Development Type: \nRacket (2000 cred/250 per turn), \nFront (1000 cred/60 per turn) ", "City of Remnants", MessageBoxButtons.OKCancel);

                if (dialogResult2 == DialogResult.OK)
                {
                    SoundEffectPlayer.playSoundEffect(Properties.Resources.ok_option2);


                    //check if player has the right balance
                    if (PlayerResources.gameState.selectCurrentPlayer().goldCount >= 2000)
                    {
                        //set yield of square to 250
                        PlayerResources.gameState.gameBoard.getBoard().ElementAt(index - 1).yield = 250;
                        PlayerResources.gameState.selectCurrentPlayer().goldCount += -2000;
                    }
                    else
                    {
                        MessageBoxManager.Unregister();

                        SoundEffectPlayer.playSoundEffect(Properties.Resources.cancel_option2);

                        return;
                    }
                }
                else if (dialogResult2 == DialogResult.Cancel)
                {
                    SoundEffectPlayer.playSoundEffect(Properties.Resources.ok_option);


                    //check if player has the right balance
                    if (PlayerResources.gameState.selectCurrentPlayer().goldCount >= 1000)
                    {
                        //set yield of square to 60
                        PlayerResources.gameState.gameBoard.getBoard().ElementAt(index - 1).yield = 60;
                        PlayerResources.gameState.selectCurrentPlayer().goldCount += -1000;
                    }
                    else
                    {
                        MessageBoxManager.Unregister();
                        InformationDisplays.insufficientFundsText(gui.infoBox);
                        return;
                    }
                }
                else
                {
                    MessageBoxManager.Unregister();
                    return;
                }

                MessageBoxManager.Unregister();
            }
            else if (PanelControls.setupFlag == true && aiFlag == false)
            {
                //headquarters all have a yield of 100
                PlayerResources.gameState.gameBoard.getBoard().ElementAt(index - 1).yield = 100;
            }
            else if (aiFlag == true)
            {
                //figure out what prices the player can afford
                List <string> aiChoices = new List <string>();
                aiChoices.Add("FRONT");
                if (PlayerResources.gameState.selectCurrentPlayer().goldCount >= 2000)
                {
                    aiChoices.Add("RACKET");
                }

                //now pick one and buy it
                int    r            = PlayerResources.rndProperty.Next(aiChoices.Count);
                string randomAction = (string)aiChoices[r];

                if (randomAction == "FRONT")
                {
                    //buy front
                    //set yield of square to 60
                    PlayerResources.gameState.gameBoard.getBoard().ElementAt(index - 1).yield = 60;
                    PlayerResources.gameState.selectCurrentPlayer().goldCount += -1000;
                }
                else
                {
                    //buy racket
                    //set yield of square to 250
                    PlayerResources.gameState.gameBoard.getBoard().ElementAt(index - 1).yield = 250;
                    PlayerResources.gameState.selectCurrentPlayer().goldCount += -2000;
                }
            }


            if (aiFlag == false)
            {
                InformationDisplays.transactionCompleteText(gui.infoBox);

                //update player credits
                gui.creditsBox.Text = "" + PlayerResources.gameState.selectCurrentPlayer().goldCount;
            }

            //set button tooltips
            ButtonControls.setButtonToolTips(gui);

            //toggle button light
            ButtonControls.setButtonLight(button, PlayerResources.gameState.currentPlayer);

            //change occupier of selected square
            PlayerResources.gameState.gameBoard.getBoard().ElementAt(index - 1).setOccupier(PlayerResources.gameState.currentPlayer);

            //update player information
            PlayerResources.gameState.updatePlayerStatistics(PlayerResources.gameState.currentPlayer, PlayerResources.gameState.gameBoard.getBoard().ElementAt(index - 1));

            //update the stats bar
            PanelControls.updateScore(gui);

            //set cursors
            ButtonControls.setCursorsForNextTurn(gui);


            availableAction = false; // no more actions

            //refresh button text
            if (PanelControls.setupFlag == true)
            {
                button.Text = PlayerResources.gameState.currentPlayer.ToString();
            }
        }