예제 #1
0
 public void LoadLevel1()
 {
     Console.Clear();
     wall.LoadLevel("1");
     DrawField();
     Draw();
     worm = new Worm(new Point {
         X = 32, Y = 13
     }, ConsoleColor.DarkGreen, 'o');
 }
예제 #2
0
        public void PressedKey(ConsoleKeyInfo consoleKeyInfo)
        {
            switch (consoleKeyInfo.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:
                Console.Clear();
                Console.SetCursorPosition(20, 30);
                Console.WriteLine("Exit?");
                Environment.Exit(0);
                break;

            case ConsoleKey.F2:
                Console.Clear();
                worm.body.Clear();
                worm.body.Add(new Point {
                    X = 20, Y = 20
                });
                wall.LoadLevel(2);
                food.Generate(wall.body, worm.body);
                level = 2;
                break;

            case ConsoleKey.F3:
                Console.Clear();
                worm.body.Clear();
                worm.body.Add(new Point {
                    X = 20, Y = 20
                });
                wall.LoadLevel(3);
                food.Generate(wall.body, worm.body);
                level = 3;
                break;
            }

            CheckColision();
            CheckWallColision();
            CheckSelfCollision();
        }
예제 #3
0
        public void CreateNewLvl(GameLvl lvl) //метод для создания нового уровня
        {
            Alive = true;
            if (lvl == GameLvl.first)
            {
                snake = new Snake(new Point {
                    X = 17, Y = 16
                }, ConsoleColor.Black, 'o');
                food = new Food(new Point {
                    X = -1, Y = -1
                }, ConsoleColor.Black, '@');
                wall  = new Wall(null, ConsoleColor.Black, '#');
                score = 0;
            }
            else
            {
                score += (snake.body.Count - 1) * coef;
                snake.body.Clear();
                snake.body.Add(new Point {
                    X = 17, Y = 16
                });
                wall.body.Clear();
            }

            wall.LoadLevel(lvl);
        }
예제 #4
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);
            }
        }
예제 #5
0
        static void TestWall()
        {
            Wall wall = new Wall('#', ConsoleColor.Green);

            wall.LoadLevel(1);

            wall.Draw();
        }
예제 #6
0
        public void StartGame()
        {
            run = true;
            wall.LoadLevel(1);
            // draw it only once
            wall.Draw();

            ThreadStart threadStart    = new ThreadStart(DrawAndMoveGameObjects);
            Thread      moveDrawThread = new Thread(threadStart);

            // run the thread
            moveDrawThread.Start();

            // balance = 10 000 -> 15 000 -> 9000

            // op1: add 5000 = (1) get balance; (2) balance = (1) + 5000

            // op2: pay 1000 (mobile) = (1) get balance; (2) balance = (1) - 1000

            while (run)
            {
                // leads to many errors
                //DrawAndMoveGameObjects();
                ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                case ConsoleKey.UpArrow:
                    // set movement direction
                    serpent.ChangeDirection(Direction.Up);
                    break;

                case ConsoleKey.DownArrow:
                    serpent.ChangeDirection(Direction.Down);
                    break;

                case ConsoleKey.LeftArrow:
                    serpent.ChangeDirection(Direction.Left);
                    break;

                case ConsoleKey.RightArrow:
                    serpent.ChangeDirection(Direction.Right);
                    break;

                case ConsoleKey.Escape:
                    run = false;
                    break;

                default:
                    break;
                }
            }

            Console.Clear();
            Console.ForegroundColor = ConsoleColor.White;
            Console.SetCursorPosition(19, 19);
            Console.Write("GAME OVER");
        }
예제 #7
0
 public void Draw()
 {
     Console.Clear();
     wall.LoadLevel();
     foreach (GameObject g in gameObjects)
     {
         g.Draw();
     }
 }
예제 #8
0
        public void StartGame()
        {
            run = true;
            wall.LoadLevel(1);
            // draw it only once
            wall.Draw();

            while (run)
            {
                serpent.Draw();
                food.Draw();
                ConsoleKeyInfo pressedKey = Console.ReadKey();
                switch (pressedKey.Key)
                {
                case ConsoleKey.UpArrow:
                    // Clear before moving because if serpent moves first, we cannot clear properly
                    serpent.Clear();
                    serpent.Move(Direction.Up);
                    CheckFoodCatch();
                    break;

                case ConsoleKey.DownArrow:
                    serpent.Clear();
                    serpent.Move(Direction.Down);
                    CheckFoodCatch();
                    break;

                case ConsoleKey.LeftArrow:
                    serpent.Clear();
                    serpent.Move(Direction.Left);
                    CheckFoodCatch();
                    break;

                case ConsoleKey.RightArrow:
                    serpent.Clear();
                    serpent.Move(Direction.Right);
                    CheckFoodCatch();
                    break;

                case ConsoleKey.Escape:
                    run = false;
                    break;

                default:
                    break;
                }
            }

            Console.Clear();
            Console.ForegroundColor = ConsoleColor.White;
            Console.SetCursorPosition(19, 19);
            Console.Write("GAME OVER");
        }
예제 #9
0
파일: Game.cs 프로젝트: Alibek120699/PP2
        public Game()
        {
            isAlive   = true;
            gameLevel = GameLevel.First;

            worm = new Worm(new Point {
                X = 10, Y = 10
            },
                            ConsoleColor.Magenta, '0');
            food = new Food(new Point {
                X = 20, Y = 10
            },
                            ConsoleColor.Green, '1');
            wall = new Wall(null, ConsoleColor.Cyan, '#');

            wall.LoadLevel(GameLevel.First);
        }
예제 #10
0
파일: Game.cs 프로젝트: darbayevtxt/Csharp
        public Game()
        {
            isAlive = true;
            snake   = new Snake(10, 10, '*', ConsoleColor.White);
            wall    = new Wall('#', ConsoleColor.Yellow);
            wall.LoadLevel();
            food = new Food(0, 0, 'o', ConsoleColor.Cyan);
            food.Generate(snake, wall);


            g_objects = new List <GameObject>();
            g_objects.Add(snake);
            g_objects.Add(food);
            g_objects.Add(wall);

            Console.CursorVisible = false;
        }
예제 #11
0
파일: Game.cs 프로젝트: VitaliyOleinik/PP2
        public Game()
        {
            g_objects = new List <GameObject>();
            snake     = new Snake(20, 10, '*', ConsoleColor.White);
            food      = new Food(0, 0, 'o', ConsoleColor.Cyan);
            wall      = new Wall('#', ConsoleColor.Green);
            wall.LoadLevel();
            while (food.IsCollisionWithObject(snake) || food.IsCollisionWithObject(wall))
            {
                food.Generate();
            }

            g_objects.Add(snake);
            g_objects.Add(food);
            g_objects.Add(wall);
            isAlive = true;
        }
예제 #12
0
        public Game()
        {
            g_objects = new List <GObject>();

            snake = new Snake(1, 1, '*', ConsoleColor.White);
            wall  = new Wall('#', ConsoleColor.Green);
            wall.LoadLevel();
            food = new Food(0, 0, 'o', ConsoleColor.Red);

            food.Generate(snake, wall);


            g_objects.Add(snake);
            g_objects.Add(food);
            g_objects.Add(wall);

            isAlive = true;
        }
예제 #13
0
파일: Game.cs 프로젝트: abkabd/PP2_2018S
        public Game()
        {
            isAlive   = true;
            gameLevel = GameLevel.First;

            worm = new Worm(new Point {
                X = 10, Y = 10
            },
                            ConsoleColor.White, '*');
            food = new Food(new Point {
                X = 20, Y = 10
            },
                            ConsoleColor.White, '+');

            food.Draw();
            wall = new Wall(null, ConsoleColor.White, '#');

            wall.LoadLevel(GameLevel.First);
            wall.Draw();
        }
예제 #14
0
        public Game()
        {
            isAlive = true;

            worm = new Worm(new Point {
                X = 10, Y = 10
            },
                            ConsoleColor.White, '*');
            food = new Food(new Point {
                X = 20, Y = 10
            },
                            ConsoleColor.Magenta, 'o');
            wall = new Wall(null, ConsoleColor.White, '#');

            wall.LoadLevel(1);

            g_objects.Add(worm);
            g_objects.Add(food);
            g_objects.Add(wall);
        }
예제 #15
0
        public Game()
        {
            gameLevel = GameLevel.First;

            worm = new Worm(new Point {
                X = 10, Y = 10
            },
                            ConsoleColor.White, '*');
            food = new Food(new Point {
                X = 14, Y = 10
            },
                            ConsoleColor.White, '+');
            wall = new Wall(null, ConsoleColor.White, '#');

            wall.LoadLevel(GameLevel.First);


            wormTimer          = new Timer();
            wormTimer.Interval = 500;
            wormTimer.Elapsed += T_Elapsed;
        }
예제 #16
0
        public Game()
        {
            isAlive   = true;
            gameLevel = GameLevel.First;

            worm = new Worm(new Point {
                X = 10, Y = 10
            },
                            ConsoleColor.DarkYellow, '▲');
            food = new Food(new Point {
                X = 20, Y = 10
            },
                            ConsoleColor.White, '☺');
            wall = new Wall(null, ConsoleColor.White, '#');

            wall.LoadLevel(GameLevel.First);

            g_objects.Add(worm);
            g_objects.Add(food);
            g_objects.Add(wall);
        }
예제 #17
0
파일: GameState.cs 프로젝트: luikaaa27/PP2
 void CheckFood()
 {
     if (w.CheckCollision(f.body[0]))
     {
         point += 100 + level * 10;
         w.Eat(f.body[0]);
         if (point >= levels[level])
         {
             level++;
             speed -= 50;
             b.LoadLevel(level);
             Console.BackgroundColor = ConsoleColor.Gray;
             b.Draw();
             Console.BackgroundColor = ConsoleColor.Black;
         }
         f.Generate(new object[] { w, b });
         Console.ForegroundColor = ConsoleColor.Red;
         f.Draw();
         Console.ForegroundColor = ConsoleColor.Green;
     }
 }
예제 #18
0
        /* private void ChangeTime(object sender, ElapsedEventArgs e)
         * {
         *   Console.SetCursorPosition(47, 27);
         *   Console.WriteLine(DateTime.Now.Second);
         * }*/

        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            w.Clear();
            w.Move();
            if (!end)
            {
                w.Draw();
            }
            CheckFood();
            if (Bally.Score >= 20)
            {
                b.body.Clear();
                Console.Clear();
                b.LoadLevel(2);
                Bally.PrevS += Bally.Score;
                Bally.Score  = 0;
            }
            CheckWall();
            if (w.body.Count >= 4)
            {
                CheckBody();
            }
        }
예제 #19
0
파일: Game.cs 프로젝트: aseksenali/PP2
        public void Play(int speed)
        {
            Console.BackgroundColor = ConsoleColor.Cyan;
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.Clear();
            snake.DrawOnLoad();
            level.LoadLevel(levelNumber);

            do
            {
                food.Draw();
            } while (snake.getHistory().Contains(new Tuple <int, int>(food.x_position, food.y_position)) || level.walls[food.x_position, food.y_position] == 1);

            food.Show();

            do
            {
                while (!Console.KeyAvailable && snake.isAlive())
                {
                    Console.SetCursorPosition(75, 31);
                    if (score < 10)
                    {
                        Console.Write("0");
                    }
                    Console.Write(score);


                    if (snake.X_position == food.x_position && snake.Y_position == food.y_position)
                    {
                        snake.Eat(food);
                        score++;
                        if (score == 20)
                        {
                            score = 0;
                            ChangeLevel();
                            Console.Clear();
                            level.LoadLevel(levelNumber);
                            snake = new Snake(1, 1);
                        }
                        Console.SetCursorPosition(75, 31);
                        Console.Write(score);
                        do
                        {
                            food.Draw();
                        } while (level.walls[food.x_position, food.y_position] == 1 || snake.getHistory().Contains(new Tuple <int, int>(food.x_position, food.y_position)));

                        food.Show();
                    }

                    if (level.walls[snake.X_position, snake.Y_position] == 1)
                    {
                        snake.Kill();
                        break;
                    }

                    snake.Move(snake.prev);
                    if (snake.prev == Direction.LEFT || snake.prev == Direction.RIGHT)
                    {
                        Thread.Sleep(333 - 27 * speed);
                    }
                    else if (snake.prev == Direction.TOP || snake.prev == Direction.BOTTOM)
                    {
                        Thread.Sleep(500 - 40 * speed);
                    }
                    snake.Draw();
                }
                if (snake.isAlive())
                {
                    ConsoleKeyInfo csi = Console.ReadKey(true);
                    switch (csi.Key)
                    {
                    case ConsoleKey.UpArrow:
                        if (snake.prev != Direction.BOTTOM)
                        {
                            snake.prev = Direction.TOP;
                        }
                        break;

                    case ConsoleKey.DownArrow:
                        if (snake.prev != Direction.TOP)
                        {
                            snake.prev = Direction.BOTTOM;
                        }
                        break;

                    case ConsoleKey.LeftArrow:
                        if (snake.prev != Direction.RIGHT)
                        {
                            snake.prev = Direction.LEFT;
                        }
                        break;

                    case ConsoleKey.RightArrow:
                        if (snake.prev != Direction.LEFT)
                        {
                            snake.prev = Direction.RIGHT;
                        }
                        break;

                    case ConsoleKey.Escape:
                        Serialize();
                        snake.Kill();
                        break;
                    }
                }
            } while (snake.isAlive());
            Serialize_Record();
        }
예제 #20
0
 public void MoveSnakeThread()
 {
     speed    = 200;
     playGame = true;
     Console.SetWindowSize(100, 31);
     food.x = 10;
     food.y = 10;
     wall.LoadLevel(levelCount);
     wall.Draw();
     Console.ForegroundColor = ConsoleColor.DarkRed;
     Console.SetCursorPosition(10, 10);
     Console.Write('@');
     Console.ForegroundColor = ConsoleColor.Black;
     while (playGame == true)
     {
         moovable = false;
         if (snake.body[0].x == food.x && snake.body[0].y == food.y)
         {
             snake.AddToBody();
             food.NewPosition(snake.body, wall.body);
             score++;
             moovable = true;
             speed    = Math.Max(100, speed - 10);
         }
         if (score == 5 && levelCount == 1)
         {
             x = 1;
             y = 0;
             levelCount++;
             wall.LoadLevel(levelCount);
             snake.body.Clear();
             wall.Draw();
             snake.body.Add(new Point(4, 3));
             snake.body.Add(new Point(3, 3));
             snake.body.Add(new Point(2, 3));
         }
         if (score == 10)
         {
             Console.Clear();
             Console.SetCursorPosition(0, 0);
             Console.Write("Your score is : ");
             Console.WriteLine(score + sc);
             Console.WriteLine("Press escape to continue");
             Console.ForegroundColor = ConsoleColor.Black;
             break;
         }
         if (snake.CheckGame(wall.body) == true)
         {
             Console.Clear();
             playGame = false;
             Console.SetCursorPosition(0, 0);
             Console.Write("Your score is : ");
             Console.WriteLine(score + sc);
             Console.WriteLine("Press escape to continue");
             Console.ForegroundColor = ConsoleColor.Black;
             break;
         }
         Console.ForegroundColor = ConsoleColor.DarkRed;
         Console.SetCursorPosition(food.x, food.y);
         Console.WriteLine("@");
         Console.SetCursorPosition(0, 23);
         Console.ForegroundColor = ConsoleColor.Magenta;
         Console.WriteLine("Score: ");
         Console.SetCursorPosition(7, 23);
         Console.Write(score);
         snake.Move(x, y, moovable);
         snake.Draw();
         Thread.Sleep(speed);
     }
 }
예제 #21
0
 public void Level()
 {
     wall.LoadLevel(score / 3 + 1);
     wall.Draw();
 }
예제 #22
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;
                    }
                }
            }
        }
예제 #23
0
        public void PressedKey(ConsoleKeyInfo consoleKeyInfo)
        {
            switch (consoleKeyInfo.Key)
            {
            case ConsoleKey.UpArrow:
                if (w.body.Count > 1)
                {
                    if (movement != "down")
                    {
                        w.Move(0, -1);
                        movement = "up";
                    }
                }
                else
                {
                    w.Move(0, -1);
                    movement = "up";
                }
                break;

            case ConsoleKey.DownArrow:
                if (w.body.Count > 1)
                {
                    if (movement != "up")
                    {
                        w.Move(0, 1);
                        movement = "down";
                    }
                }
                else
                {
                    w.Move(0, 1);
                    movement = "down";
                }
                break;

            case ConsoleKey.LeftArrow:
                if (w.body.Count > 1)
                {
                    if (movement != "right")
                    {
                        w.Move(-1, 0);
                        movement = "left";
                    }
                }
                else
                {
                    w.Move(-1, 0);
                    movement = "left";
                }
                break;

            case ConsoleKey.RightArrow:
                if (w.body.Count > 1)
                {
                    if (movement != "left")
                    {
                        w.Move(1, 0);
                        movement = "right";
                    }
                }
                else
                {
                    w.Move(1, 0);
                    movement = "right";
                }
                break;
            }

            CheckFood();
            if (Bally.Score >= 20)
            {
                b.body.Clear();
                Console.Clear();
                b.LoadLevel(2);
                Bally.PrevS += Bally.Score;
                Bally.Score  = 0;
            }
            CheckWall();
            if (w.body.Count >= 4)
            {
                CheckBody();
            }
        }
예제 #24
0
        public void MoveSnakeThread()
        {
            int speedReturn = speed;

            playGame = true;
            Console.SetWindowSize(100, 31);
            food.x = 10;
            food.y = 10;
            wall.LoadLevel(levelCount);
            wall.Draw();
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.SetCursorPosition(10, 10);
            Console.Write('@');
            Console.ForegroundColor = ConsoleColor.Black;
            int pos = -1;

            while (playGame)
            {
                for (int i = 0; i < highScores.name.Count; i++)
                {
                    if (highScores.name[i] == Program.login)
                    {
                        pos = i;
                        break;
                    }
                }
                if (pos == -1)
                {
                    highScores.name.Add(Program.login);
                    highScores.score.Add(0);
                    pos = highScores.name.Count - 1;
                }
                moovable = false;
                if (snake.body[0].x == food.x && snake.body[0].y == food.y)
                {
                    snake.AddToBody();
                    food.NewPosition(snake.body, wall.body);
                    score++;
                    moovable = true;
                    speed    = Math.Max(100, speed - 10);
                }
                highScores.score[pos] = Math.Max(score + sc, highScores.score[pos]);
                if (score != 0 && score % 5 == 0 && levelCount < maxLevel)
                {
                    x = 1;
                    y = 0;
                    levelCount++;
                    wall.LoadLevel(levelCount);
                    snake.body.Clear();
                    wall.Draw();
                    snake.body.Add(new Point(4, 3));
                    snake.body.Add(new Point(3, 3));
                    snake.body.Add(new Point(2, 3));
                    score = 0;
                    sc    = levelCount * 5 - 5;
                }
                if (score != 0 && score % 5 == 0 && levelCount == maxLevel)
                {
                    Console.Clear();
                    Console.SetCursorPosition(0, 0);
                    Console.Write("Your score is : ");
                    Console.WriteLine(score + sc);
                    Console.Write("Your maximail score is : ");
                    Console.WriteLine(highScores.score[pos]);
                    Console.WriteLine("Press escape to continue");
                    Console.ForegroundColor = ConsoleColor.Black;
                    //Console.ReadKey();
                    break;
                }
                if (snake.CheckGame(wall.body))
                {
                    Console.Clear();
                    playGame = false;
                    Console.SetCursorPosition(0, 0);
                    Console.Write("Your score is : ");
                    Console.WriteLine(score + sc);
                    Console.Write("Your maximail score is : ");
                    Console.WriteLine(highScores.score[pos]);
                    Console.WriteLine("Press escape to continue");
                    Console.ForegroundColor = ConsoleColor.Black;
                    break;
                }
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.SetCursorPosition(food.x, food.y);
                Console.WriteLine("@");
                Console.SetCursorPosition(0, 23);
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine("Score: ");
                Console.SetCursorPosition(7, 23);
                Console.Write(score + sc);
                snake.Move(x, y, moovable);
                snake.Draw();
                Thread.Sleep(speed);
            }
            SaveHighScore(highScores);
            speed = speedReturn;
        }
예제 #25
0
        public void Draw()
        {
            food.Draw();
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.SetCursorPosition(15, 24);

            Console.WriteLine("SCORE:{0}", score);
            wall.Draw();

            while (true)
            {
                worm.Move();
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.SetCursorPosition(15, 24);
                Console.WriteLine("              ");
                Console.SetCursorPosition(15, 24);
                Console.WriteLine("SCORE:{0}", score);

                if (worm.body[0].Equals(food.body[0]))
                {
                    worm.body.Add(new Point {
                        X = food.body[0].X, Y = food.body[0].Y
                    });
                    food.body[0] = food.CreateFood(wall.body, worm.body);

                    score++;
                }
                else
                {
                    foreach (Point p in wall.body)
                    {
                        if (p.Equals(worm.body[0]))
                        {
                            Console.Clear();
                            Console.SetCursorPosition(10, Game.boardH / 2);
                            Console.WriteLine("GAME OVER!!!");
                            isAlive = false;
                            Console.ForegroundColor = ConsoleColor.Black;

                            Stop();
                        }
                    }
                }
                if (score == 3)
                {
                    wall.CleanBody();


                    interval  = 200;
                    gameLevel = GameLevel.Second;
                    wall.LoadLevel(GameLevel.Second);

                    Console.Clear();
                    wall.Draw();

                    food.body[0] = food.CreateFood(wall.body, worm.body);
                    worm.body.Clear();
                    worm.body.Add(new Point {
                        X = 24, Y = 16
                    });
                    score++;
                    continue;
                }
                worm.Draw();
                food.Draw();
                Thread.Sleep(Game.interval);
            }
        }
예제 #26
0
        public void PressedKey(ConsoleKeyInfo consoleKeyInfo)
        {
            switch (consoleKeyInfo.Key)
            {
            case ConsoleKey.UpArrow:
                worm.Dx = 0;
                worm.Dy = -speed;
                break;

            case ConsoleKey.DownArrow:
                worm.Dx = 0;
                worm.Dy = speed;
                break;

            case ConsoleKey.LeftArrow:
                worm.Dx = -speed;
                worm.Dy = 0;
                break;

            case ConsoleKey.RightArrow:
                worm.Dx = speed;
                worm.Dy = 0;
                break;

            case ConsoleKey.Spacebar:
                timer.Enabled = !timer.Enabled;
                break;

            case ConsoleKey.Escape:
                Console.Clear();
                Console.SetCursorPosition(20, 30);
                Console.WriteLine("Exit?");
                Environment.Exit(0);
                break;

            case ConsoleKey.F2:
                Console.Clear();
                worm.body.Clear();
                worm.body.Add(new Point {
                    X = 20, Y = 20
                });
                wall.LoadLevel(2);
                wall.Draw();
                food.Generate(wall.body, worm.body);
                food.Draw();
                level = 2;

                break;

            case ConsoleKey.F3:
                Console.Clear();
                worm.body.Clear();
                worm.body.Add(new Point {
                    X = 20, Y = 20
                });
                wall.LoadLevel(3);
                wall.Draw();
                food.Draw();
                food.Generate(wall.body, worm.body);
                level = 3;
                speed = 2;
                break;
            }

            CheckColision();
        }