private void restartGame()
        {
            foreach (CompTank tank in compTanks)
            {
                Controls.Remove(tank);
                tank.Close();
            }

            userTank.Close();

            gameStatus = GAME_STATUS.LEVEL_SELECT;
            Size       = new Size(350, 150);

            foreach (Button b in buttons)
            {
                b.Show();
            }
        }
Esempio n. 2
0
        private void BulletsMoveWorker_Tick(object sender, EventArgs e)
        {
            foreach (var b in bullets)
            {
                if (b.IsDisposed)
                {
                    break;
                }

                switch (b.Direction)
                {
                case DIRECTION.U:
                    b.Location = new Point(b.Location.X, b.Location.Y - bulletStep);
                    break;

                case DIRECTION.D:
                    b.Location = new Point(b.Location.X, b.Location.Y + bulletStep);
                    break;

                case DIRECTION.L:
                    b.Location = new Point(b.Location.X - bulletStep, b.Location.Y);
                    break;

                case DIRECTION.R:
                    b.Location = new Point(b.Location.X + bulletStep, b.Location.Y);
                    break;

                default:
                    bullets.Remove(b);
                    b.Close();
                    break;
                }

                if (b.Location.X <= gameFieldLocationX || b.Location.X >= gameFieldLocationX + gameFieldWidth ||
                    b.Location.Y <= gameFieldLocationY || b.Location.Y >= gameFieldLocationY + gameFieldHeight)
                {
                    bullets.Remove(b);
                    b.Close();
                    break;
                }

                Point bulletCenter = new Point(b.Location.X + bulletHeight / 2, b.Location.Y + bulletWidth / 2);
                foreach (var wall in walls)
                {
                    if (bulletCenter.X >= wall.Location.X && bulletCenter.X <= wall.Location.X + wallWidth &&
                        bulletCenter.Y >= wall.Location.Y && bulletCenter.Y <= wall.Location.Y + wallHeight)
                    {
                        walls.Remove(wall);
                        Controls.Remove(wall);
                        bullets.Remove(b);
                        b.Close();
                        break;
                    }
                }

                if (bulletCenter.X >= userBase.Location.X && bulletCenter.X <= userBase.Location.X + baseWidth &&
                    bulletCenter.Y >= userBase.Location.Y && bulletCenter.Y <= userBase.Location.Y + baseHeight)
                {
                    isUserTankAlive = false;
                    userBase.Close();
                    bullets.Remove(b);
                    b.Close();
                    break;
                }

                bool isNeedBreak = false;
                switch (b.BulletType)
                {
                case BULLET_TYPE.USER:
                    foreach (CompTank tank in compTanks)
                    {
                        if (bulletCenter.X >= tank.Location.X && bulletCenter.X <= tank.Location.X + tankWidth &&
                            bulletCenter.Y >= tank.Location.Y && bulletCenter.Y <= tank.Location.Y + tankHeight)
                        {
                            compTanks.Remove(tank);
                            tank.Close();
                            bullets.Remove(b);
                            b.Close();
                            isNeedBreak = true;
                            break;
                        }
                    }

                    break;

                case BULLET_TYPE.COMP:
                    if (bulletCenter.X >= userTank.Location.X && bulletCenter.X <= userTank.Location.X + tankWidth &&
                        bulletCenter.Y >= userTank.Location.Y && bulletCenter.Y <= userTank.Location.Y + tankHeight)
                    {
                        isUserTankAlive = false;
                        userTank.Close();
                        bullets.Remove(b);
                        b.Close();
                        isNeedBreak = true;
                        break;
                    }

                    break;
                }

                if (isNeedBreak)
                {
                    break;
                }
            }
        }
Esempio n. 3
0
        private void BulletsMoveWorker_Tick(object sender, EventArgs e)
        {
            foreach (var b in bullets)
            {
                if (b.IsDisposed)
                {
                    break;
                }

                switch (b.direction)
                {
                case DIRECTION.U:
                    b.Location = new Point(b.Location.X, b.Location.Y - bulletStep);
                    break;

                case DIRECTION.D:
                    b.Location = new Point(b.Location.X, b.Location.Y + bulletStep);
                    break;

                case DIRECTION.L:
                    b.Location = new Point(b.Location.X - bulletStep, b.Location.Y);
                    break;

                case DIRECTION.R:
                    b.Location = new Point(b.Location.X + bulletStep, b.Location.Y);
                    break;

                default:
                    bullets.Remove(b);
                    b.Close();
                    break;
                }

                if (b.Location.X <= 0 || b.Location.X >= 1260 || b.Location.Y <= 0 || b.Location.Y >= 660)
                {
                    bullets.Remove(b);
                    b.Close();
                    break;
                }

                Point bulletCenter = new Point(b.Location.X + TanksGame.bulletHeight / 2, b.Location.Y + TanksGame.bulletWidth / 2);

                bool isNeedBreak = false;
                switch (b.bulletType)
                {
                case BULLET_TYPE.USER:
                    foreach (CompTank tank in compTanks)
                    {
                        if (bulletCenter.X >= tank.Location.X && bulletCenter.X <= tank.Location.X + TanksGame.tankWidth &&
                            bulletCenter.Y >= tank.Location.Y && bulletCenter.Y <= tank.Location.Y + TanksGame.tankHeight)
                        {
                            compTanks.Remove(tank);
                            tank.Close();
                            bullets.Remove(b);
                            b.Close();
                            isNeedBreak = true;
                            break;
                        }
                    }

                    break;

                case BULLET_TYPE.COMP:
                    if (bulletCenter.X >= userTank.Location.X && bulletCenter.X <= userTank.Location.X + TanksGame.tankWidth &&
                        bulletCenter.Y >= userTank.Location.Y && bulletCenter.Y <= userTank.Location.Y + TanksGame.tankHeight)
                    {
                        isUserTankAlive = false;
                        userTank.Close();
                        bullets.Remove(b);
                        b.Close();
                        isNeedBreak = true;
                        break;
                    }

                    break;
                }

                if (isNeedBreak)
                {
                    break;
                }
            } // foreach b in bullets
        }