Advanced Search

Results 1 to 3 of 3

Thread: Java and the ACM Graphics Package Help

  1. #1
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java and the ACM Graphics Package Help

    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:
    Code:
    	
    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();
    	    pile.create(numSticks);
    		
    }
    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!

  2. #2
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

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

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •