-
Notifications
You must be signed in to change notification settings - Fork 4
/
Player.java
85 lines (72 loc) · 1.81 KB
/
Player.java
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package othello.Othello;
import java.io.*;
import java.util.ArrayList;
/**
* Created by pmunoz on 01/04/14. Updated by aeap and jgeorge on 14/05/14.
*/
public class Player {
private String name; // name of the player
private int color; // color of the chips
private Board board; // board
/**
* Class constructor. Creates a player.
*
* @param String
* name - the player's name
* @param int color - the color of the chips
* @param Board
* board - the board used
*/
public Player(String name, int color, Board board) {
this.name = name;
this.color = color;
this.board = board;
}
/**
* Prompts the user for their name and sets it as the name variable.
*
* Null values throws a message
*/
public void setNames() throws IOException {
BufferedReader line = new BufferedReader(new InputStreamReader(
System.in));
System.out.println("tell me your name: ");
this.name = line.readLine();
}
/**
* Gets the name of the player.
*
* @return name of the player
*/
public String getName() {
return this.name;
}
/**
* Gets the number of the player.
*
* @return the number of the player
*/
public int getColor() {
return this.color;
}
/**
* Places a chip for a chosen player at the chosen location. Replaces the
* chips in between the player's chips to the player's color.
*
* @param int row - the row of the chip
* @param int col - the column of the chip
*/
public void placeChip(int row, int col) {
this.board.placeChip(this.color, row, col);
Move move = new Move(row, col);
this.board.replaceChip(move, this.color);
}
/**
* Find the valid moves and allow them to be selected.
*/
public void findCanSelect() {
ArrayList<Move> moves = board.validMove(this.color);
for (Move move : moves)
board.setCanSelect(move);
}
}