// This event handler method lauches a two player game when the button is clicked private void btnTwoP_Click(object sender, EventArgs e) { // Instantiate and display a new DiceWindow DiceWindow dwTwoPlayer = new DiceWindow(); dwTwoPlayer.Show(); // Minimise the menu button window WindowState = FormWindowState.Minimized; // Instantiate and display a name entry InputBox dialog for player one InputBox ibxP1Name = new InputBox(1); ibxP1Name.ShowDialog(); // Instantiate and display a name entry InputBox dialog for player two InputBox ibxP2Name = new InputBox(2); ibxP2Name.ShowDialog(); // Instantiate and display the game windows Player frmPlayer1 = new Player(ibxP1Name, dwTwoPlayer, 2); Player frmPlayer2 = new Player(ibxP2Name, dwTwoPlayer, 2); frmPlayer1.Show(); frmPlayer2.Show(); }
// This event handler method lauches a one player game when the button is clicked private void btnSolo_Click(object sender, EventArgs e) { // Instantiate and display a new DiceWindow DiceWindow dwSolo = new DiceWindow(); dwSolo.Show(); // Minimise the menu button window WindowState = FormWindowState.Minimized; // Instantiate and display a name entry InputBox dialog InputBox ibxName = new InputBox(1); ibxName.ShowDialog(); // Instantiate and display the game window Player frmPlayer = new Player(ibxName, dwSolo); frmPlayer.Show(); }
// Constructor creates a new Player receiving a name from ibxInputBox, access to the dice window // through dwDiceWin and a number of players as parameters public Player(InputBox ibxInputBox, DiceWindow dwDiceWin, int iPlayers = 1) { InitializeComponent(); bLurgit = false; // Hides "Games Won" label because it makes no sense in this case if (iPlayers == 1) { lblSession.Visible = false; } // Instantiate a new game session sesPlayerSession = new Session(); // Initialise counters _iNumPlayers++; iPlayerNumber = _iNumPlayers; iRollCounter = 0; iRoundCounter = 1; _iGameCounter = 1; // Initialise dice window dwDice = dwDiceWin; // Instantiate the first game gGame = new Game(); // Instantiate first round rouRound = new Round(1); // Dice have no reason to be user lockable at this point dwDice.disableAllDice(); // Set the properties of the player windows Top = dwDiceWin.Top; if (_iNumPlayers == 1) { cPlayerColour = Color.LightBlue; Left = dwDiceWin.Left - 50 - Width; } else { cPlayerColour = Color.LightPink; Left = dwDiceWin.Right + 50; Enabled = false; } BackColor = cPlayerColour; // Set the title of the player windows if (ibxInputBox.sName == null) { sPlayerName = "Computer"; btnRoll.Visible = false; } else { sPlayerName = ibxInputBox.sName; } Text = sPlayerName; }