//------HANDLE TURN METHOD------ private void tryMove(int row, int col, CupObj cupObj) { Cup toBeEmptied = board.getCup(row, col); if (toBeEmptied.isEmpty()) { MessageBox.Show("Please click on a cup that is not empty."); return; } if (!board.isOwned(row)) { TurnInfo.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; turnExclamation.Visible = true; numClicksWrongSide++; if (numClicksWrongSide == 3) { numClicksWrongSide = 0; MessageBox.Show("This cup does not belong to you. Please click on a cup that belongs to you."); } return; } numClicksWrongSide = 0; bool stealOccured = board.makeMove(row, col); if (stealOccured) { stealStones(cupObj); bonusInfo.Visible = true; bonusInfo.Text = "Stolen Opponent's Stones!"; } else { moveStones(cupObj); bonusInfo.Visible = false; } updateCounts(); TurnInfo.BorderStyle = System.Windows.Forms.BorderStyle.None; turnExclamation.Visible = false; if (board.getTurn() == 0 && lastPlayer == 0) { lastPlayer = 0; bonusInfo.Visible = true; bonusInfo.Text = "Double Turn!"; } else if (board.getTurn() == 0 && lastPlayer != 0) { lastPlayer = 0; } else if (board.getTurn() == 1 && lastPlayer == 1) { lastPlayer = 1; bonusInfo.Visible = true; bonusInfo.Text = "Double Turn!"; } else //(board.getTurn() == 1 && lastPlayer != 1) { lastPlayer = 1; } }
private void stealStones(CupObj cupObj) { CupObj stealerCup = moveStones(cupObj); List <StoneObj> stealerStones = getStonesWithTag((int)stealerCup.Tag); CupObj stolenCup = getCupAcross(stealerCup); List <StoneObj> stolenStones = getStonesWithTag((int)stolenCup.Tag); //MessageBox.Show("Stealer cup = " + (int)stealerCup.Tag + " \nStolen cup = " + (int)stolenCup.Tag); foreach (StoneObj stone in stolenStones) { if (board.getTurn() == 0) //p2's turn just happened { moveStoneToCup(stone, stolenCup, cup7); } else // p2's turn { moveStoneToCup(stone, stolenCup, cup14); } } foreach (StoneObj stone in stealerStones) { if (board.getTurn() == 0) //p2's turn just happened { moveStoneToCup(stone, stealerCup, cup7); } else // p2's turn { moveStoneToCup(stone, stealerCup, cup14); } } }
//------ACCESSOR-TYPE METHODS------ private CupObj getCupAcross(CupObj c) { if (c.Equals(cup1)) { return(cup13); } if (c.Equals(cup2)) { return(cup12); } if (c.Equals(cup3)) { return(cup11); } if (c.Equals(cup4)) { return(cup10); } if (c.Equals(cup5)) { return(cup9); } if (c.Equals(cup6)) { return(cup8); } if (c.Equals(cup13)) { return(cup1); } if (c.Equals(cup12)) { return(cup2); } if (c.Equals(cup11)) { return(cup3); } if (c.Equals(cup10)) { return(cup4); } if (c.Equals(cup9)) { return(cup5); } if (c.Equals(cup8)) { return(cup6); } return(null); }
private void moveStoneToCup(StoneObj s, CupObj oldC, CupObj newC) { Random rnd = new Random(); Point oldCupLoc = oldC.Location; Point newCupLoc = newC.Location; int stoneX = s.Location.X + (newCupLoc.X - oldCupLoc.X); int stoneY = s.Location.Y + (newCupLoc.Y - oldCupLoc.Y); int randomInt = rnd.Next(0, 2); //if moving to a mancala cup, Y should occasionally be incremented by more to put it in the bottom half if (randomInt == 1 && ((int)newC.Tag == 7 || (int)newC.Tag == 14)) { stoneY += 80; } s.Location = new Point(stoneX, stoneY); s.Tag = newC.Tag; }
//------GRAPHICAL MOVEMENT METHODS------ private CupObj moveStones(CupObj cupObj) { playGameSound(2); List <StoneObj> stonesToMove = getStonesWithTag((int)cupObj.Tag); int originalTag = (int)cupObj.Tag; int nextTag = nextCupTag(originalTag, originalTag); int landedTag = nextTag; foreach (StoneObj stone in stonesToMove) { if (nextTag == 7 || nextTag == 14) { playGameSound(3); } moveStoneToCup(stone, getCupWithTag((int)cupObj.Tag), getCupWithTag(nextTag)); landedTag = nextTag; nextTag = nextCupTag(originalTag, nextTag); } CupObj landedIn = getCupWithTag(landedTag); return(landedIn); }
private void drawStoneInCup(StoneObj s, CupObj c, Random rnd) { int stoneCol = rnd.Next(1, 6); Bitmap stoneImg; if (stoneCol == 1) { stoneImg = new Bitmap(MancalaGUI.Properties.Resources.rockBlue); } else if (stoneCol == 2) { stoneImg = new Bitmap(MancalaGUI.Properties.Resources.rockGreen); } else if (stoneCol == 3) { stoneImg = new Bitmap(MancalaGUI.Properties.Resources.rockPurple); } else if (stoneCol == 4) { stoneImg = new Bitmap(MancalaGUI.Properties.Resources.rockRed); } else { stoneImg = new Bitmap(MancalaGUI.Properties.Resources.rockYellow); } s.BackgroundImage = stoneImg; s.BackgroundImageLayout = ImageLayout.Stretch; s.Enabled = false; s.Visible = true; s.Size = new Size(35, 25); s.BackColor = Color.Transparent; s.BorderStyle = BorderStyle.None; Point cupLoc = c.Location; Size cupSize = c.Size; int stoneX = rnd.Next(c.Location.X, c.Location.X + c.Width - s.Width); int stoneY = rnd.Next(c.Location.Y, c.Location.Y + c.Height - s.Height); s.Location = new Point(stoneX, stoneY); }