Example #1
0
        /// <summary>
        /// Stats the game of Durak
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, EventArgs e)
        {
            int    deckSize    = 0;
            int    playerCount = 0;
            String playerName  = "";

            //ensure the player has selected a palyer count
            if (cbxPlayers.SelectedIndex != -1)
            {
                //check which decksize they picked.
                if (rbtn20.Checked)
                {
                    deckSize = 20;
                }
                else if (rbtn36.Checked)
                {
                    deckSize = 36;
                }
                else if (rbtn52.Checked)
                {
                    deckSize = 52;
                }

                Int32.TryParse(cbxPlayers.SelectedItem.ToString(), out playerCount);

                //ensure they entered a name of non-zero length
                if (txtName.Text.Length > 0)
                {
                    //Creates an array of players. Can be between 2 and 7
                    Player[] players;

                    List <Player> playerList = new List <Player>();
                    //set the players name to their input
                    playerName = txtName.Text;
                    playerList.Add(new Player(playerName));
                    //loop over the remaining players and set there names to be AI and a number
                    for (int i = 0; i < playerCount - 1; i++)
                    {
                        playerList.Add(new Player("AI " + (i + 1)));
                    }
                    //Sets each player in the arary.
                    players = playerList.ToArray();

                    //Close the main menu, and open the game window
                    this.Hide();
                    var gameWindow = new frmGameWindow(players, deckSize);
                    //binding closing the game window to also close the main menu
                    gameWindow.Closed += (s, args) => this.Close();
                    gameWindow.Show();
                }
            }
        }
Example #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            int    deckSize    = 0;
            int    playerCount = 0;
            String playerName  = "";

            if (cbxPlayers.SelectedIndex != -1)
            {
                if (rbtn20.Checked)
                {
                    deckSize = 20;
                }
                else if (rbtn36.Checked)
                {
                    deckSize = 36;
                }
                else if (rbtn52.Checked)
                {
                    deckSize = 52;
                }

                Int32.TryParse(cbxPlayers.SelectedItem.ToString(), out playerCount);

                if (txtName.Text.Length > 0)
                {
                    Durak newGame = new Durak(deckSize);

                    //Creates an array of players. Can be between 2 and 7
                    Player[] players;

                    List <Player> playerList = new List <Player>();
                    playerName = txtName.Text;
                    playerList.Add(new Player(playerName));
                    for (int i = 0; i < playerCount - 1; i++)
                    {
                        playerList.Add(new Player("AI " + i));
                    }
                    //Sets each player in the arary.
                    players = playerList.ToArray();

                    //Setting the players. Must be done before starting the game.
                    newGame.SetPlayers(players);
                    //Close the main menu, and open the game window
                    this.Hide();
                    var gameWindow = new frmGameWindow();
                    gameWindow.Closed += (s, args) => this.Close();
                    gameWindow.Show();
                }
            }
        }