コード例 #1
0
ファイル: Program.cs プロジェクト: Alibek120699/PP2
        static void Main(string[] args)
        {
            Game game = new Game();

            game.SetupBoard();

            while (game.isAlive)
            {
                game.Draw();
                game.Process();
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: baibolatovads/Week-6
        static void Main(string[] args)
        {
            Game game = new Game();

            game.SetupBoard();

            while (game.isAlive)
            {
                game.Draw();
                ConsoleKeyInfo pressedButton = Console.ReadKey();
                game.Process(pressedButton);
            }
        }
コード例 #3
0
        private static void Main()
        {
            Console.Clear();
            Renderer.Init();
            var game = new Game();

            game.Init();
            while (Running)
            {
                game.Update();
                game.Draw();
                Renderer.Draw();
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: abzalmyrzash/PP-II
        static void DrawMove()
        {
            while (true)
            {
                if (!Game.pause)
                {
                    Game.snake.Move(Game.snake.direction);

                    Thread.Sleep(Game.snake.speed);

                    if (Game.snake.body[0].x > 69)
                    {
                        Game.snake.body[0].x = 0;
                    }
                    else if (Game.snake.body[0].x < 0)
                    {
                        Game.snake.body[0].x = 69;
                    }

                    if (Game.snake.body[0].y > 19)
                    {
                        Game.snake.body[0].y = 0;
                    }
                    else if (Game.snake.body[0].y < 0)
                    {
                        Game.snake.body[0].y = 19;
                    }

                    if (Game.snake.AteFood())
                    {
                        Game.food.SetRandomPosition();
                    }

                    Game.CheckGameOver();
                    if (Game.Over)
                    {
                        break;
                    }

                    Game.Draw();
                }
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: aimlee/PPII
        static void MoveSnakeTimer(object state)
        {
            switch (direction)
            {
            case 1:
                Game.snake.Move(1, 0);
                break;

            case 2:
                Game.snake.Move(0, 1);
                break;

            case 3:
                Game.snake.Move(-1, 0);
                break;

            case 4:
                Game.snake.Move(0, -1);
                break;
            }
            Game.Draw();
        }
コード例 #6
0
        void MenuAction()
        {
            switch (menu.ind)
            {
            case 0:
                mode     = Mode.play;
                lvl      = GameLvl.first;
                game.lvl = lvl;
                game.CreateNewLvl(game.lvl);
                game.LoadColors(snakecolor, headcolor, wallcolor, foodcolor);
                game.CreateNewFood();
                game.Draw();
                break;

            case 1:
                mode = Mode.play;
                game = Game.Load();
                game.LoadColors(snakecolor, headcolor, wallcolor, foodcolor);
                game.Draw();
                game.StopSnake();
                break;

            case 2:
                menu.ChangeOptions();
                menumode = menu.menumode;
                menu.DrawAll();
                break;

            case 3:
                break;

            case 4:
                Switch = false;
                EndProcess();
                break;
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: makeevnikita/GospodinSnake
        static void Main(string[] args)
        {
            string[,] map = new string[width, height];
            string e     = "Легко";
            string m     = "Средний";
            string h     = "Сложный";
            int    menu  = 0;
            bool   start = false;

            Console.WriteLine("Выберете сложность (стрелки вверх и вниз) и нажмите Enter");
            while (start == false)
            {
                if (menu == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.SetCursorPosition(0, 1);
                    Console.WriteLine(e);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.SetCursorPosition(0, 2);
                    Console.WriteLine(m);
                    Console.SetCursorPosition(0, 3);
                    Console.WriteLine(h);
                }
                else if (menu == 1)
                {
                    Console.SetCursorPosition(0, 1);
                    Console.WriteLine(e);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.SetCursorPosition(0, 2);
                    Console.WriteLine(m);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.SetCursorPosition(0, 3);
                    Console.WriteLine(h);
                }
                else if (menu == 2)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.SetCursorPosition(0, 1);
                    Console.WriteLine(e);
                    Console.SetCursorPosition(0, 2);
                    Console.WriteLine(m);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.SetCursorPosition(0, 3);
                    Console.WriteLine(h);
                    Console.ForegroundColor = ConsoleColor.White;
                }
                if (Console.KeyAvailable == true)
                {
                    f = Console.ReadKey();
                    if (f.Key == ConsoleKey.UpArrow)
                    {
                        if (menu != 0)
                        {
                            --menu;
                        }
                    }
                    if (f.Key == ConsoleKey.DownArrow)
                    {
                        if (menu != 2)
                        {
                            ++menu;
                        }
                    }
                    if (f.Key == ConsoleKey.Enter)
                    {
                        start = true;
                    }
                }
            }
            Console.Clear();


            if (menu == 0)
            {
                width  = 10;
                height = 10;
                map    = new string[width, height];
                speed  = 400;
            }
            else if (menu == 1)
            {
                width  = 15;
                height = 15;
                map    = new string[width, height];
                speed  = 250;
            }
            else if (menu == 2)
            {
                width  = 20;
                height = 20;
                map    = new string[width, height];
                speed  = 100;
            }
            Random rnd = new Random();

            headX = width / 2; headY = height / 2;
            while (true)
            {
                fruitX = rnd.Next(1, width - 2); fruitY = rnd.Next(1, height - 2);
                if (fruitX == headX && fruitY == headY || fruitX != headX && fruitY == headY || fruitX != headX && fruitY != headY)
                {
                    break;
                }
            }
            while (game == true)
            {
                Game.Draw(width, height, ref headX, ref headY, ref fruitX, ref fruitY, ref map);
                Game.Move(width, height, ref headX, ref headY, move, ref map);
                Game.EatGenerate(ref score, width, height, ref map, headX, headY, ref fruitX, ref fruitY, ref eat, masX, masY);
                Game.Tail(ref masX, ref masY, ref map, ref eat, ref size, headX, headY);
                Game.Lose(width, height, masX, masY, headX, headY, ref game, size);
                Game.Win(width, height, map, ref game);
                for (int i = 0; i < width; i++)
                {
                    for (int j = 0; j < height; j++)
                    {
                        Console.SetCursorPosition(j, i);
                        Console.Write(map[i, j]);
                    }
                    Console.WriteLine();
                }
                Console.SetCursorPosition(0, height);
                Console.WriteLine("Длина змейки: " + size);

                if (Console.KeyAvailable == true)
                {
                    f = Console.ReadKey();
                    if (f.Key == ConsoleKey.UpArrow)
                    {
                        if (move != "Down")
                        {
                            move = "Up";
                        }
                    }
                    if (f.Key == ConsoleKey.DownArrow)
                    {
                        if (move != "Up")
                        {
                            move = "Down";
                        }
                    }
                    if (f.Key == ConsoleKey.RightArrow)
                    {
                        if (move != "Left")
                        {
                            move = "Right";
                        }
                    }
                    if (f.Key == ConsoleKey.LeftArrow)
                    {
                        if (move != "Right")
                        {
                            move = "Left";
                        }
                    }
                }
                Thread.Sleep(speed);
            }
        }
コード例 #8
0
 private void OnPaint(object sender, PaintEventArgs e)
 {
     m_GameGraphics.Clear(m_BackgroundColor);
     m_Game.Draw(m_GameGraphics);
     e.Graphics.DrawImage(m_GameField, 0, m_RestartBtn.Height);
 }
コード例 #9
0
 private void OnPaint(object sender, PaintEventArgs e)
 {
     game.Draw(gameGraphics);
     e.Graphics.DrawImage(gameArea, 0, UpperMargin);
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: abzalmyrzash/PP-II
        public static void Main(string[] args)
        {
            Console.SetWindowSize(120, 30);

            Console.CursorVisible = false;
            Console.Clear();

            Game.Init();
            Console.Clear();

            DrawFrame();
            Game.wall.Draw();

            Game.Draw();
            Thread myThread = new Thread(DrawMove);

            myThread.Start();


            while (!Game.exit && !Game.Over)
            {
                while (!Game.Over)
                {
                    if (Console.KeyAvailable)
                    {
                        bool           tryagain = false;
                        ConsoleKeyInfo btn;
                        if (!Game.Over)
                        {
                            btn = Console.ReadKey(true);
                        }
                        else
                        {
                            break;
                        }

                        if (btn.Key != ConsoleKey.P)
                        {
                            Game.pause = false;
                            switch (btn.Key)
                            {
                            case ConsoleKey.W:
                                if (Game.snake.direction != 1 && Game.snake.direction != 2)
                                {
                                    Game.snake.direction = 1;
                                }
                                else
                                {
                                    tryagain = true;
                                }
                                break;

                            case ConsoleKey.S:
                                if (Game.snake.direction != 1 && Game.snake.direction != 2)
                                {
                                    Game.snake.direction = 2;
                                }
                                else
                                {
                                    tryagain = true;
                                }
                                break;

                            case ConsoleKey.A:
                                if (Game.snake.direction != 3 && Game.snake.direction != 4)
                                {
                                    Game.snake.direction = 3;
                                }
                                else
                                {
                                    tryagain = true;
                                }
                                break;

                            case ConsoleKey.D:
                                if (Game.snake.direction != 3 && Game.snake.direction != 4)
                                {
                                    Game.snake.direction = 4;
                                }
                                else
                                {
                                    tryagain = true;
                                }
                                break;

                            case ConsoleKey.Escape:
                                myThread.Abort();

                                Console.Clear();
                                Game.pause = true;
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("GAME PAUSE");
                                int      option  = 0;
                                string[] options = { "Resume", "Save the game and exit", "Exit without saving" };

                                while (true)
                                {
                                    Console.Clear();
                                    Console.WriteLine("GAME PAUSE");

                                    for (int i = 0; i < 3; i++)
                                    {
                                        if (option == i)
                                        {
                                            Console.BackgroundColor = ConsoleColor.White;
                                        }
                                        else
                                        {
                                            Console.BackgroundColor = ConsoleColor.Black;
                                        }

                                        Console.WriteLine(options[i]);
                                    }
                                    ConsoleKey key = Console.ReadKey(true).Key;
                                    switch (key)
                                    {
                                    case ConsoleKey.UpArrow:
                                        if (option > 0)
                                        {
                                            option--;
                                        }
                                        break;

                                    case ConsoleKey.DownArrow:
                                        if (option < 2)
                                        {
                                            option++;
                                        }
                                        break;
                                    }
                                    if (key == ConsoleKey.Enter)
                                    {
                                        if (option == 0)
                                        {
                                            Console.Clear();
                                            myThread = new Thread(DrawMove);
                                            myThread.Start();
                                            DrawFrame();
                                            Game.Draw();
                                            break;
                                        }

                                        else if (option == 1)
                                        {
                                            Game.Save();
                                            Game.exit = true;
                                            break;
                                        }

                                        else
                                        {
                                            Game.exit = true;
                                        }
                                        break;
                                    }

                                    if (key == ConsoleKey.Escape)
                                    {
                                        Console.Clear();
                                        myThread = new Thread(DrawMove);
                                        myThread.Start();
                                        DrawFrame();
                                        Game.Draw();
                                        break;
                                    }
                                }

                                break;
                            }
                        }
                        else
                        {
                            Game.pause = true;
                        }

                        if (!tryagain)
                        {
                            break;
                        }
                    }
                }
            }
        }