-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cs
58 lines (52 loc) · 2.11 KB
/
Player.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
namespace MySnake {
class Player {
public Snake snake;
public bool gameOver = false;
PlayerControls playerControls;
public int score = 0;
Position scorePosition;
public string playerName;
public Player(string playerName, PlayerControls playerControls, Position scorePosition, Position startPosition) {
this.playerName = playerName;
this.playerControls = playerControls;
this.scorePosition = scorePosition;
this.snake = new Snake(startPosition);
}
public Player(string playerName, PlayerControls playerControls, Position scorePosition, Position startPosition, char snakeTailChar, char snakeHeadChar) {
this.playerName = playerName;
this.playerControls = playerControls;
this.scorePosition = scorePosition;
this.snake = new Snake(snakeTailChar, snakeHeadChar, startPosition);
writeScore();
}
public void writeScore() {
Console.SetCursorPosition(this.scorePosition.x, this.scorePosition.y);
Console.Write(playerName + ": " + score);
}
public void processUserInput(ConsoleKey userInput) {
if(userInput == this.playerControls.moveDown) {
snake.changeMovement(Movement.DOWN);
}
else if(userInput == this.playerControls.moveUp) {
snake.changeMovement(Movement.UP);
}
else if(userInput == this.playerControls.moveLeft) {
snake.changeMovement(Movement.LEFT);
}
else if(userInput == this.playerControls.moveRight) {
snake.changeMovement(Movement.RIGHT);
}
else if(userInput == this.playerControls.pause) {
//TODO pause function
}
}
public bool checkSnakeError(LinkedList<Position> allSnakePositions) {
if(this.snake.checkNextPositionError(allSnakePositions)) {
return false;
}
return true;
}
}
}