我正在创建tictactoe游戏,我想创建一个循环(下面)。玩家可以是人或计算机。现在我想让代码等待,直到方法player.move()
内的语句将解锁。如何实现?
while(!finished){
Player player = fetchNextPlayer();
player.move();//MOVE suppose to encourage human player to click on a certain JButton
LOCK;//until there is a line in move() saying to unlock.
}
交易是在Player
的情况下move()应该只是鼓励玩家点击按钮,如果fetchNextPlayer()
返回ComputerPlayer extends Player
的实例,它会自动点击某个按钮。如果没有锁定,ComputerPlayer
将不会等到人类玩家点击按钮。