View Full Version : Java and the ACM Graphics Package Help

10-13-2007, 03:59 PM
I'm creating an applet that will open up the ACM package and play a game.

The game works like this:
-There are 2 players - One human and one computer player
-The human player declares how many sticks will be used in the pile
-The human player decides if they want to play against a computer with a greedy strategy, a timid strategy, or a perfect strategy.
-Each player goes back and forth removing sticks 1, 2, or 3 at a time until the last stick is removed
-When the last stick is removed that person is declared the loser.

So I have to have a Java Interface for player which greedyplayer, timidplayer, and cleverplayer will all use.

And I have an engine class which will basically run the entire game. Then I will have a class that keeps track of the pile. Right now this is how I have it setup:
The engine runs in main starting a scanner and that will ask how many sticks you would like to play with (in the console) and then it sends that information as a parameter to the pile class. The pile class will draw the canvas and the sticks with this information using the ACM graphics package. This is all I want to be able to do so far but I'm stuck. I think I could take it from here as I've written a couple different text based versions of this game.

My problem is that I can't seem to be able to do anything. Here is my main:

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in;
in = new Scanner(System.in);
System.out.print("Enter the number of sticks to play the game with: ");
int numSticks = in.nextInt();

NimEngine pile = new NimEngine();


But it never even asks for the number of sticks in the console, it simply draws the canvas and seems to basically stop doing anything else...

And I'm using Eclipse for Mac if that makes a difference, thanks so much!

10-13-2007, 04:10 PM
It would appear I wouldn't want a main class but rather a run() class, huh?

Weird, I really wish my professor had explained that to me...

10-13-2007, 05:00 PM
It would appear I wouldn't want a main class but rather a run() class, huh?You mean a method, and only if you're using an applet (unless it's something that ACM does, I'm not familiar with the package). Your design is a little out-of-shape, I must say; the Pile class sounds like it's on the verge of becoming a "god class," one with way too much stuffed into it to be readable or flexible. It's a mistake I still make with regularity, so I can speak with authority on the subject :) If I were you, I'd separate the user interface from the backend (this means the engine and the Pile class) and have said user interface inherit from an interface (Java interface) that provides a set of methods that the engine can call on when it needs to interface with the user.