Example #1
0
        public override void Move()
        {
            int x = X;
            int y = Y;

            switch (currentDirection)
            {
            case direction.Down:
                ++y;
                break;

            case direction.Right:
                ++x;
                break;

            case direction.Up:
                --y;
                break;

            case direction.Left:
                --x;
                break;
            }

            switch (Collision(x, y))
            {
            case collisionType.Apple:
                X = x;
                Y = y;
                GameModel.Score++;
                Apple tempApple = FindItemIn(GameModel.apples, X, Y, 1);
                GameModel.apples.Remove(tempApple);
                Apple.AddNewApple(tempApple.X, tempApple.Y);
                break;

            case collisionType.Wall:
                break;

            case collisionType.Tank:
                GameModel.EndTheGame();
                break;

            case collisionType.None:
                X = x;
                Y = y;
                break;
            }

            kolobokView.ChangeImage(currentDirection);
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(tbCountOfTanks.Text) && !int.TryParse(tbCountOfTanks.Text, out countOfTanks))
            {
                label2.Text = "Введите корректное значение";
                return;
            }

            if (!String.IsNullOrEmpty(tbCountOfApple.Text) && !int.TryParse(tbCountOfApple.Text, out countOfApple))
            {
                lblError.Text = "Введите корректное значение";
                return;
            }

            if (!String.IsNullOrEmpty(tbSpeed.Text) && !int.TryParse(tbSpeed.Text, out speed))
            {
                label6.Text = "Введите корректное значение";
                return;
            }

            tank    = new Tank[countOfTanks];
            kolobok = new Kolobok(imageList1, border, wall, brokenWall, speed);
            listOfObjects.Add(kolobok);
            for (int i = 0; i < countOfTanks; i++)
            {
                tank[i] = new Tank(imageList1, border, wall, kolobok, brokenWall, speed);
                listOfObjects.Add(tank[i]);
                Thread.Sleep(50);
            }

            kolobok.InitEvent(tank);

            apple = new Apple[countOfApple];
            for (int i = 0; i < countOfApple; i++)
            {
                apple[i] = new Apple(imageList1, border, wall, brokenWall);
                listOfObjects.Add(apple[i]);
                Thread.Sleep(50);
            }

            pictureBox1.Image = buf;
            timer1.Start();
            Reset();
        }
Example #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            apples     = Apple.RemoveHited(apples);
            bullets    = Bullet.RemoveHited(bullets);
            enemies    = EnemyTank.AddExplosion(enemies, this);
            walls      = GameObject.AddExplosion(walls, this);
            explosions = GameObject.RemoveHited(explosions, this);

            if (kolobok.IsHit)
            {
                StopGame();
                return;
            }

            while (apples.Count < 5)
            {
                AddApple();
            }

            List <GameObject> dump = new List <GameObject>();

            foreach (GameObject item in walls)
            {
                dump.Add(item);
            }

            foreach (GameObject item in water)
            {
                dump.Add(item);
            }

            foreach (EnemyTank item in enemies)
            {
                dump.Add(item);
            }

            privStep = now;
            now      = DateTime.Now;
            g.Clear(backgroundColor);

            pictureBox1.Image = bp;

            kolobok.Move(privStep, now, dump);
            kolobok.RemoveApples(apples);
            kolobok.CheckTankCollision(enemies);
            kolobok.CheckBulletCollision(bullets);
            kolobok.Draw(this);

            foreach (GameObject obj in walls)
            {
                obj.Draw(this);
            }

            foreach (GameObject obj in water)
            {
                obj.Draw(this);
            }

            foreach (Apple obj in apples)
            {
                obj.Draw(this);
            }

            foreach (Explosion obj in explosions)
            {
                obj.Draw(this);
            }

            foreach (EnemyTank obj in enemies)
            {
                obj.Move(privStep, now, dump);
                obj.CheckKolobok(kolobok, this);
                obj.Draw(this);
            }

            foreach (Bullet obj in bullets)
            {
                obj.Move(privStep, now, walls, enemies, kolobok);
                obj.Draw(this);
            }

            this.label2.Text = kolobok.Score.ToString();

            if (form2 != null)
            {
                form2.UpdateData(apples, enemies, kolobok);
            }
        }
Example #4
0
        public void Play()
        {
            while (gameStatus==GameStatus.playing)
             {
             Thread.Sleep(speedGame);
             Packman.Run();
             Projectile.Run();

             ((Hunter)tanks[0]).Run(Packman.X, Packman.Y);
             for (int i = 1; i < tanks.Count;i++ )
                 tanks[i].Run();

             foreach (FireTank ft in fireTank)
                 ft.Fire();

             for (int i = 1; i < tanks.Count; i++)
                 if (Math.Abs(tanks[i].X - projectile.X) < 13 && Math.Abs(tanks[i].Y - projectile.Y) < 13&&
                     Math.Abs(tanks[i].X-projectile.X)>7&&Math.Abs(tanks[i].X-projectile.X)>7  )
                 {
                     fireTank.Add(new FireTank(tanks[i].X,tanks[i].Y));
                     tanks.RemoveAt(i);
                     projectile.DefaultSettings();
                 }

             for (int i = 0; i < tanks.Count-1;i++ )
             {
                 for (int j = i + 1; j < tanks.Count;j++ )
                 {
                     if (
                         (Math.Abs(tanks[i].X - tanks[j].X) <= 20 && tanks[i].Y == tanks[j].Y) ||
                         (Math.Abs(tanks[i].Y - tanks[j].Y) <= 20 && tanks[i].X == tanks[j].X) ||
                         (Math.Abs(tanks[i].Y - tanks[j].Y) <= 20 && Math.Abs(tanks[i].X - tanks[j].X) <= 20))
                     {
                         if (i == 0)
                          ((Hunter)tanks[i]).TurnAround();
                         else
                          tanks[i].TurnAround();
                         tanks[j].TurnAround();
                     }
                 }
             }
             for (int i = 0; i < tanks.Count;i++ )
             {
                 if (
                         (Math.Abs(tanks[i].X - Packman.X) <= 19 && tanks[i].Y == Packman.Y) ||
                         (Math.Abs(tanks[i].Y - Packman.Y) <= 19 && tanks[i].X == Packman.X) ||
                         (Math.Abs(tanks[i].Y - Packman.Y) <= 19 && Math.Abs(tanks[i].X - Packman.X) <= 19)
                    )
                     gameStatus = GameStatus.looser;
             }

            for (int i = 0; i < apples.Count; i++)
             {
                 if (Math.Abs(packman.X - apples[i].X) < 13 && Math.Abs(packman.Y - apples[i].Y) < 13)
                 {
                     apples[i] = new Apple(step+=30, 280);

                     CreateApples(collectedApples++);
                 }

             }
            if (collectedApples > 4)
                gameStatus = GameStatus.winner;

             }
        }
Example #5
0
        public void Play()
        {
            while (gameStatus == GameStatus.playing)
            {
                Thread.Sleep(speedGame);

                projectile.Run();
                packman.Run();
                // run for hunter
                ((Hunter)tanks[0]).Run(packman.X, packman.Y);

                for (int i = 1; i < tanks.Count; i++)
                {
                    tanks[i].Run();
                }

                //burning tank

                foreach (FireTank ft in fireTank)
                {
                    ft.Burn();
                }

                for (int i = 1; i < tanks.Count; i++)
                {
                    if (Math.Abs(tanks[i].X - projectile.X) < 11 && Math.Abs(tanks[i].Y - projectile.Y) < 11)
                    {
                        fireTank.Add(new FireTank(tanks[i].X, tanks[i].Y));
                        tanks.RemoveAt(i);
                        projectile.DefaultSettings();
                    }
                }


                //tank+tank
                for (int i = 0; i < tanks.Count - 1; i++)
                {
                    for (int j = i + 1; j < tanks.Count; j++)
                    {
                        if (
                            (Math.Abs(tanks[i].X - tanks[j].X) <= 20 && (tanks[i].Y == tanks[j].Y))
                            ||
                            (Math.Abs(tanks[i].Y - tanks[j].Y) <= 20 && (tanks[i].X == tanks[j].X))
                            ||
                            (Math.Abs(tanks[i].X - tanks[j].X) <= 20) && (Math.Abs(tanks[i].Y - tanks[j].Y) <= 20)
                            )
                        {
                            if (i == 0)
                            {
                                ((Hunter)tanks[i]).TurnAround();
                            }
                            else
                            {
                                tanks[i].TurnAround();
                            }
                            tanks[j].TurnAround();
                        }
                    }
                }
                // packman+tank
                for (int i = 0; i < tanks.Count; i++)
                {
                    if (
                        (Math.Abs(tanks[i].X - packman.X) <= 20 && (tanks[i].Y == packman.Y))
                        ||
                        (Math.Abs(tanks[i].Y - packman.Y) <= 20 && (tanks[i].X == packman.X))
                        ||
                        (Math.Abs(tanks[i].X - packman.X) <= 20) && (Math.Abs(tanks[i].Y - packman.Y) <= 20)
                        )
                    {
                        gameStatus = GameStatus.loser;
                    }
                }

                if (changeStreep != null)
                {
                    changeStreep();
                }

                //packman+apple
                for (int i = 0; i < apples.Count; i++)
                {
                    if (Math.Abs(packman.X - apples[i].X) < 4 && Math.Abs(packman.Y - apples[i].Y) < 4)
                    {
                        apples[i] = new Apple(0 + collectedApples * 20, 260);
                        collectedApples++;
                    }
                }

                if (collectedApples > 4)
                {
                    gameStatus = GameStatus.winner;
                }

                if (changeStreep != null)
                {
                    changeStreep();
                }
            }
        }
Example #6
0
 void IfCollectApple()
 {
     for (int i = 0; i < apples.Count; i++)
         if ((Math.Abs(pacman.X - apples[i].X) < 2 && Math.Abs(pacman.Y - apples[i].Y) < 2))
         {
             apples[i] = new Apple(step += 30, 420);
             CreateApples(++collectedApples);
         }
 }