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

            Figure H1 = new HorizontalLine(0, 79, 0, '+');

            H1.Draw();
            Figure H2 = new HorizontalLine(0, 79, 23, '+');

            H2.Draw();
            Figure V1 = new VerticalLine(0, 0, 23, '+');

            V1.Draw();
            Figure V2 = new VerticalLine(79, 0, 23, '+');

            V2.Draw();


            WallsCreator W1 = new WallsCreator(2, 10, Direction.LEFT, 79, 23);

            W1.Draw();
            WallsCreator W2 = new WallsCreator(2, 10, Direction.DOWN, 79, 23);

            W2.Draw();



            Point p1 = new Point(4, 8, '#');
            Snake s1 = new Snake(p1, 7, Direction.RIGHT);

            s1.Draw();
            FoodCreator foodCr = new FoodCreator(79, 23, '@');
            Point       food   = foodCr.Create();

            food.Print(ConsoleColor.Red);

            while (true)
            {
                if (s1.eat(food))
                {
                    food = foodCr.Create();
                    food.Print(ConsoleColor.Red);
                }
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    s1.HandControl(key);
                }

                s1.Move();
                Thread.Sleep(150);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            int Score = 0;

            Console.SetWindowSize(102, 28);
            Console.SetBufferSize(102, 28);
            Walls walls = new Walls(102, 27);

            walls.Draw();
            GameMenu    GameParams  = new GameMenu();
            Point       p           = new Point(4, 5, '*');
            Snake       snake       = new Snake(p, 5, Direction.RIGHT);
            FoodCreator foodCreator = new FoodCreator(100, 25, '$');
            Point       food        = foodCreator.CreateFood();
            Point       food2       = foodCreator.CreateFood();

            snake.Draw();
            food.Draw();
            while (true)
            {
                GameParams.WriteMenu();
                GameParams.Score(Score);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.GetDirection(key.Key);
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    while (snake.CheckPositionFood(food))
                    {
                        food = foodCreator.CreateFood();
                    }
                    food.Draw();
                    Score++;
                    GameParams.Score(Score);
                }
                snake.Draw();

                if (snake.IsHitTail() || walls.HitinWall(snake))
                {
                    GameParams.WriteGameisOver(Score);
                    break;
                }
                else
                {
                    Thread.Sleep(100);
                }
                snake.Move();
            }
            Console.ReadLine();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 27);                                  //Bufer size

            Walls       wall        = new Walls(80, 25);                    //Create all Wals
            Point       point       = new Point(4, 5, '*');                 //Create point
            Snake       snake       = new Snake(point, 2, Direction.right); //Create first state of snake
            FoodCreator foodCreator = new FoodCreator(80, 25, '$');         //Function for generate state of food
            Point       food        = foodCreator.CreateFood();             //Create state of food

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



            while (true)
            {
                if (wall.IsHit(snake) || snake.IsHitTail()) //Protect to crash with wall or tail
                {
                    break;                                  //Out from circle
                }

                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                    snake.speed = snake.speed * 2;
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100 / snake.speed + 90);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandlKey(key.Key);
                }// End first if

                // Thread.Sleep(100);
                //snake.Move();
            }//End while



            Console.ReadKey();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 27);                         //Bufer size

            Walls wall = new Walls(80,25);                         //Create all Wals
            Point point = new Point(4, 5, '*');                    //Create point
            Snake snake = new Snake(point, 2, Direction.right);    //Create first state of snake
            FoodCreator foodCreator = new FoodCreator(80, 25, '$');//Function for generate state of food
            Point food = foodCreator.CreateFood();                 //Create state of food

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

            while (true)
            {
                if (wall.IsHit(snake) || snake.IsHitTail()) //Protect to crash with wall or tail
                {
                    break;       //Out from circle
                }

                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                    snake.speed = snake.speed * 2;
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100/snake.speed + 90);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandlKey(key.Key);
                }// End first if

               // Thread.Sleep(100);
                //snake.Move();

            }//End while

            Console.ReadKey();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(90, 50);

            Wolls wools = new Wolls(90, 50);
            wools.Draw();

            FoodCreator footerCreator = new FoodCreator(50, 90, '$');
            Point foot = footerCreator.CreateFood();
            foot.Draw();

            Thread.Sleep(100);

            Point p = new Point(4, 5, '*');
            Snape sp = new Snape(p, 2, Direction.UP);
            sp.Draw();
            
            while(true)
            {
                if ((wools.isHit(sp))||(sp.isHitTail()))
                {
                    break;
                }
                if (sp.Eat(foot))
                {
                    foot = footerCreator.CreateFood();
                    foot.Draw();
                }
                else sp.Move();

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