コード例 #1
0
ファイル: GameState.cs プロジェクト: Almaz-Takibayev/PP2
        private void CheckCollision()
        {
            if (worm.IsIntersected(wall.body) || worm.IsIntersected(worm.body))
            {
                gameOver = true;
                Console.Clear();
                Console.SetCursorPosition(15, 20);
                Console.Write("Game Over!");
            }
            else if (worm.IsIntersected(food.body))
            {
                //player.score.Score += 10;
                scoreLevel.Score += 25;
                player.Score      = scoreLevel.Score;
                if (scoreLevel.Score == 50)
                {
                    wall.Clear();
                    LevelNumber      = 1;
                    scoreLevel.Level = 2;
                    wall.Draw();
                }
                else if (scoreLevel.Score == 100)
                {
                    wall.Clear();

                    LevelNumber      = 2;
                    scoreLevel.Level = 3;
                    wall             = new Wall('#', LevelNumber);
                    wall.Draw();
                }
                worm.Eat(food.body);
                food.GenerateLocation(worm.body, wall.body);
            }
        }
コード例 #2
0
 void CheckWallColision()
 {
     if (wall.CheckIntersection(worm.body) == true)
     {
         worm.Clear();
         food.Clear();
         wall.Clear();
         Console.WriteLine("     ");
         Console.WriteLine("Game over");
         Environment.Exit(0);
     }
 }
コード例 #3
0
ファイル: GameState.cs プロジェクト: Aigerim22/pp2
        void CheckFood()
        {
            if (w.CheckCollision(b.body))
            {
                gameOver = true;
                Console.Clear();
                Console.SetCursorPosition(10, 20);
                Console.WriteLine("Game over!");
            }
            else if (w.CheckCollision(f.body))
            {
                w.Eat(f.body[0]);
                score++;
                f.Generate();
            }
            else if (w.CheckCollisionwithItself())
            {
                gameOver = true;
                Console.Clear();
                Console.SetCursorPosition(10, 20);
                Console.WriteLine("Game over!");
            }

            if (score > MaxScore)
            {
                b.Clear();
                b.body.Clear();
                level = 3;
                b.LoadLevel(3);
            }
        }
コード例 #4
0
ファイル: Game.cs プロジェクト: Alibek120699/PP2
        public void Process()
        {
            ConsoleKeyInfo pressedButton = Console.ReadKey();

            switch (pressedButton.Key)
            {
            case ConsoleKey.UpArrow:
                worm.Move(0, -1);
                break;

            case ConsoleKey.DownArrow:
                worm.Move(0, 1);
                break;

            case ConsoleKey.LeftArrow:
                worm.Move(-1, 0);
                break;

            case ConsoleKey.RightArrow:
                worm.Move(1, 0);
                break;

            case ConsoleKey.Escape:
                break;
            }

            if (worm.body[0].Equals(food.body[0]))
            {
                worm.body.Add(new Point {
                    X = food.body[0].X, Y = food.body[0].Y
                });
                count++;
                if (count == 3)
                {
                    wall.Clear();
                    worm.Clear();
                    worm.body.Clear();
                    wall.LoadLevel(gameLevel);
                    wall.Draw();
                    gameLevel++;
                    count = 0;
                }
                Random rx = new Random();
                while (wall.IsPointBelong(food.body[0]) || worm.IsPointBelong(food.body[0]))
                {
                    food.body[0] = new Point {
                        X = rx.Next(1, 30), Y = rx.Next(1, 30)
                    };
                }
            }
            else
            {
                foreach (Point p in wall.body)
                {
                    if (p.Equals(worm.body[0]))
                    {
                        Console.Clear();
                        Console.WriteLine("GAME OVER!!!");
                        isAlive = false;
                        break;
                    }
                }
                for (int i = 1; i < worm.body.Count; i++)
                {
                    if (worm.body[i].Equals(worm.body[0]))
                    {
                        Console.Clear();
                        Console.WriteLine("GAME OVER!!!");
                        isAlive = false;
                        break;
                    }
                }
            }
        }
コード例 #5
0
ファイル: Game.cs プロジェクト: zhengissov/PT2017
        public void Start()
        {
            Load();


            Thread t = new Thread(new ThreadStart(worm.Move));

            t.Start();

            while (true)
            {
                wall.Save();
                if (score == 500 && nextLevel == true)
                {
                    level = level + 1;
                    wall.Clear();
                    wall.Generate(level);
                    wall.Draw();
                    nextLevel = false;
                    score     = 0;

                    worm.Clear();
                    Point p = new Point();
                    p = worm.points[0];
                    worm.points.Clear();
                    worm.points.Add(p);
                }

                ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                case ConsoleKey.F2:
                    this.Save();
                    break;

                case ConsoleKey.F3:
                    wall = wall.Load() as Wall;
                    wall.Draw();
                    worm.Clear();
                    worm = worm.Load() as Worm;
                    worm.AttachGameLink(this);
                    t.Abort();

                    t = new Thread(new ThreadStart(worm.Move));
                    t.Start();
                    break;

                case ConsoleKey.UpArrow:
                    worm.dx = 0;
                    worm.dy = -1;
                    break;

                case ConsoleKey.DownArrow:
                    worm.dx = 0;
                    worm.dy = 1;
                    break;

                case ConsoleKey.LeftArrow:
                    worm.dx = -1;
                    worm.dy = 0;
                    break;

                case ConsoleKey.RightArrow:
                    worm.dx = 1;
                    worm.dy = 0;
                    break;

                case ConsoleKey.Escape:
                    break;
                }
            }
        }