Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using SnakeOOP2b.Controller;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SnakeOOP2b
- {
- class Snake
- {
- public Queue<Point> body = new Queue<Point>();
- public Snake(int snakeLenght)
- {
- for (int i = 0; i < snakeLenght; i++)
- {
- body.Enqueue(new Point(i,0));
- }
- }
- public void Move(Direction direction)
- {
- Point newHead = CreateNewHead(direction);
- body.Enqueue(newHead);
- body.Dequeue();
- }
- public void Eat(Direction direction)
- {
- Point newHead = CreateNewHead(direction);
- body.Enqueue(newHead);
- }
- private Point CreateNewHead(Direction direction)
- {
- Point newHead = new Point(0,0), head = body.Last();
- switch (direction)
- {
- case Direction.Right:
- if (head.x == Console.WindowWidth - 1) newHead = new Point(0, head.y);
- else newHead = new Point(head.x + 1, head.y);
- break;
- case Direction.Left:
- if (head.x == 0) newHead = new Point(Console.WindowWidth - 1, head.y);
- else newHead = new Point(head.x - 1, head.y);
- break;
- case Direction.Up:
- if (head.y == 0) newHead = new Point(head.x, Console.WindowHeight - 1);
- else newHead = new Point(head.x, head.y - 1);
- break;
- case Direction.Down:
- if (head.y == Console.WindowHeight - 1) newHead = new Point(head.x, 0);
- else newHead = new Point(head.x, head.y + 1);
- break;
- }
- return newHead;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement