Click here to Skip to main content
11,575,921 members (57,618 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java
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 18:42pm
Edited 15-Oct-12 19:13pm
TorstenH.34.7K
v2
Comments
Sergey Alexandrovich Kryukov at 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 Luharuka at 14-Oct-12 7:54am
   
+5 to Sergey!

1 solution

Rate this: bad
good
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[^]

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:

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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 330
1 F-ES Sitecore 145
2 OriginalGriff 125
3 Dave Kreskowiak 120
4 Abhinav S 98
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 600
2 Abhinav S 438
3 F-ES Sitecore 410
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 16 Oct 2012
Copyright © CodeProject, 1999-2015
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