如何更新图形对象的位置? [英] How to update the position of an graphic object?

查看:83
本文介绍了如何更新图形对象的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个简单的逻辑棋盘游戏.这是一款人机与​​电脑游戏.我无法从计算机端移动对象.每次移动后,必须更新对象的位置.我创建了一种更新对象第一步的方法.从我侧移动之后,计算机侧重复相同的移动.有什么方法可以使用继承,递归或辅助方法来解决此问题?提前致谢.任何帮助将不胜感激.

添加了提问者:
我有一种用于人的方法,一种用于计算机的方法.轮到人类玩耍后,就调用了计算机方法.我知道如何第一次移动计算机,但是此后,当我以人类的身份轮到我时,计算机也会重复相同的移动.

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.

推荐答案

是的,您可以使用与计算机移动相同的方法.

Java是面向对象的编程(OOP),因此您可以创建可以多次调用的函数.

Java教程-面向对象的编程概念 [
Yes, you can use the same methods you are using for your move for the computers move.

Java is Object Oriented Programming (OOP) and therefor you can create functions that can be called multiple times.

The Java Tutorial - Object-Oriented Programming Concepts[^]


OK, so you are already moving stones/figures/whatever.
The function that moves the "playing item" is probably using some member variable of the class. Let it use only given arguments:

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).


这篇关于如何更新图形对象的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆