Object Oriented Design of a Small Java Game
- by user2733436
This is the problem i am dealing with. I have to make a simple game of NIM. I am learning java using a book so far i have only coded programs that deal with 2 classes. This program would have about 4 classes i guess including the main class. My problem is i am having a difficult time designing classes how they will interact with each other. I really want to think and use a object oriented approach. So the first thing i did was design the Pile CLASS as it seemed the easiest and made the most sense to me in terms of what methods go in it.
Here is what i have got down for the Pile Class so far.
package Nim;
import java.util.Random;
public class Pile {
private int initialSize;
public Pile(){
}
Random rand = new Random();
public void setPile(){
initialSize = (rand.nextInt(100-10)+10);
}
public void reducePile(int x){
initialSize = initialSize - x;
}
public int getPile(){
return initialSize;
}
public boolean hasStick(){
if(initialSize>0){
return true;
}
else
{
return false;
}
}
}
Now i need help in designing the Player Class. By that i mean i am not asking for anyone to write code for me as that defeats the purpose of learning i was just wondering how would i design the player class and what would go on it. My guess is that the player class would contain method for choosing move for computer and also receiving the move human user makes. Lastly i am guessing in the Game class i am guessing the turns would be handeled. I am really lost right now so i was wondering if someone can help me think through this problem it would be great. Starting with the player class would be appreciated.
I know there are some solutions for this problem online but i refuse to look at because i want to develop my own approach to such problems and i am confident if i can get through this problem i can solve other problems.
I apologize if this question is a bit poor but in specific i need help in designing the Player class.