Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(80, 25);
            Console.SetBufferSize(80, 25);

            HorizontailLine upLine    = new HorizontailLine(0, 78, 0, '+');
            HorizontailLine downLine  = new HorizontailLine(0, 78, 24, '+');
            verticalLine    leftLine  = new verticalLine(0, 24, 0, '+');
            verticalLine    rightLine = new verticalLine(0, 24, 78, '+');

            upLine.draw();
            downLine.draw();
            leftLine.draw();
            rightLine.draw();

            point p     = new point(7, 5, '*');
            snake snake = new snake(p, 4, direction.rigth);

            snake.draw();

            foodCreator foodCreator = new foodCreator(80, 25, '$');
            point       food        = foodCreator.CreateFood();

            food.draw();



            while (true)
            {
                if (snake.eat(food))
                {
                    //food = foodCreator.CreateFood();
                    food = foodCreator.CreateFood();
                    food.draw();
                }
                else
                {
                    //    snake.move();

                    Thread.Sleep(100);
                }

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
                Thread.Sleep(100);
                snake.move();
            }


            //Console.ReadLine();
        }
Esempio n. 2
0
 static void Main(string[] args)
 {
     Console.SetWindowSize(sizex, sizey);
     Console.SetCursorPosition(1, 1);
     dragon = new snake(1, 1);
     for(int i = 0; i < 5; ++i)
     {
         int x = () % sizex, y = getrand() % sizey;
         Food.add(x, y);
     }
     for(int i = 0; i < 20; ++i)
     {
         int x = getrand() % sizex, y = getrand() % sizey;
         if (x == 1 && y == 1) continue;
         Wall.add(x, y);
     }
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            HorizontalLines upLine = new HorizontalLines(0, 78, 0, '+');
            HorizontalLines downLine = new HorizontalLines(0, 78, 24, '+');
            VerticalLines leftLine = new VerticalLines(0, 24, 78, '+');
            VerticalLines rightLine = new VerticalLines(0, 24, 78, '+');
            upLine.Drow();
            downLine.Drow();
            leftLine.Drow();
            rightLine.Drow();
            Point p = new Point(4, 5, '*');
            snake snake = new snake(p, 4, Direction.Right);
            snake.Drow();
            snake.Move();
            Thread.Sleep(300);

            Console.ReadLine();
        }
Esempio n. 4
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     if (!snake.alive)
     {
         timer1.Enabled = false;
         MessageBox.Show("DEAD SNAKE!! Score :" + snake.getScore());
         snake          = new snake();
         food           = new food();
         timer1.Enabled = true;
     }
     else
     {
         if (snake.ate)
         {
             snake.ate = false;
             food      = new food();
         }
         snake.move();
         snake.eat(food.pos);
         Refresh();
     }
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Console.CursorVisible = false;
            Console.SetWindowSize(103, 30);
            snake Snake = new snake();
            Food  Food  = new Food();
            wall  Wall  = new wall();

            int level = 1;

            while (true)
            {
                Snake.Draw();
                Food.Draw();
                Wall.Draw();
                Console.SetCursorPosition(0, 1);
                Console.WriteLine("Score :");
                Console.WriteLine(Snake.a);


                ConsoleKeyInfo btn = Console.ReadKey();
                switch (btn.Key)
                {
                case ConsoleKey.UpArrow:
                    Snake.Move(0, -1);
                    break;

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

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

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


                if (Snake.body[0].x < 14)
                {
                    Snake.body[0].x = 96;
                }
                if (Snake.body[0].x > 96)
                {
                    Snake.body[0].x = 14;
                }
                if (Snake.body[0].y < 7)
                {
                    Snake.body[0].y = 21;
                }
                if (Snake.body[0].y > 21)
                {
                    Snake.body[0].y = 7;
                }

                if (Snake.GameOver(Wall))
                {
                    Snake.a = 0;

                    Console.Clear();

                    Snake.body = new List <Point>();
                    Snake.body.Add(new Point(16, 7));
                    Snake.body.Add(new Point(15, 7));
                    Snake.body.Add(new Point(14, 7));
                }

                if (Snake.CanEat(Food))
                {
                    Food.setRandomPosition();
                }
            }
        }
Esempio n. 6
0
 public Form1()
 {
     InitializeComponent();
     snake = new snake();
     food  = new food();
 }