Click here to Skip to main content
13,352,408 members (41,007 online)
Rate this:
Please Sign up or sign in to vote.
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 13-Oct-12 19:42pm
Updated 15-Oct-12 20:13pm
Not enough information. We don't know what do you try so far. Some minimal code sample could help greatly -- use "Improve question" above.
Nitesh Luharuka 14-Oct-12 7:54am
+5 to Sergey!

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180111.1 | Last Updated 16 Oct 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100