问题描述
我正在尝试开发一个简单的逻辑棋盘游戏.这是一款人机与电脑游戏.我无法从计算机端移动对象.每次移动后,必须更新对象的位置.我创建了一种更新对象第一步的方法.从我侧移动之后,计算机侧重复相同的移动.有什么方法可以使用继承,递归或辅助方法来解决此问题?提前致谢.任何帮助将不胜感激.
添加了提问者:
我有一种用于人的方法,一种用于计算机的方法.轮到人类玩耍后,就调用了计算机方法.我知道如何第一次移动计算机,但是此后,当我以人类的身份轮到我时,计算机也会重复相同的移动.
I am trying to develop a simple logic board game. It is a human vs computer game. I am having trouble moving the object from computer side. After each move the position of the object has to be updated. I created a method for updating the first move of the object. After I made move from my side, the same move repeats for computer side. Is there any way to solve this problem using inheritance, recursion or helper method? Thanks in advance. Any help will be greatly appreciated.
Questioner added:
I have one method for human and one for computer. After human play his turn, computer method is called. I know how to move the computer for the first time but after that the same move repeats for computer after I play my turn as a human.
推荐答案
private void moveStone(int iSteps /*moreArgmuents*/){
// doMove();
}
这些参数应在每次调用函数时重新设置.没有成员变量可以在其中调用(至少不是计算/移动负责任的变量).
those arguments should be set newly every time the function is called. No member variables to be called in there (at least non of the calculation/move responsible ones).
这篇关于如何更新图形对象的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!