private void ResultGameChecker_Tick(object sender, EventArgs e) { if (compTanks.Count() == 0) { resultGameChecker.Stop(); MessageBox.Show("Winner!"); RestartGame(); return; } if (isUserTankAlive == false) { resultGameChecker.Stop(); MessageBox.Show("You lose!"); RestartGame(); return; } }
private void DebugTimer_Tick(object sender, EventArgs e) { debugLabel.Text = "CompTanks: " + compTanks.Count() + " Bullets: " + bullets.Count(); }
private void TanksGame_KeyDown(object sender, KeyEventArgs e) { Random rnd = new Random(); Bullet bullet = null; switch (e.KeyCode) { case Keys.W: userTank.BackgroundImage = Properties.Resources.light_utank_u; userTank.direction = DIRECTION.U; Point newUpLoc = new Point(userTank.Location.X, userTank.Location.Y - compTankStep); if (newUpLoc.Y <= 0) { break; } userTank.Location = newUpLoc; break; case Keys.S: userTank.BackgroundImage = Properties.Resources.light_utank_d; userTank.direction = DIRECTION.D; Point newDownLoc = new Point(userTank.Location.X, userTank.Location.Y + compTankStep); if (newDownLoc.Y >= 600) { break; } userTank.Location = newDownLoc; break; case Keys.A: userTank.BackgroundImage = Properties.Resources.light_utank_l; userTank.direction = DIRECTION.L; Point newLeftLoc = new Point(userTank.Location.X - compTankStep, userTank.Location.Y); if (newLeftLoc.X <= 0) { break; } userTank.Location = newLeftLoc; break; case Keys.D: userTank.BackgroundImage = Properties.Resources.light_utank_r; userTank.direction = DIRECTION.R; Point newRightLoc = new Point(userTank.Location.X + compTankStep, userTank.Location.Y); if (newRightLoc.X >= 1200) { break; } userTank.Location = newRightLoc; break; case Keys.Space: if (!isReadyToShoot) { break; } bullet = new Bullet(BULLET_TYPE.USER, userTank.direction, userTank.Location); bullets.Add(bullet); Controls.Add(bullet); bullet.Show(); isReadyToShoot = false; gunLabel.Text = "Gun: Reloading"; reloadTimer.Start(); break; case Keys.B: if (compTanks.Count() == 0) { break; } int tankIndex = rnd.Next() % compTanks.Count(); bullet = new Bullet(BULLET_TYPE.COMP, compTanks[tankIndex].direction, compTanks[tankIndex].Location); bullets.Add(bullet); Controls.Add(bullet); bullet.Show(); isCompReadyToShoot = true; break; } }