예제 #1
0
 public void Draw() //метод для рисования игры
 {
     Console.Clear();
     food.Draw();
     snake.Draw();
     wall.Draw();
     DrawStatus();
 }
예제 #2
0
 public void Run()
 {
     worm.Draw();
     timer.Elapsed += elapsed;
     timer.Interval = 300;
     timer.Start();
     food.Draw();
     wall.Draw();
 }
예제 #3
0
        public void Run()
        {
            ThreadStart action = new ThreadStart(ChangeFrame);
            Thread      task   = new Thread(action);

            task.Start();
            food.Draw();
            wall.Draw();
        }
예제 #4
0
파일: GameState.cs 프로젝트: luikaaa27/PP2
 public void Run()
 {
     timer.Elapsed += Timer_Elapsed;
     timer.Start();
     Console.ForegroundColor = ConsoleColor.Red;
     f.Draw();
     Console.ForegroundColor = ConsoleColor.Green;
     Console.BackgroundColor = ConsoleColor.White;
     b.Draw();
     Console.BackgroundColor = ConsoleColor.Black;
 }
예제 #5
0
파일: GameState.cs 프로젝트: Groompel/PP2
        public void Run()
        {
            CheckCollision();
            food.Draw();
            worm.Draw();
            wall.Draw();
            consoleKeyInfo = Console.ReadKey();
            switch (consoleKeyInfo.Key)
            {
            case ConsoleKey.UpArrow:
                dir = Dir.UP;
                break;

            case ConsoleKey.DownArrow:
                dir = Dir.DOWN;
                break;

            case ConsoleKey.LeftArrow:
                dir = Dir.LEFT;
                break;

            case ConsoleKey.RightArrow:
                dir = Dir.RIGHT;
                break;
            }
        }
예제 #6
0
파일: Game.cs 프로젝트: Nuralievjr/PP2
 public static void Draw()
 {
     Console.Clear();
     snake.Draw();
     food.Setup();
     wall.Draw();
 }
예제 #7
0
        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);
            }
        }
예제 #8
0
        static void Main(string[] args)
        {
            Snake snake = new Snake();
            Wall  wall  = new Wall();

            while (true)
            {
                ConsoleKeyInfo press = Console.ReadKey();
                if (press.Key == ConsoleKey.UpArrow)
                {
                    snake.Move(0, -1);
                }
                if (press.Key == ConsoleKey.DownArrow)
                {
                    snake.Move(0, 1);
                }
                if (press.Key == ConsoleKey.LeftArrow)
                {
                    snake.Move(-1, 0);
                }
                if (press.Key == ConsoleKey.RightArrow)
                {
                    snake.Move(1, 0);
                }

                if (press.Key == ConsoleKey.Escape)
                {
                    break;
                }

                Console.Clear();
                snake.Draw();
                wall.Draw();
            }
        }
예제 #9
0
 public static void func()
 {
     while (true)
     {
         if (direction == 3)
         {
             snake.Move(0, 1);
         }
         if (direction == 4)
         {
             snake.Move(0, -1);
         }
         if (direction == 2)
         {
             snake.Move(-1, 0);
         }
         if (direction == 1)
         {
             snake.Move(1, 0);
         }
         if (gameOver)
         {
             break;
         }
         Console.Clear();
         snake.Draw();
         wall.Draw();
         Thread.Sleep(speed);
     }
 }
예제 #10
0
        public void Draw()
        {
            Console.Clear();
            Console.SetCursorPosition(0, 0);
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    if (i == 0 || i == height - 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write('#');
                    }
                    else if (j == 0 || j == width - 1)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write('#');
                    }
                }
                Console.WriteLine();
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Username: "******"Your score: " + score);
            Console.WriteLine("Level: " + degree);

            w.Draw();
            f.Draw();
            b.Draw();
        }
예제 #11
0
        /*public void Run()
         * {
         *  ThreadStart action = new ThreadStart(ChangeFrame);
         *  Thread task = new Thread(action);
         *  task.Start();
         *  food.Draw();
         *  wall.Draw();
         * }*/
        public void Run2()
        {
            timer.Elapsed += Timer_Elapsed;
            timer.Start();

            gameTime.Elapsed += GameTime_Elapsed;
            gameTime.Start();

            wall.Draw();
            if (food.body.Count == 0)
            {
                food.Generate(worm.body, wall.body);
            }

            food.Draw();
        }
예제 #12
0
        static void TestWall()
        {
            Wall wall = new Wall('#', ConsoleColor.Green);

            wall.LoadLevel(1);

            wall.Draw();
        }
예제 #13
0
 public GameState()
 {
     Console.SetWindowSize(40, 40);
     Console.SetBufferSize(40, 40);
     Console.CursorVisible = false;
     Console.Clear();
     wall.Draw();
 }
예제 #14
0
파일: Game.cs 프로젝트: abzalmyrzash/PP-II
 public static void Draw()
 {
     snake.Draw();
     wall.Draw();
     food.Draw();
     Program.ShowScore();
     Program.FindSpeed();
 }
예제 #15
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");
        }
예제 #16
0
        public void Run()
        {
            timer.Elapsed += Timer_Elapsed;
            timer.Start();

            food.GenerateLocation(worm.body, wall.body);
            wall.Draw();
            food.Draw();
        }
예제 #17
0
파일: GameState.cs 프로젝트: Aigerim22/pp2
 public void Draw()
 {
     if (!gameOver)
     {
         w.Draw();
         f.Draw();
         b.Draw();
     }
 }
예제 #18
0
파일: Game.cs 프로젝트: shyngys18/PP2
 public static void Draw()
 {
     //Console.Clear();
     snake.Draw();
     food.Draw();
     wall.Draw();
     Console.SetCursorPosition(0, 21);
     Console.WriteLine("Your Score: " + score);
 }
예제 #19
0
 public void Draw()
 {
     if (!gameOver)
     {
         worm.Draw();
         food.Draw();
         wall.Draw();
     }
 }
예제 #20
0
        public void Draw()
        {
            if (!end)
            {
                w.Draw();
            }

            f.Draw();
            b.Draw();
        }
예제 #21
0
 public void Draw()
 {
     worm.Draw();
     wall.Draw();
     if (food.body.Count == 0)
     {
         food.Generate(worm.body, wall.body);
     }
     food.Draw();
 }
예제 #22
0
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">Some arguments</param>
        private static void Main(string[] args)
        {
            var isGameOn = true;

            var  game  = new Game(28, 70, 10, 10, 'X', 'O', 200m);
            Food food  = new FoodAt(17, 20);
            var  wall  = new Wall(game.WindowHeigth, game.WindowWidth, game.WallSymbol);
            var  snake = new Snake(
                new Point(
                    game.SnakeStartPositionX,
                    game.SnakeStartPositionY,
                    game.SnakeSymbol),
                Direction.Right);

            Console.WindowHeight  = game.WindowHeigth + 2;
            Console.WindowWidth   = game.WindowWidth + 2;
            Console.CursorVisible = false;

            wall.Draw();
            food.Draw();

            ConsoleKey command = ConsoleKey.RightArrow;

            while (isGameOn)
            {
                System.Threading.Thread.Sleep((int)game.Speed);

                if (Console.KeyAvailable)
                {
                    command = Console.ReadKey().Key;
                    snake.HandleKey(command);
                }

                snake.MoveSnake();

                if (snake.Eat(food))
                {
                    game.AddSpeed();
                    food = CreateFood(game);
                    food.Draw();
                }

                var isWallHit = snake.DidSnakeHitWall(snake, game.WindowWidth, game.WindowHeigth);

                if (isWallHit)
                {
                    isGameOn = false;
                    Console.SetCursorPosition(10, 10);
                    Console.WriteLine("The snke hit the wall and died.");
                }
            }

            ContinueTheGameOrNot();
        }
예제 #23
0
        public void Run(string ass)
        {
            Thread thread = new Thread(MoveSnake);

            thread.Start();

            project(ass);
            food.GenerateLocation(worm.body, wall.body);

            wall.Draw();
            food.Draw();
        }
예제 #24
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");
        }
예제 #25
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(40, 50);
            Console.SetBufferSize(40, 50);
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Continue - 1");
            Console.WriteLine("New game - 2");
            Console.WriteLine("Pause - space");
            string option = Console.ReadLine();
            Food   food1  = new Food();

            Console.Clear();
            if (option == "1")
            {
                System system = Deserialize();
                food1.WhereisFood(system.wall, system.worm);
                Keys(system.wall, system.worm, food1);
                if (!system.worm.isAlive)
                {
                    Console.WriteLine("Start new game?");
                    Console.WriteLine("2-yes");
                    string option1 = Console.ReadLine();
                    if (option1 == "2")
                    {
                        Console.Clear();
                        Console.SetWindowSize(40, 40);
                        Worm worm = new Worm();
                        Console.Clear();
                        Global.level = 1;
                        Wall wall = new Wall(Global.level);
                        wall.Draw();
                        Food food = new Food();
                        food.WhereisFood(wall, worm);

                        ///  System system = new System(wall, worm);
                        Keys(wall, worm, food);
                    }
                }
            }
            else
            {
                Console.SetWindowSize(40, 40);
                Worm worm = new Worm();

                Wall wall = new Wall(Global.level);
                wall.Draw();
                Food food = new Food();
                food.WhereisFood(wall, worm);

                ///  System system = new System(wall, worm);
                Keys(wall, worm, food);
            }
        }
예제 #26
0
        static void Draw()
        {
            Console.Clear();

            snake.Draw();
            food.Draw();
            wall.Draw();
            while (alive)
            {
                Thread.Sleep(250);
                snake.Clear();

                snake.Move();
                if (snake.intersect((GameObject)food))
                {
                    snake.upgrade();
                    food.Clear();
                    food.setPoint(getEmptyCell());
                    food.Draw();
                    score++;
                    curscore++;
                }
                if (wall.intersect(snake.points[0]))
                {
                    alive = false;
                    break;
                }


                snake.Draw();

                Console.SetCursorPosition(0, HEIGHT);
                Console.Write("Score: {0}   Level: {1}", score, level);
                if (curscore == 5)
                {
                    curscore = 0;
                    level++;
                    Console.Clear();
                    wall = new Wall();
                    for (int i = 1; i <= 10 * (level + 1); i++)
                    {
                        wall.points.Add(getEmptyCell());
                    }

                    snake.Draw();
                    food.Draw();
                    wall.Draw();

                    Thread.Sleep(1000);
                }
            }
        }
예제 #27
0
        public void Run()
        {
            timer.Elapsed += Timer_Elapsed;
            timer.Start();

            wall = new Wall('#', LevelNumber, c);
            wall.Draw();
            food.GenerateLocation(worm.body, wall.body);
            food.Draw();

            scoreLevel.Draw();
            //player.Draw();
        }
예제 #28
0
        public void Run(int diff)
        {
            this.diff      = diff;
            this.diff     += score / 4;
            timer.Elapsed += Timer_Elapsed;
            timer.Interval = 400 - this.diff * 85;
            timer.Start();

            Console.ForegroundColor = ConsoleColor.Green;
            f.Draw();
            Console.ResetColor();
            b.Draw();
        }
예제 #29
0
 public void Draw()
 {
     if (!gameOver)
     {
         wall = new Wall('#', LevelNumber);
         worm.Draw();
         food.Draw();
         wall.Draw();
         //player.score.Draw();
         scoreLevel.Draw();
         player.Draw();
     }
 }
예제 #30
0
        public void Run()
        {
            timer2.Elapsed += ChangeTime;
            timer2.Interval = 1000;
            timer2.Start();

            timer.Elapsed += Timer_Elapsed;
            timer.Interval = 120;
            timer.Start();

            f.Draw();
            b.Draw();
        }
예제 #31
0
파일: Program.cs 프로젝트: 11Vector11/Snake
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);

            Wall walls = new Wall(80, 25);
            walls.Draw();

            //Отрисовка точек
            Point p = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);
            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point food = foodCreator.CreateFood();
            food.Draw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }

                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            WriteGameOver();
            Console.ReadLine();
        }