Beispiel #1
0
        static void Main(string[] args)
        {
            //Point FirstPoint = new Point(10, 5, '*');
            //FirstPoint.drawPoint();
            //Console.ReadLine();

            Console.SetBufferSize(80, 25);
            //HorizontalLine upLine = new HorizontalLine(0, 78, 0, '+');
            //HorizontalLine downLine = new HorizontalLine(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();

            Walls walls = new Walls(80, 25);

            walls.Draw();

            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            snake.Draw();

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

            food.DrawPoint();


            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.DrawPoint();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);

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

            //Console.ReadLine();
        }
Beispiel #2
0
 public void DrawNewFood()
 {
     X    = random.Next(2, gameFieldWidth);
     Y    = random.Next(2, gameFieldHeigth);
     food = new Point(X, Y, '$');
     food.DrawPoint();
 }
Beispiel #3
0
        internal void Move()
        {
            Point tailPoint = pointsList.First();

            pointsList.Remove(tailPoint);
            Point headPoint = GetNextPoint();

            pointsList.Add(headPoint);
            tailPoint.RemovePoint();
            headPoint.DrawPoint();
        }
Beispiel #4
0
        internal void Move()
        {
            Point tail = pList.First();

            pList.Remove(tail);
            Point head = GetNextPoint();

            pList.Add(head);

            tail.Clear();
            head.DrawPoint();
        }
Beispiel #5
0
        internal void MoveHero()
        {
            Point tailPoint = pointList.First(); // return first list element

            pointList.Remove(tailPoint);         // delete last point it snake
            Point headPoint = GetNextPoint();

            pointList.Add(headPoint);

            tailPoint.ClearPoint();
            headPoint.DrawPoint();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;      // Welcome to the Matrix

            Console.SetBufferSize(120, 30);                    // Set console window size

            Point point = new Point(4, 5, '@');                // Start snake position and default snake symbol
            Hero  snake = new Hero(point, 4, Direction.RIGHT); // point = start dir. position and snake symbol, 4 = default snake lenght, default direction

            snake.DrawFigure();

            FoodCreator foodCreator = new FoodCreator(100, 25, '#'); // Max range of food spawn and default food symbol
            Point       foodPoint   = foodCreator.CreateFood();

            foodPoint.DrawPoint();

            Walls walls = new Walls(120, 25); // Max x and y position of walls

            walls.DrawWalls();

            while (true)
            {
                if (snake.Eat(foodPoint))
                {
                    foodPoint = foodCreator.CreateFood();
                    foodPoint.DrawPoint();
                }
                else
                {
                    snake.MoveHero();
                }
                Thread.Sleep(300);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.ChangeDirectionKey(key.Key);
                }
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(80, 25);
            HorizontalLine upLine    = new HorizontalLine(0, 78, 0, '+');
            HorizontalLine downLine  = new HorizontalLine(0, 78, 24, '+');
            VerticalLine   leftLine  = new VerticalLine(0, 0, 24, '+');
            VerticalLine   rightLine = new VerticalLine(78, 0, 24, '+');

            upLine.DrawLine();
            downLine.DrawLine();
            leftLine.DrawLine();
            rightLine.DrawLine();
            Point p1 = new Point(3, 3, '*');

            p1.DrawPoint();


            Console.ReadLine();
        }
Beispiel #8
0
        internal void Move()
        {
            Point tail = pList.First();

            pList.Remove(tail);
            Point head = GetNextPoint();

            pList.Add(head);

            tail.ClearPoint();
            head.DrawPoint();

            if (direction == Direction.Up || direction == Direction.Down)
            {
                Thread.Sleep(speedVertical);
            }
            else
            {
                Thread.Sleep(speedHorizontal);
            }
        }
Beispiel #9
0
        public void StartGame()
        {
            Score score = new Score();

            score.PrintScore();
            Walls walls = new Walls(81, 25);

            walls.Draw();

            //Initializing Snake
            Point tail  = new Point(4, 5, '*');
            Snake snake = new Snake(tail, 3, Direction.Right);

            snake.Draw();
            snake.PrintSpeed();

            FoodGenerator foodGenerator = new FoodGenerator(78, 23, '#');
            Point         food          = foodGenerator.CreateFood(snake);

            food.DrawPoint();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    if (Score.score > Score.maxScore)
                    {
                        Score.maxScore = Score.score;
                    }
                    score.PrintGameOver();
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.SetCursorPosition(39, 16);
                    while (true)
                    {
                        if (Console.KeyAvailable)
                        {
                            ConsoleKeyInfo key = Console.ReadKey();
                            if (key.Key == ConsoleKey.Y)
                            {
                                Console.Clear();
                                Score.score = 0;
                                StartGame();
                            }
                            else if (key.Key == ConsoleKey.N)
                            {
                                Environment.Exit(0);
                            }
                            else
                            {
                                Console.Write("");
                            }
                        }
                    }
                }

                if (snake.Eat(food))
                {
                    food = foodGenerator.CreateFood(snake);
                    food.DrawPoint();
                    score.PrintScore();
                    snake.PrintSpeed();
                }
                else
                {
                    snake.Move();
                }

                //Thread.Sleep(100);

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.KeyHandler(key.Key);
                }
            }
        }