-
Notifications
You must be signed in to change notification settings - Fork 0
/
HumanPlayer.java
60 lines (53 loc) · 1.37 KB
/
HumanPlayer.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
package com.example.kindle.winningfour.boardgame;
import java.awt.Color;
import java.awt.event.KeyEvent;
import com.amazon.kindle.kindlet.event.KindleKeyCodes;
import com.example.kindle.boardgame.IPiece;
import com.example.kindle.boardgame.IPosition2D;
import com.example.kindle.boardgame.Position2D;
import com.example.kindle.winningfour.App;
public class HumanPlayer extends Player
{
public HumanPlayer(final Color color)
{
super(color);
}
protected void onKeyboard(final KeyEvent event)
{
int key = event.getKeyCode();
App.log("HumanPlayer::onKeyboard" + event);
if (event.isActionKey())
{
if (key == KindleKeyCodes.VK_BACK)
{
event.consume();
}
else
{
switch (key)
{
case KindleKeyCodes.VK_FIVE_WAY_SELECT:
case KindleKeyCodes.VK_FIVE_WAY_DOWN:
case KindleKeyCodes.VK_FIVE_WAY_UP:
{
IPiece piece = new Piece(this);
IPosition2D pos = new Position2D(App.gamer.getSelectedRow(), 0);
App.gamer.makeTurn(new Turn(piece, pos));
break;
}
case KindleKeyCodes.VK_FIVE_WAY_LEFT:
App.gamer.selectPrev();
break;
case KindleKeyCodes.VK_FIVE_WAY_RIGHT:
App.gamer.selectNext();
break;
default:
key = 0;
break;
}
event.consume();
}
}
App.log("HumanPlayer::onKeyboard done");
}
}