Results 1 to 2 of 2
  1. #1
    NBAPwns is offline Member
    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Question If Statements and how to switch to Player 1 to Player 2 repeat

    Hey, im new to java and im wondering on how i can make it so that i can go to Player 1 rolling the dice then Player 2 Rolling the dice and then player 1 and so on. What im facing right now is that it's going to player 1 rolling twice or more and then switching to player 2 vise versa i just want them to take turns rolling the dice

    if (randomNumber % 2 != 0)

    {

    c.setCursor (5, 200);
    c.println ("Player 1: Odd Number");
    c.println ("You Rolled " + randomNumber);
    c.println ("Please press any character to continue ");
    BlueBall = c.getChar ();
    c.clear ();
    squares ();
    BlueRedBall ();


    }

    if (randomNumber % 2 == 0)

    {


    c.setCursor (5, 200);
    c.println ("Player 2: Even Number");
    c.println ("You Rolled " + randomNumber);
    c.println ("Please press any character to continue ");
    RedBall = c.getChar ();
    c.clear ();
    squares ();
    BlueRedBall ();

    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,589
    Rep Power
    23

    Default Re: If Statements and how to switch to Player 1 to Player 2 repeat

    How is the value in randomNumber set and changed? That controls which block of code is executed.

    BTW if the condition is binary (true or false) you don't need two if statements with one condition the NOT of the other. Normally you use an else clause for that case.


    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    Last edited by Norm; 12-18-2013 at 03:25 AM.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Player Movement Help!
    By Mitch in forum Java Gaming
    Replies: 1
    Last Post: 04-13-2012, 05:51 AM
  2. Help with Mp3 player
    By Crathes in forum New To Java
    Replies: 36
    Last Post: 05-15-2011, 11:50 PM
  3. JMF player.setSource
    By lambi in forum Advanced Java
    Replies: 2
    Last Post: 02-22-2010, 01:09 PM
  4. mp3 player applet
    By willemjav in forum Java Applets
    Replies: 0
    Last Post: 05-20-2008, 01:16 AM

Posting Permissions

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