Пример #1
0
 public static void Func()
 {
     while (k == 0)
     {
         if ((food.loc.x == snake.body[0].x && food.loc.y == snake.body[0].y))
         {
             wall.Level(wall, snake);
             if (snake.body.Count > 1)
             {
                 snake.body.Add(new Point(snake.body[snake.body.Count - 1].x, snake.body[snake.body.Count - 1].y));
             }
             else
             {
                 snake.body.Add(new Point(5, 5));
             }
             food.SetRandomPosition(wall, snake);
             food.Draw();
         }
         if (direction == 1)
         {
             snake.Move(0, 1);
         }
         if (direction == 2)
         {
             snake.Move(0, -1);
         }
         if (direction == 3)
         {
             snake.Move(1, 0);
         }
         if (direction == 4)
         {
             snake.Move(-1, 0);
         }
         if (snake.CollisionWithWall(snake, wall))
         {
             snake.Save(name, snake.body.Count);
             k = 1;
         }
         food.Draw();
         snake.Draw();
         wall.ReadLevel();
         wall.Draw();
         Thread.Sleep(100);
     }
 }
Пример #2
0
        public static void MoveSnakeThread()
        {
            while (true)
            {
                Snake.draw();
                Food.draw();
                //  food1.draw1();
                Wall.draw();


                wall.Level();
                food.Process(wall);
                z++;
                z %= 60;
                if (z == 59 && bigfoodexists == false)
                {
                    BigFood.draw();
                    bigfoodexists = true;
                }



                switch (direction)
                {
                case 1:
                    snake.Move(0, -1);

                    break;

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

                    break;

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

                    break;

                case 4:
                    snake.Move(-1, 0);

                    break;
                }



                wall.Scoremenu();
                if (Snake.body[0].x < 0)
                {
                    Snake.body[0].x = 60;
                }
                if (Snake.body[0].x > 60)
                {
                    Snake.body[0].x = 0;
                }
                if (Snake.body[0].y < 0)
                {
                    Snake.body[0].y = 30;
                }
                if (Snake.body[0].y > 30)
                {
                    Snake.body[0].y = 0;
                }
                Console.SetCursorPosition(0, 33);
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine("Your Score: " + score);


                if (snake.Eat())
                {
                    score += 1;
                    Console.SetCursorPosition(0, 33);
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine("Your Score: " + score);
                }
                if (snake.Eat1())
                {
                    score += 3;
                    Console.SetCursorPosition(0, 33);
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine("Your Score: " + score);
                    bigfoodexists = false;
                }
                if (score > 7)
                {
                    Console.Clear();
                    snake.NewLevel();
                    Wall.level++;
                    if (Wall.level > 2)
                    {
                        Wall.level = 1;
                        score      = 0;
                    }
                }



                if (bigfood.IsontheSnake() == false || bigfood.Isonthewall() == false)
                {
                    bigfood.setrandompos();
                }
                if (snake.D1() == false || snake.D2() == false)
                {
                    realgameover = true;
                    gameover     = true;
                    Gameover();
                }
                if (food.Isonthefood() == false)
                {
                    food.setrandompos();
                }
                if (bigfood.Isonthefood() == false)
                {
                    bigfood.setrandompos();
                }

                Thread.Sleep(speed);
            }
        }