Exemplo n.º 1
0
 public static void draw(snake s)
 {
     Pen pen = new Pen(Color.FromArgb(255, 0, 0, 0));
     e.Graphics.DrawLine(pen, 20, 10, 300, 100);
     int x = s.x;
     int y = s.y;
 }
Exemplo n.º 2
0
 public void Level(Wall wall, snake snake)
 {
     if (snake.body.Count == 4)
     {
         Console.Clear();
         wall.cnt++;
         wall.ReadLevel();
         int a = 1;
         for (int i = 0; i < snake.body.Count; i++)
         {
             snake.body[i].x = a;
             snake.body[i].y = 10;
             a++;
         }
     }
     if (snake.body.Count == 8)
     {
         Console.Clear();
         wall.cnt++;
         wall.ReadLevel();
         int b = 1;
         for (int i = 0; i < snake.body.Count; i++)
         {
             snake.body[i].x = b;
             snake.body[i].y = 10;
             b++;
         }
     }
 }
Exemplo n.º 3
0
        public static void draw(snake s)
        {
            Pen pen = new Pen(Color.FromArgb(255, 0, 0, 0));

            e.Graphics.DrawLine(pen, 20, 10, 300, 100);
            int x = s.x;
            int y = s.y;
        }
Exemplo n.º 4
0
        public snake B()
        {
            XmlSerializer xs    = new XmlSerializer(typeof(snake));
            FileStream    fs    = new FileStream("snake.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            snake         snake = xs.Deserialize(fs) as snake;

            fs.Close();
            return(snake);
        }
Exemplo n.º 5
0
        public void SetRandomPosition(Wall wall, snake snake)
        {
            int x = new Random().Next(1, 25);
            int y = new Random().Next(1, 25);

            while (Checking(wall, snake, x, y))
            {
                x = new Random().Next(1, 25);
                y = new Random().Next(1, 25);
            }
            loc = (new Point(x, y));
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            snake.FinalWrite();
            name = Console.ReadLine();
            Console.Clear();
            Console.CursorVisible = false;
            food.SetRandomPosition(wall, snake);
            food.Draw();
            Thread thread = new Thread(Func);

            thread.Start();
            while (true)
            {
                if (k == 1)
                {
                    Console.ReadKey();
                    return;
                }
                ConsoleKeyInfo pk = Console.ReadKey();
                if (pk.Key == ConsoleKey.S)
                {
                    snake.A();
                    wall.A();
                    food.A();
                }
                if (pk.Key == ConsoleKey.V)
                {
                    Console.Clear();

                    snake = snake.B();
                    wall  = wall.B();
                    food  = food.B();
                }
                if (pk.Key == ConsoleKey.UpArrow)
                {
                    direction = 2;
                }
                if (pk.Key == ConsoleKey.DownArrow)
                {
                    direction = 1;
                }
                if (pk.Key == ConsoleKey.LeftArrow)
                {
                    direction = 4;
                }
                if (pk.Key == ConsoleKey.RightArrow)
                {
                    direction = 3;
                }
            }
        }
Exemplo n.º 7
0
 public bool Checking(Wall wall, snake snake, int x, int y)
 {
     for (int i = 0; i < wall.format.Count; i++)
     {
         for (int j = 0; j < snake.body.Count; j++)
         {
             if ((snake.body[j].x == x && snake.body[j].y == y) || (wall.format[i].x == x && wall.format[i].y == y))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 8
0
 public bool CollisionWithWall(snake snake, Wall wall)
 {
     for (int i = 1; i < snake.body.Count; i++)
     {
         for (int j = 0; j < wall.format.Count; j++)
         {
             if ((snake.body[0].x == snake.body[i].x && snake.body[0].y == snake.body[i].y) || (snake.body[0].x == wall.format[j].x && snake.body[0].y == wall.format[j].y))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            snake s = new snake(0, 0);
            ConsoleKeyInfo keyinfo;
            while (true)
            {
                keyinfo=Console.ReadKey();
               if (keyinfo.Key==ConsoleKey.Escape)
               {
                   break;
               }

               if (keyinfo.Key == ConsoleKey.UpArrow)
               {
                   s.moveUp();
               }

               if (keyinfo.Key == ConsoleKey.DownArrow)
               {
                   s.moveDawn();
               }

               if (keyinfo.Key == ConsoleKey.LeftArrow)
               {
                   s.moveLeft();
               }

               if (keyinfo.Key == ConsoleKey.RightArrow)
               {
                   s.moveRight();
               }

               Draw.draw(s);

            }
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            snake          s = new snake(0, 0);
            ConsoleKeyInfo keyinfo;

            while (true)
            {
                keyinfo = Console.ReadKey();
                if (keyinfo.Key == ConsoleKey.Escape)
                {
                    break;
                }

                if (keyinfo.Key == ConsoleKey.UpArrow)
                {
                    s.moveUp();
                }

                if (keyinfo.Key == ConsoleKey.DownArrow)
                {
                    s.moveDawn();
                }

                if (keyinfo.Key == ConsoleKey.LeftArrow)
                {
                    s.moveLeft();
                }

                if (keyinfo.Key == ConsoleKey.RightArrow)
                {
                    s.moveRight();
                }

                Draw.draw(s);
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            // some setup
            bool game = true;
            bool play = false;
            int  index;

            string prop = "Select your destiny:";

            string[] options1 = { "Start game", "Quit game" };
            string[] options2 = { "Main menu", "Quit game" };
            string[] options3 = { "Continue", "End game" };

            int banerY = 15;
            int score;

            string[] snakeBaner = new[]
            {
                @"   oo_                         ",
                @"  /  _)-<             _        ",
                @"  \__ `.             | |       ",
                @"     `. | _ __   __ _| | _____ ",
                @"     _| || '_ \ / _` | |/ / _ \",
                @"  ,-'   || | | | (_| |   <  __/",
                @"(_..--'  |_| |_|\__,_|_|\_\___|"
            };

            string[] gameover = new[]
            {
                @"   ██████╗  █████╗ ███╗   ███╗███████╗",
                @"  ██╔════╝ ██╔══██╗████╗ ████║██╔════╝",
                @"  ██║  ███╗███████║██╔████╔██║█████╗  ",
                @"  ██║   ██║██╔══██║██║╚██╔╝██║██╔══╝  ",
                @"  ╚██████╔╝██║  ██║██║ ╚═╝ ██║███████╗",
                @"   ╚═════╝ ╚═╝  ╚═╝╚═╝     ╚═╝╚══════╝",
                @"                                      ",
                @"   ██████╗ ██╗   ██╗███████╗██████╗   ",
                @"  ██╔═══██╗██║   ██║██╔════╝██╔══██╗  ",
                @"  ██║   ██║██║   ██║█████╗  ██████╔╝  ",
                @"  ██║   ██║╚██╗ ██╔╝██╔══╝  ██╔══██╗  ",
                @"  ╚██████╔╝ ╚████╔╝ ███████╗██║  ██║  ",
                @"   ╚═════╝   ╚═══╝  ╚══════╝╚═╝  ╚═╝  "
            };

            //snake player = new snake(); // make a player <- our snake
            menu Main  = new menu(prop, options1, 31);                 // get ready main menu
            menu End   = new menu(prop, options2, 31);                 // menu after game over
            menu Pause = new menu("Choose what to do:", options3, 31); // pause menu

            // setup the game and map


            // main game loop
            while (game)
            {
                Console.SetWindowSize(100, 50);
                Console.CursorVisible = false;
                score = 0;
                snake player = new snake();
                Console.Clear();
                MapBoarders();
                ShowTop(score);
                ShowBaner(snakeBaner, banerY);
                index = Main.MakeMenu();
                if (index == 0)
                {
                    play = true;
                }
                else if (index == 1)
                {
                    game = false;
                }
                Console.Clear();
                player.MakeSnack();
                player.MakeDrug();
                MapBoarders();

                while (play)
                {
                    Console.SetWindowSize(100, 50);
                    Console.CursorVisible   = false;
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    ShowTop(score);

                    play = player.DrawGame();
                    if (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo press = Console.ReadKey();
                        switch (press.Key)
                        {
                        case (ConsoleKey.UpArrow):
                            if (player.directon != "DOWN")
                            {
                                player.directon = "UP";
                            }
                            break;

                        case (ConsoleKey.DownArrow):
                            if (player.directon != "UP")
                            {
                                player.directon = "DOWN";
                            }
                            break;

                        case (ConsoleKey.LeftArrow):
                            if (player.directon != "RIGHT")
                            {
                                player.directon = "LEFT";
                            }
                            break;

                        case (ConsoleKey.RightArrow):
                            if (player.directon != "LEFT")
                            {
                                player.directon = "RIGHT";
                            }
                            break;

                        case (ConsoleKey.Escape):
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            index = Pause.MakeMenu();
                            if (index == 0)
                            {
                                Console.Clear();
                                MapBoarders();
                                break;
                            }
                            else if (index == 1)
                            {
                                play = false;
                            }
                            break;
                        }
                    }
                    if (player.EatFood() == 1)
                    {
                        player.MakeSnack();
                        score += 5;
                        Console.Beep(800, 10);
                    }
                    if (player.EatFood() == 2)
                    {
                        player.MakeDrug();
                        score += 10;
                        Console.Beep(500, 10);
                    }
                }
                if (game)
                {
                    MapBoarders();
                    ShowBaner(gameover, banerY);
                    index = End.MakeMenu();
                    if (index == 0)
                    {
                    }
                    else if (index == 1)
                    {
                        game = false;
                    }
                }
            }
        }