//the only thing you can really do to a boardsquare object public bool occupy(object sender, player player, int selectedCard) { boardsquare square = (sender as boardsquare); DialogResult result = MessageBox.Show("are you sure you wish to occupy square " + square.squareID.ToString() + "?", "HALT", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { switch (player.id) { case 1: square.BackColor = System.Drawing.Color.Red; break; case 2: square.BackColor = System.Drawing.Color.Blue; break; case 3: square.BackColor = System.Drawing.Color.Green; break; } square.Enabled = false; square.occupied = true; square.occupant = player; player.ownedSquares.Add(square.squareID); player.removeCard(player, selectedCard); } return square.occupied; }
//let's play a game why not private void button1_Click(object sender, EventArgs e) { string p1name = player1name.Text; string p2name = player2name.Text; string p3name = player3name.Text; player[] players; if (p1name.Trim() == "") { p1name = "player 1"; } if (p2name.Trim() == "") { p2name = "player 2"; } if (p3name.Trim() == "") { p3name = "player 3"; } player player1 = new player(p1name, 1); player player2 = new player(p2name, 2); if (checkBox1.Checked) { player player3 = new player(p3name, 3); players = new player[] { player1, player2, player3 }; } else { players = new player[] { player1, player2 }; } game LeJeuDe99 = new game(players); this.Hide(); }
//TAKE CARD AWAY PLS public void removeCard(player player, int cardValueToRemove) { int remember = -1; for (int i = 0; i < player.hand.Count; i++) { if ((int)player.hand[i] == cardValueToRemove) { remember = i; } } player.hand.Remove(player.hand[remember]); }
//ctor makes a game thingy and draws cards for players to start with public game(player[] players) { playerList = players; gameDeck = new cards(); for (int i = 0; i < 5; i++) //5 cards per player to start { for (int j = 0; j < playerList.Length; j++) //card 1 player 1 2 3 card 2 player 1 2 3... { playerList[j].hand.Add(gameDeck.draw(gameDeck)); //draw a new random card from deck playerList[j].hand.Sort(); } } currentPlayer = players[0]; //start with player 1 playArea = new playarea(this); //be sure the playarea can reference the game variables, pass it along playArea.Show(); playArea.roundUpdate(currentPlayer); //game has started, thanks ctor }
//this progresses the visual elements on the form to the next player and should be called after a player's play choice is confirmed public void roundUpdate(player nextPlayer) { if (nextPlayer.hand.Count > 0) { for (int i = 0; i < 5; i++) { RadioButton cardbutton = (this.Controls["panel1"].Controls["radioCard" + i] as RadioButton); cardbutton.Checked = false; cardbutton.Visible = false; } for (int i = 1; i < 100; i++) { boardsquare square = (this.Controls["bsq" + i] as boardsquare); square.Enabled = false; } lblPlayer.Text = nextPlayer.name; for (int i = 0; i < nextPlayer.hand.Count; i++) { RadioButton cardbutton = (this.Controls["panel1"].Controls["radioCard" + i] as RadioButton); cardbutton.Visible = true; cardbutton.Text = nextPlayer.hand[i].ToString() + " to 99"; } if (panel1.Visible) { panel1.Visible = false; btnHand.Text = "show hand"; } btnDrawCard.Enabled = false; btnDiscard.Enabled = false; if (nextPlayer.hand.Count < 5) { btnDrawCard.Enabled = true; } } else { currentGame.prepareNextPlayer(); roundUpdate(currentGame.currentPlayer); } }
public void roundUpdate(player nextPlayer) //this progresses the visual elements on the form to the next player and should be called after a player's play choice is confirmed { if (nextPlayer.hand.Count > 0) { for (int i = 0; i < 5; i++) { RadioButton cardbutton = (this.Controls["panel1"].Controls["radioCard" + i] as RadioButton); cardbutton.Checked = false; cardbutton.Visible = false; } for (int i = 1; i < 100; i++) { boardsquare square = (this.Controls["bsq" + i] as boardsquare); square.Enabled = false; } lblPlayer.Text = nextPlayer.name; for (int i = 0; i < nextPlayer.hand.Count; i++) { RadioButton cardbutton = (this.Controls["panel1"].Controls["radioCard" + i] as RadioButton); cardbutton.Visible = true; cardbutton.Text = nextPlayer.hand[i].ToString() + " to 99"; } if (panel1.Visible) { panel1.Visible = false; btnHand.Text = "show hand"; } btnDrawCard.Enabled = false; btnDiscard.Enabled = false; if (nextPlayer.hand.Count < 5) { btnDrawCard.Enabled = true; } } else { currentGame.prepareNextPlayer(); roundUpdate(currentGame.currentPlayer); } }
private void button1_Click(object sender, EventArgs e) //let's play a game why not { string p1name = player1name.Text; string p2name = player2name.Text; string p3name = player3name.Text; player[] players; if (p1name.Trim() == "") { p1name = "player 1"; } if (p2name.Trim() == "") { p2name = "player 2"; } if (p3name.Trim() == "") { p3name = "player 3"; } player player1 = new player(p1name, 1); player player2 = new player(p2name, 2); if (checkBox1.Checked) { player player3 = new player(p3name, 3); players = new player[] { player1, player2, player3 }; } else { players = new player[] { player1, player2 }; } game LeJeuDe99 = new game(players); this.Hide(); }
//player progression; i'm bad with scoping so here's a hack for some reason i can't remember, probably becakse it's part of the "game" public void prepareNextPlayer() { try { currentPlayer = playerList[currentPlayer.id]; //haha, players[0] is id==1, [1]==2, [2]==3 so catch } catch { tries++; currentPlayer = playerList[0]; } if (tries > 4000) { System.Windows.Forms.MessageBox.Show("well, none of you have cards left. none of you.\r\nall of you lose. i am ashamed for you.\r\nthe game will now close because everyone lost.", "unbelievable"); System.Environment.Exit(-1); } }