/***************************************************** * Name: George Trieu * Date: 2018-06-08 * Title: FindBasePair (ArrayList, BaseTower, BaseEnemy) * Purpose: Find the BasePair that contains both the BaseTower * supplied and the BaseEnemy supplied * Inputs: ArrayList al * BaseTower bt * BaseEnemy be * Returns: One BasePair that contains the BaseTower, * and BaseEnemy from the supplied ArrayList, * or else it returns null. ****************************************************/ public static BasePair FindBasePair(ArrayList al, BaseTower bt, BaseEnemy be) { foreach (BasePair bp in al) { if (bp.GetTower() == bt && bp.GetEnemy() == be) { return(bp); } } return(null); }
/***************************************************** * Name: George Trieu * Date: 2018-06-08 * Title: FindBasePair (ArrayList, BaseTower) * Purpose: Find all the BasePairs that contains the BaseTower * supplied. * Inputs: ArrayList al * BaseTower bt * Returns: All BasePairs that contains the BaseTower, * from the supplied ArrayList, returns an ArrayList * of BasePairs. ****************************************************/ public static ArrayList FindBasePair(ArrayList al, BaseTower bt) { ArrayList result = new ArrayList(); foreach (BasePair bp in al) { if (bp.GetTower() == bt) { result.Add(bp); } } return(result); }
public BasePair(BaseTower bt, BaseEnemy be) { this.bt = bt; this.be = be; }
/***************************************************** * Name: George Trieu * Date: 2018-06-08 * Title: Form1_MouseClick * Purpose: Called when the mouse is clicked. Checks the * position of the mouse to see which button is * being pressed. * Inputs: object sender * MouseEventArgs e * Returns: nothing ****************************************************/ private void Form1_MouseClick(object sender, MouseEventArgs e) { if (e.Button.Equals(MouseButtons.Left)) { //Menu Controllers if (MessageBox.messageActive) { if (mouseX >= ((Form1.width * 32 - 112) / 2 + 56 - (Form1.offscreen.MeasureString(MessageBox.optionMessage, option).Width / 2) - 8) && mouseX <= ((Form1.width * 32 - 112) / 2 + 56 - (Form1.offscreen.MeasureString(MessageBox.optionMessage, option).Width / 2) - 8 + (Form1.offscreen.MeasureString(MessageBox.optionMessage, option).Width) + 16)) { if (mouseY >= 248 && mouseY <= (248 + Form1.offscreen.MeasureString(MessageBox.optionMessage, option).Height + 16)) { if (MessageBox.optionMessage == "Exit") { Application.Exit(); } else { timer1.Enabled = true; } MessageBox.messageActive = false; } } } //Click Controllers if (pickedUp == null) { if (mouseX >= ShopControl.bulletTower.X && mouseX <= (ShopControl.bulletTower.X + 31)) { if (mouseY >= ShopControl.bulletTower.Y && mouseY <= (ShopControl.bulletTower.Y + 31)) { if (cash >= 100) { pickedUp = "bullettower"; return; } } } if (mouseX >= ShopControl.laserTower.X && mouseX <= (ShopControl.laserTower.X + 31)) { if (mouseY >= ShopControl.laserTower.Y && mouseY <= (ShopControl.laserTower.Y + 31)) { if (pickedUp == null) { if (cash >= 500) { pickedUp = "lasertower"; return; } } } } if (mouseX >= ShopControl.freezeTower.X && mouseX <= (ShopControl.freezeTower.X + 31)) { if (mouseY >= ShopControl.freezeTower.Y && mouseY <= (ShopControl.freezeTower.Y + 31)) { if (pickedUp == null) { if (cash >= 750) { pickedUp = "freezetower"; return; } } } } if (mouseX >= ShopControl.cannonTower.X && mouseX <= (ShopControl.cannonTower.X + 31)) { if (mouseY >= ShopControl.cannonTower.Y && mouseY <= (ShopControl.cannonTower.Y + 31)) { if (pickedUp == null) { if (cash >= 1250) { pickedUp = "cannontower"; return; } } } } if (mouseX >= ShopControl.heartTower.X && mouseX <= (ShopControl.heartTower.X + 31)) { if (mouseY >= ShopControl.heartTower.Y && mouseY <= (ShopControl.heartTower.Y + 31)) { if (pickedUp == null) { if (cash >= 3500) { pickedUp = "hearttower"; return; } } } } if (mouseX >= ShopControl.volleyTower.X && mouseX <= (ShopControl.volleyTower.X + 31)) { if (mouseY >= ShopControl.volleyTower.Y && mouseY <= (ShopControl.volleyTower.Y + 31)) { if (pickedUp == null) { if (cash >= 5000) { pickedUp = "volleytower"; return; } } } } if (mouseX >= ShopControl.machineGunTower.X && mouseX <= (ShopControl.machineGunTower.X + 31)) { if (mouseY >= ShopControl.machineGunTower.Y && mouseY <= (ShopControl.machineGunTower.Y + 31)) { if (pickedUp == null) { if (cash >= 10000) { pickedUp = "machineguntower"; return; } } } } if (mouseX >= ShopControl.startButton.X && mouseX <= (ShopControl.startButton.X + 31)) { if (mouseY >= ShopControl.startButton.Y && mouseY <= (ShopControl.startButton.Y + 31)) { if (gameStarted == false) { gameStarted = true; } } } if (mouseX >= ShopControl.pauseButton.X && mouseX <= (ShopControl.pauseButton.X + 31)) { if (mouseY >= ShopControl.pauseButton.Y && mouseY <= (ShopControl.pauseButton.Y + 31)) { MessageBox.DisplayOneOptionMessage("Paused", "Wave: " + (wave + 1), "Resume"); } } if (mouseX >= ShopControl.fastslowButton.X && mouseX <= (ShopControl.fastslowButton.X + 31)) { if (mouseY >= ShopControl.fastslowButton.Y && mouseY <= (ShopControl.fastslowButton.Y + 31)) { isFast = !isFast; if (isFast) { gameStarted = true; } } } if (selectedTower != null) { if (mouseX >= ShopControl.sellButton.X && mouseX <= (ShopControl.sellButton.X + 63)) { if (mouseY >= ShopControl.sellButton.Y && mouseY <= (ShopControl.sellButton.Y + 31)) { cash += (selectedTower.GetCost() / 2); selectedTower.Destroy(); } } } bool towerFound = false; foreach (BaseTower bt in towers) { if (mouseX >= bt.GetLocation().X&& mouseX <= bt.GetLocation().X + 31) { if (mouseY >= bt.GetLocation().Y&& mouseY <= bt.GetLocation().Y + 31) { selectedTower = bt; towerFound = true; break; } } } if (!towerFound) { selectedTower = null; } } //PickedUp Controller if (pickedUp != null) { int tileX = mouseX / 32; int tileY = mouseY / 32; bool valid = levelMap[tileX, tileY] == '0'; foreach (BaseTower bt in towers) { if (bt.GetLocation().X == (tileX * 32)) { if (bt.GetLocation().Y == (tileY * 32)) { valid = false; break; } } } if (valid) { if (pickedUp == "bullettower") { if (cash >= 100) { towers.Add(new BaseTower(bullettower, tileX * 32, tileY * 32, "bullet")); cash -= 100; } } else if (pickedUp == "lasertower") { if (cash >= 500) { towers.Add(new BaseTower(lasertower, tileX * 32, tileY * 32, "laser", 1, 1, 46, 500)); cash -= 500; } } else if (pickedUp == "freezetower") { if (cash >= 750) { towers.Add(new FreezeTower(tileX * 32, tileY * 32)); cash -= 750; } } else if (pickedUp == "cannontower") { if (cash >= 1250) { towers.Add(new BaseTower(cannontower, tileX * 32, tileY * 32, "cannon", 50, 150, 112, 1250, "../../resources/cannonsound.wav")); cash -= 1250; } } else if (pickedUp == "hearttower") { if (cash >= 3500) { towers.Add(new HeartTower(tileX * 32, tileY * 32)); cash -= 3500; } } else if (pickedUp == "volleytower") { if (cash >= 5000) { towers.Add(new VolleyTower(tileX * 32, tileY * 32)); cash -= 5000; } } else if (pickedUp == "machineguntower") { if (cash >= 10000) { towers.Add(new BaseTower(machineguntower, tileX * 32, tileY * 32, "machinegun", 1, 25, 46, 10000)); cash -= 10000; } } } } } else if (e.Button.Equals(MouseButtons.Right)) { if (pickedUp != null) { pickedUp = null; } } }