Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
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.
Posted
Updated 15-Oct-12 19:13pm
v2
Comments
Sergey Alexandrovich Kryukov 14-Oct-12 2:14am    
Not enough information. We don't know what do you try so far. Some minimal code sample could help greatly -- use "Improve question" above.
--SA
Nitesh Kejriwal 14-Oct-12 7:54am    
+5 to Sergey!

1 solution

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[^]

EDIT:
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:

Java
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).
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900