-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanPlayer.java
More file actions
49 lines (46 loc) · 1.13 KB
/
Copy pathHumanPlayer.java
File metadata and controls
49 lines (46 loc) · 1.13 KB
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
import java.util.*;
import java.awt.Color;
/**
* Represents a
* human player in a chess game
* who plays based on
* a user's clicks.
*
* @author Linda Zeng
* @version 4.9.23
*/
public class HumanPlayer extends Player
{
private BoardDisplay display; //display of game
/**
* Constructs a human player with given attributes.
*
* @param boardP board to play on
* @param nameP name of player
* @param colorP color to play
* @param displayP display of game player is in
*/
public HumanPlayer(Board boardP, String nameP, Color colorP, BoardDisplay displayP)
{
super(boardP, nameP, colorP);
display = displayP;
}
/**
* Returns next move the
* player will play
* (based on the move selected
* by the user currently)
*
* @return player's next move
*/
public Move nextMove()
{
Move move = display.selectMove();
ArrayList<Move> validMoves = getBoard().allMoves(getColor());
while (!validMoves.contains(move))
{
move = display.selectMove();
}
return move;
}
}