Results 1 to 5 of 5

Thread: Java logic.

  1. Default Java logic.


    Im supposed to create a game with 32 buttons. It consists of a start game button, roll the dice button, 2 'counters' and and 32 buttons that create a 'game board'.

    Im utterly confused about the logic im supposed to use to make the 'counter' move across the 'board'/buttons.

    (viii) When the Roll the dice button is clicked, it should perform the following actions:
    • Simulate the rolling of a dice and place the counter in the correct square. If the position of the counter exceeds Square 32, it will go backwards. E.g. if the counter is on Square 31 and the dice number is 4, it will go backwards and land on Square 29.
    • Update the message in the text area to display the game status.
    • When the counter lands exactly on Square 32, a message will be displayed to show the completion of the game:


    GUI


    can somebody help explain what im supposed to do, step-by-step ?? just dont write the code for me. i do need help on what i need to declare though.

  2. Default Re: Java logic.


    So use Java's Random class. (Generate an integer % 6) + 1

    Run an update loop for this. It's the simplest option (though not the most mathematically astute).

    Code:
    while diceroll > 0
       if position == 32
         position -= diceroll
         diceroll = 0
       else
         position++
         diceroll--
    
    if position == 32
      show congratulations
      reset game state
    To make it appear as though the player is moving across the board, make the buttons in the depressed state to show the current position.

    EDIT: Oh, you need to show the graphics on top of the boxes. Just draw on top of them. >_>

    These seem self-explanatory. All you're doing is updating text. Just put in the text area of the screen what position the player is at, what the dice roll was, and maybe how many turns have been played thus far.

    For the counter landing on square 32, just show a modal popup that says "CONGRATULATIONS YOU WON" and show the stats for the game again. When the user clicks on "OK", reset the game state so the user can play again.
    Last edited by Fiel; 2012-08-02 at 08:06 AM.

  3. Default Re: Java logic.


    im still figuring out how to get the diceroll to add on to the 'current position' ;-; ;-; ;-;

    ok i got that part figured out.

    anyway, im at here, being all dumb about how to continue :

    Code:
            if(e.getSource()==roll){
                diceroll = game.Dice();
                position += diceroll;
                
                String update = "You rolled : "+diceroll + "\n";
                String positionupdate = "Your position: "+ (position) + "\n\n";
                
                textArea.append(update+positionupdate);
                
    
                
    
                }
    also where do I put the above loop ? and im having trouble making the icon appear on the buttons as well.... there goes my assignment marks :(
    Last edited by DeanNim; 2012-08-03 at 06:29 AM.

  4. Mercury Male
    IGN: Knight52
    Server: Earth
    Level: 534
    Job: Thread Breaker
    Guild: I'm bored of
    Alliance: political sh'it
    thailand

    Default Re: Java logic.


    I think you should put it right between update and positionupdate. I think loop could also be like this.

    Also, delete position += diceroll line; position will be added within the loop.

    Code:
    boolean reach = false;
    while(diceroll > 0)
       if(position == 32)
          reach = true;
       if(reach)
          position--;
       else
          position++;
       diceroll--;
    That's the case you may need to animate the movement, but if you don't just use this

    Code:
    position += diceroll;
    if(position > 32)
        position = 64 - position;
    Last edited by Unauthorized Intruder; 2012-08-03 at 12:10 PM. Reason: misreading

  5. Default Re: Java logic.


    that works

  6.  

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
  •