我正在开发一个tic tac toe游戏,并且想要实现撤消方法。我觉得做这件事的最好方法就是设置另一个(多个)堆栈,并复制刚刚发生的“移动”。然后,如果撤消被调用,只需弹出最后一步并重新填充游戏板。Java - 使用多个堆栈以允许“撤消”方法
所以是的,我有想法,但无法弄清楚如何实现它。
一些什么,我有:
设置:
public void set(Position p, int v, int n) throws IOException {
if (board[p.x][p.y][p.z]!= 0) throw new IOException("Position taken");
//Restrict 222 until all other's have been used
if (n != 26) {
if (p.x == 1 && p.y == 1 && p.z ==1) {
throw new IOException("[2,2,2] cannot be played until all other positions have been taken");
}
}
//Enforce x=1 for first 9, x=3 for next 9
if (n < 9) {
if (p.x != 0) throw new IOException("Please play on x=1 for the first 9 moves");
}
if (n >= 9 && n < 18) {
if (p.x != 2) throw new IOException("Please play on x=3 for the first 9 moves");
}
board[p.x][p.y][p.z] = v;
}
然后有一个板的方法,建立董事会,显示方法,当然一个的连续检查3 。
感谢您的任何意见
寻找GOF中的纪念品设计图案 – pastjean 2010-12-11 02:32:52