private void playButton_Click(object sender, EventArgs e) { try { //when user clicks play button, player object is instantiated and then a game object is. if (nameTextBox.Text == "") { MessageBox.Show("Please enter name"); return; //throw new ArgumentException("Please enter a name into name box"); } Player player = new Player(nameTextBox.Text); YanivGame game = new YanivGame(player, (int)numComBox.Value, difficultyBox.Text); this.Hide(); GameBoard gameBoard = new GameBoard(game); gameBoard.ShowDialog(); } //find more specific argument exception, maybe make own type? catch (ArgumentException ex) { MessageBox.Show(ex.Message); } }
public GameBoard(YanivGame game) { InitializeComponent(); Game = game; PlayersCards = new List <PictureBox>() { playerCard1, playerCard2, playerCard3, playerCard4, playerCard5 }; //creates an array of lists(for com cards, so it can add and remove cards) comCards = new List <PictureBox> [Game.comPlayers.Count]; for (int i = 0; i < Game.comPlayers.Count; i++) { switch (i + 1) { case 1: com1.Visible = true; comCards[i] = new List <PictureBox>() { com1card1, com1card2, com1card3, com1card4, com1card5 }; break; case 2: com2.Visible = true; comCards[i] = new List <PictureBox>() { com2card1, com2card2, com2card3, com2card4, com2card5 }; break; case 3: com3.Visible = true; comCards[i] = new List <PictureBox>() { com3card1, com3card2, com3card3, com3card4, com3card5 }; break; case 4: com4.Visible = true; comCards[i] = new List <PictureBox>() { com4card1, com4card2, com4card3, com4card4, com4card5 }; break; default: //pick better exception throw new InvalidOperationException("none of the switch cases were hit with i: " + i); } } }