public bool occupy(object sender, player player, int selectedCard) //the only thing you can really do to a boardsquare object { 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); }
int score(boardsquare squareToCheck, int scoreToAdjust) //score is a verb { if (squareToCheck.occupant == currentPlayer) { scoreToAdjust++; } else { scoreToAdjust = 0; //have to kill it; if it breaks the chain it's useless to increment at all } return(scoreToAdjust); }
void updateAvailableSquares(int chosenCard) //this updates the boardsquare clickables { for (int i = 1; i < chosenCard; i++) { boardsquare b = (this.Controls["bsq" + i.ToString()] as boardsquare); b.Enabled = false; } for (int i = chosenCard; i < 100; i++) { boardsquare b = (this.Controls["bsq" + i.ToString()] as boardsquare); if (!(b.occupied)) { b.Enabled = true; } } }
//ctor - happens right when you instantiate the class - this stuff should be in every new game, but only once per game or something public playarea(game gameInProgress) { currentGame = gameInProgress; InitializeComponent(); //board layout arrays int[] row1 = new int[10] { 73, 72, 71, 70, 69, 68, 67, 66, 65, 100}; int[] row2 = new int[10] { 74, 57, 58, 59, 60, 61, 62, 63, 64, 99 }; int[] row3 = new int[10] { 75, 56, 21, 20, 19, 18, 17, 36, 37, 98 }; int[] row4 = new int[10] { 76, 55, 22, 13, 14, 15, 16, 35, 38, 97 }; int[] row5 = new int[10] { 77, 54, 23, 12, 1, 4, 5, 34, 39, 96 }; int[] row6 = new int[10] { 78, 53, 24, 11, 2, 3, 6, 33, 40, 95 }; int[] row7 = new int[10] { 79, 52, 25, 10, 9, 8, 7, 32, 41, 94 }; int[] row8 = new int[10] { 80, 51, 26, 27, 28, 29, 30, 31, 42, 93 }; int[] row9 = new int[10] { 81, 50, 49, 48, 47, 46, 45, 44, 43, 92 }; int[] row10 = new int[10] { 82, 83, 84, 85, 86, 87, 88, 89, 90, 91 }; rows = new int[][] { row1, row2, row3, row4, row5, row6, row7, row8, row9, row10 }; for (int i = 0; i < rows.Length; i++) //row { int[] row = rows[i]; for (int j = 0; j < row.Length; j++) //column { //lets make a play area howabout, 10x10 and arranged in that bizarre matrix above int s = 35; //arbitrary woo boardsquare square = new boardsquare(); //boardsquare object inherits button - see boardsquare.cs square.Name = "bsq" + row[j]; square.Text = row[j].ToString(); square.squareID = row[j]; square.row = i; square.column = j; square.Size = new System.Drawing.Size(s, s); square.Location = new Point(j * s, i * s); square.Click += new EventHandler(square_Click); square.Enabled = false; this.Controls.Add(square); } } //oops, this is the game of 99, not 100 this.Controls.RemoveByKey("bsq100"); }
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); } }
//score is a verb int score(boardsquare squareToCheck, int scoreToAdjust) { if (squareToCheck.occupant == currentPlayer) { scoreToAdjust++; } else { scoreToAdjust = 0; //have to kill it; if it breaks the chain it's useless to increment at all } return scoreToAdjust; }
public bool checkForWin() //OMG DID SOMEONE WIN YET? hey know what i found out, this gets really slow after a while... :( { //so this is ugly bool gameOver = false; if (currentPlayer.ownedSquares.Count > 4) { ArrayList ownedSquares = currentPlayer.ownedSquares; foreach (int squareID in ownedSquares) { boardsquare square = (playArea.Controls["bsq" + squareID] as boardsquare); int[] target = { square.row, square.column }; int[][] rows = playArea.rows; int vertNegScore = 0; int horzNegScore = 0; int diagForeNegScore = 0; int diagBackNegScore = 0; int vertPosScore = 0; int horzPosScore = 0; int diagForePosScore = 0; int diagBackPosScore = 0; // |up,down --up,down \up,down /up,down scores boardsquare bsqVertPos = null; boardsquare bsqVertNeg = null; boardsquare bsqHorzPos = null; boardsquare bsqHorzNeg = null; boardsquare bsqDiagBackPos = null; boardsquare bsqDiagBackNeg = null; boardsquare bsqDiagForePos = null; boardsquare bsqDiagForeNeg = null; // |up,down --up,down \up,down /up,down square objects for (int i = 0; i < 5; i++) //5 total vert, horiz, and diag back/fore... check both ++ and -- in loop { if (gameOver == false) { try { int vertneg = rows[square.row + i][square.column]; bsqVertNeg = (playArea.Controls["bsq" + vertneg] as boardsquare); vertNegScore = score(bsqVertNeg, vertNegScore); } catch { } try { int vertpos = rows[square.row - i][square.column]; bsqVertPos = (playArea.Controls["bsq" + vertpos] as boardsquare); vertPosScore = score(bsqVertPos, vertPosScore); } catch { } try { int horzneg = rows[square.row][square.column + i]; bsqHorzNeg = (playArea.Controls["bsq" + horzneg] as boardsquare); horzNegScore = score(bsqHorzNeg, horzNegScore); } catch { } try { int horzpos = rows[square.row][square.column - i]; bsqHorzPos = (playArea.Controls["bsq" + horzpos] as boardsquare); horzPosScore = score(bsqHorzPos, horzPosScore); } catch { } try { int diagforeneg = rows[square.row + i][square.column + i]; bsqDiagForeNeg = (playArea.Controls["bsq" + diagforeneg] as boardsquare); diagForeNegScore = score(bsqDiagForeNeg, diagForeNegScore); } catch { } try { int diagforepos = rows[square.row - i][square.column - i]; bsqDiagForePos = (playArea.Controls["bsq" + diagforepos] as boardsquare); diagForePosScore = score(bsqDiagForePos, diagForePosScore); } catch { } try { int diagbackneg = rows[square.row + i][square.column - i]; bsqDiagBackNeg = (playArea.Controls["bsq" + diagbackneg] as boardsquare); diagBackNegScore = score(bsqDiagBackNeg, diagBackNegScore); } catch { } try { int diagbackpos = rows[square.row - i][square.column + i]; bsqDiagBackPos = (playArea.Controls["bsq" + diagbackpos] as boardsquare); diagBackPosScore = score(bsqDiagBackPos, diagBackPosScore); } catch { } int[] scores = { vertNegScore, vertPosScore, horzNegScore, horzPosScore, diagForeNegScore, diagForePosScore, diagBackNegScore, diagBackPosScore }; foreach (int score in scores) { if (score > 4) { System.Windows.Forms.MessageBox.Show("HOLY CRAP, " + currentPlayer.name + " HAS WON!", "WE GOT A WINNER", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation); gameOver = true; break; } } } } } } return(gameOver); }
public playarea(game gameInProgress) //ctor - happens right when you instantiate the class - this stuff should be in every new game, but only once per game or something { currentGame = gameInProgress; InitializeComponent(); //board layout arrays int[] row1 = new int[10] { 73, 72, 71, 70, 69, 68, 67, 66, 65, 100 }; int[] row2 = new int[10] { 74, 57, 58, 59, 60, 61, 62, 63, 64, 99 }; int[] row3 = new int[10] { 75, 56, 21, 20, 19, 18, 17, 36, 37, 98 }; int[] row4 = new int[10] { 76, 55, 22, 13, 14, 15, 16, 35, 38, 97 }; int[] row5 = new int[10] { 77, 54, 23, 12, 1, 4, 5, 34, 39, 96 }; int[] row6 = new int[10] { 78, 53, 24, 11, 2, 3, 6, 33, 40, 95 }; int[] row7 = new int[10] { 79, 52, 25, 10, 9, 8, 7, 32, 41, 94 }; int[] row8 = new int[10] { 80, 51, 26, 27, 28, 29, 30, 31, 42, 93 }; int[] row9 = new int[10] { 81, 50, 49, 48, 47, 46, 45, 44, 43, 92 }; int[] row10 = new int[10] { 82, 83, 84, 85, 86, 87, 88, 89, 90, 91 }; rows = new int[][] { row1, row2, row3, row4, row5, row6, row7, row8, row9, row10 }; for (int i = 0; i < rows.Length; i++) //row { int[] row = rows[i]; for (int j = 0; j < row.Length; j++) //column { //lets make a play area howabout, 10x10 and arranged in that bizarre matrix above int s = 35; //arbitrary woo boardsquare square = new boardsquare(); //boardsquare object inherits button - see boardsquare.cs square.Name = "bsq" + row[j]; square.Text = row[j].ToString(); square.squareID = row[j]; square.row = i; square.column = j; square.Size = new System.Drawing.Size(s, s); square.Location = new Point(j * s, i * s); square.Click += new EventHandler(square_Click); square.Enabled = false; this.Controls.Add(square); } } //oops, this is the game of 99, not 100 this.Controls.RemoveByKey("bsq100"); }