private void towerSalvo(Tower tower) { if (tower.health != 0 && gameParams.health != 0) { gameParams.health = gameParams.health - 10; if (gameParams.health <= 0) { gameParams.health = 0; if (defeat == false) { Defeat wind = new Defeat(this); defeat = true; this.IsEnabled = false; wind.Show(); } } } }
void timerTick2(object sender, EventArgs e) { if (tanksAliveCounter != 0) { tankShootIterator++; EnemyTank tempTank = new EnemyTank(this, 0); if (tankShootIterator == tankShootTime) { tankShootIterator = 0; tempTank = enemyTanksToShoot(); // Debug.WriteLine("x = " + temp.xGridPosition.ToString() + " y = " + temp.yGridPosition.ToString()); //Debug.WriteLine("------------------------------------------"); if (enemyShootStateHolder == (int)enemyTankShellState.initState) { enemyShootsList.Add(new Rectangle()); enemyShootsList[enemyShootCount].Height = 5; enemyShootsList[enemyShootCount].Width = 4; enemyShootsList[enemyShootCount].Fill = new SolidColorBrush(Colors.Red); enemyShootStateHolder = (int)enemyTankShellState.shootState; enemyShootX = tempTank.xGridPosition * 60 + 38; enemyShootY = tempTank.yGridPosition * 60 + 60; this.obstacleCanvas.Children.Add(enemyShootsList[enemyShootCount]); Canvas.SetTop(enemyShootsList[enemyShootCount], enemyShootY); Canvas.SetLeft(enemyShootsList[enemyShootCount], enemyShootX); enemyShootCount++; } } if (enemyShootStateHolder == (int)enemyTankShellState.shootState) { enemyShootY += ammoVelocity; this.obstacleCanvas.Children.Remove(enemyShootsList[enemyShootCount - 1]); this.obstacleCanvas.Children.Add(enemyShootsList[enemyShootCount - 1]); Canvas.SetTop(enemyShootsList[enemyShootCount - 1], enemyShootY); Canvas.SetLeft(enemyShootsList[enemyShootCount - 1], enemyShootX); if (enemyShootY == enemyShootRange) { enemyShootStateHolder = (int)enemyTankShellState.hitState; } } if (enemyShootStateHolder == (int)enemyTankShellState.hitState) { if (isHerePlayerTank(enemyShootX)) { if (gameParams.health - enemyTankDamage > 0) { gameParams.health -= enemyTankDamage; } else { gameParams.health = 0; if (defeat == false) { defeat = true; Defeat wind = new Defeat(this); this.IsEnabled = false; wind.Show(); } } } enemyShootStateHolder = (int)enemyTankShellState.initState; this.obstacleCanvas.Children.Remove(enemyShootsList[enemyShootCount - 1]); } } }