-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMachine.java
More file actions
33 lines (30 loc) · 867 Bytes
/
Machine.java
File metadata and controls
33 lines (30 loc) · 867 Bytes
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
import java.util.Random;
/**
* Логика игрока - компьютер | player logic - computer
* @author Timur Muratov
* 06/04/2016
*/
public class Machine extends Gamer {
Random random = new Random();
public Machine(Game game) {
super(game);
}
@Override
public void step() {
System.out.println("Ход компьютера | comp step (id: " + id + ")");
boolean success = false;
while (!success) {
int position = random.nextInt(9) + 1;
if (position == 0) {
game.gameOver = true;
game.looser = id;
return;
}
success = game.convas.setPosition(position, id);
}
}
@Override
public String who() {
return "Компьютер | Computer";
}
}