-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
75 lines (59 loc) · 1.31 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
package com.example.kindle.winningfour.boardgame;
import java.awt.Color;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import com.example.kindle.boardgame.IGameContext;
import com.example.kindle.boardgame.IPlayer;
import com.example.kindle.winningfour.App;
public class Player implements IPlayer
{
public Player(final Color color)
{
this.color = color;
this.keyAdapter = new KeyAdapter()
{
public void keyPressed(KeyEvent event)
{
Player.this.onKeyboard(event);
}
};
}
public Color getColor()
{
return this.color;
}
public KeyAdapter getKeyAdapter()
{
return this.keyAdapter;
}
protected void onKeyboard(final KeyEvent event)
{
}
public void interrupt() throws InterruptedException
{
}
public void think(final IGameContext context)
{
}
public boolean equals(Object other)
{
if (this == other) return true;
if (other == null) return false;
if (getClass() != other.getClass()) return false;
if (getClass() == IPlayer.class)
{
IPlayer lhs = (IPlayer) this;
IPlayer rhs = (IPlayer) other;
return rhs.getColor().equals(lhs.getColor());
}
return false;
}
public void destroy()
{
App.log("Player::destroy");
this.keyAdapter = null;
App.log("Player::destroy done");
}
private KeyAdapter keyAdapter;
private final Color color;
}