示例#1
0
文件: Player.cs 项目: krix38/snake
 public void Move()
 {
     ConsoleWrapper.ConsoleWriteCharXY(BODY_CHAR, headX, headY);
     bodyCoords.Add(new Tuple <int, int>(headX, headY));
     moveSnake();
     checkWallCollision(headX, headY);
     checkSelfCollision(headX, headY);
     isMooving = false;
 }
示例#2
0
        public void spawnFood()
        {
            Random random = new Random();
            var    foodX  = random.Next(1, Console.WindowWidth - 1);
            var    foodY  = random.Next(1, Console.WindowHeight - 2);

            foodList.Add(new Tuple <int, int>(foodX, foodY));
            ConsoleWrapper.ConsoleWriteCharXY(FOOD_CHARACTER, foodX, foodY);
        }
示例#3
0
文件: Player.cs 项目: krix38/snake
        public void InitialDrawSnakeHorizontal()
        {
            var currentX = headX;
            var currentY = headY;

            ConsoleWrapper.ConsoleWriteCharXY(HEAD_CHAR, headX, headY);
            for (int i = 0; i < this.Length; i++)
            {
                ConsoleWrapper.ConsoleWriteCharXY(BODY_CHAR, --currentX, currentY);
                bodyCoords.Add(new Tuple <int, int>(currentX, currentY));
            }
            tailX = currentX;
            tailY = currentY;
            Console.SetCursorPosition(0, Console.WindowHeight - 1);
        }
示例#4
0
文件: Player.cs 项目: krix38/snake
        private void moveTail()
        {
            ConsoleWrapper.ConsoleWriteCharXY(' ', tailX, tailY);
            removeBodyCoords(tailX, tailY);
            switch (tailQueue.Dequeue())
            {
            case RIGHT:
                tailX++;
                break;

            case LEFT:
                tailX--;
                break;

            case UP:
                tailY--;
                break;

            case DOWN:
                tailY++;
                break;
            }
        }
示例#5
0
文件: Player.cs 项目: krix38/snake
 private void moveDown()
 {
     ConsoleWrapper.ConsoleWriteCharXY(HEAD_CHAR, headX, ++headY);
     tailQueue.Enqueue(DOWN);
 }
示例#6
0
文件: Player.cs 项目: krix38/snake
 private void moveUp()
 {
     ConsoleWrapper.ConsoleWriteCharXY(HEAD_CHAR, headX, --headY);
     tailQueue.Enqueue(UP);
 }
示例#7
0
文件: Player.cs 项目: krix38/snake
 private void moveLeft()
 {
     ConsoleWrapper.ConsoleWriteCharXY(HEAD_CHAR, --headX, headY);
     tailQueue.Enqueue(LEFT);
 }
示例#8
0
文件: Player.cs 项目: krix38/snake
 private void moveRight()
 {
     ConsoleWrapper.ConsoleWriteCharXY(HEAD_CHAR, ++headX, headY);
     tailQueue.Enqueue(RIGHT);
 }