Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 deaparately need help with dialog boxes and graphics.
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic
Author Message
lord_dread




PostPosted: Sat Jan 29, 2011 10:15 pm   Post subject: deaparately need help with dialog boxes and graphics.

all i need, is for a quick animation to pop up at the beginning of my game. for those of you who are wondering this game is completely different from the last one i tried getting help with here.

this wouldn't be a problem, but the game heavily uses dialog boxes, and i can't figure out how to use both in the same program. i know it's possible, i've done it before. i just can't find the program i did it in. please keep it as bare bones basic as possible (as in, grade 11 computer science basic)and please reply as soon as possible.please ignore the comments, as they are from previous programs. the method that needs to be added to the main program is the intro method and, while i've deleted anything pertaining to it here in the main program, i tried everything i could think of and none of it worked properly. thankyou, and please hurry, this is somewhat urgent. even if you don't know, could you at least say that, just reply.


here's my code:
main class:
/*kyle patton
05/11/2010
create a quiz with multiple difficulty levels.*/
//allows us to make option boxes
import java.applet.*;
import java.awt.*;
import javax.swing.*;
// The "Q" class.

public class RPSExpert

{

public static void main (String[] args)
{ //declare images

//java.awt.Graphics g;
int repeat; //variable for choice of playing again
int pHealth;
int cHealth;
//call the suplamentary class
RPSExpertSup rps = new RPSExpertSup ();
//call methods to read instructions
rps.instructions ();
//begin the main game loop
do
{
rps.variableAssignment ();
do
{
//get their answer
rps.getInput ();
//ceck their answer
rps.comDecision ();

rps.result ();
pHealth = rps.getPHealth ();
cHealth = rps.getCHealth ();
}
while ((pHealth > 0) && (cHealth > 0));
if ((pHealth <= 0) && (cHealth <= 0))
{
JOptionPane.showMessageDialog (null, "whait, what?!the game is a tie!?", "well,this is awkward.", JOptionPane.PLAIN_MESSAGE);
}
else if (pHealth <= 0)
{
JOptionPane.showMessageDialog (null, " Ouch, you just lost the game! ", "victory and a meme, what could be better?", JOptionPane.PLAIN_MESSAGE);
}
else if (cHealth <= 0)
{
JOptionPane.showMessageDialog (null, "Congragulations! you win!", "You lagswitching hacker! I demand a rematch!", JOptionPane.PLAIN_MESSAGE);
}
//ask them if they would like to play again
repeat = JOptionPane.showConfirmDialog (null, "Would you like to play again? ", "I'm waiting...", 0, 1);
}
//check if they want to play again
while (repeat == 0);
System.exit (0); //ends program
} // main method
} // quiz class

suplementary class

/*kyle patton
27/01/2011
create a quiz with multiple difficulty levels.*/

import java.awt.*;
import javax.swing.*;

//create the suplementary class
public class RPSExpertSup
{
//declare variables
private String stringAnswer; //input retreived from window
private int pHealth; //ealth of player
private int cHealth; //
private int pRock;
private int pPaper;
private int pScissors;
private int cRock;
private int cPaper;
private int cScissors;
private int cChoice;
private int setup;
private int rx;
private int ry;
private int px;
private int py;
private int sx;
private int sy;
private int by;
//method to display instructions
public void instructions ()
{
//display their instructions
JOptionPane.showMessageDialog (null, "hello, and welcome to rps: expert mode.", "ROCK PAPER SCISSORS! WOOOOOOOOH!", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog (null, "the gameplay is the same as ordinary rock paper scissors:\n rock beats scissors\n scissors beat paper\n paper beats rock", "then what's so expert about it?", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog (null, "However, ther's a twist.", "OH SNAP!", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog (null, "a maximum of 4 rocks, 4 papers, and 4 scissors can be used during the game.", "but what if they always tie?", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog (null, "these are distributed at the beginning of the game\n so that each player has a random amount from the opening pool.", "seriously, what happens when they tie?", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog (null, "furthermore, each player starts with 6 health.", "Health? is this how to solve the tie problem?", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog (null, " losing a round costs you 2 health \n winning deals 2 damage to your apponent \n a tie causes both sides to lose one health.", "ok, now i get it, a maximum of 6 roundswith a possible double ko", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog (null, "each round you will be shown how many of each option you have left\n use this to plan on what has the most likely chance of winning.", "ah, so there's some strategy...", JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog (null, " now, let's get to the game! ", "GREAT! now that i know the rules, i shall be your opponent, Bwahahahahahahaaaaaa!", JOptionPane.PLAIN_MESSAGE);

}


//method for gaining input
public void getInput ()
{
//show statistics, ask what they would like to do
stringAnswer = JOptionPane.showInputDialog (null, "your health: " + pHealth + "\nopponent's health: " + cHealth + "\nrocks remaining: " + pRock + "\npaper remaining: " + pPaper + "\nscissors remaining: " + pScissors + "\nso, Rock, Paper, or Scissors?", "I'm waaiitiing", 3);
//convert their answer to upper case
stringAnswer = stringAnswer.toUpperCase ();
}



//method for setting variable values.
public void variableAssignment ()
{
pHealth = 6;
cHealth = 6;
setup = (int) (Math.random () * 39) + 1; //x position of grass
if ((setup >= 1) && (setup <= 5))
{
pRock = 3;
pPaper = 2;
pScissors = 1;
}
else if ((setup >= 6) && (setup <= 10))
{
pRock = 3;
pPaper = 1;
pScissors = 2;
}
else if ((setup >= 11) && (setup <= 15))
{
pRock = 1;
pPaper = 3;
pScissors = 2;
}
else if ((setup >= 16) && (setup <= 20))
{
pRock = 1;
pPaper = 2;
pScissors = 3;
}
else if ((setup >= 21) && (setup <= 25))
{
pRock = 2;
pPaper = 1;
pScissors = 3;
}
else if ((setup >= 25) && (setup <= 30))
{
pRock = 2;
pPaper = 3;
pScissors = 1;
}
else if ((setup >= 31) && (setup <= 35))
{
pRock = 2;
pPaper = 2;
pScissors = 2;
}
cRock = 4 - pRock;
cPaper = 4 - pPaper;
cScissors = 4 - pScissors;
} //lightQuestions


public void comDecision ()
{
if ((cRock > 0) && (cPaper > 0) && (cScissors > 0))
{
setup = (int) (Math.random () * 14) + 1; //x position of grass
if ((setup >= 1) && (setup <= 5))
{
cChoice = 1;
}
else if ((setup >= 6) && (setup <= 10))
{
cChoice = 2;
}
else if ((setup >= 11) && (setup <= 15))
{
cChoice = 3;
}
}
else if (!(cRock > 0) && (cPaper > 0) && (cScissors > 0))
{
setup = (int) (Math.random () * 9) + 1; //x position of grass
if ((setup >= 1) && (setup <= 5))
{
cChoice = 2;
}
else if ((setup >= 6) && (setup <= 10))
{
cChoice = 3;
}

}
else if ((cRock > 0) && !(cPaper > 0) && (cScissors > 0))
{
setup = (int) (Math.random () * 9) + 1; //x position of grass
if ((setup >= 1) && (setup <= 5))
{
cChoice = 1;
}
else if ((setup >= 6) && (setup <= 10))
{
cChoice = 3;
}

}
else if ((cRock > 0) && (cPaper > 0) && !(cScissors > 0))
{
setup = (int) (Math.random () * 9) + 1; //x position of grass
if ((setup >= 1) && (setup <= 5))
{
cChoice = 1;
}
else if ((setup >= 6) && (setup <= 10))
{
cChoice = 2;
}

}
else if (!(cRock > 0) && !(cPaper > 0) && (cScissors > 0))
{
cChoice = 3;
}
else if (!(cRock > 0) && (cPaper > 0) && !(cScissors > 0))
{
cChoice = 2;
}
else if ((cRock > 0) && !(cPaper > 0) && !(cScissors > 0))
{
cChoice = 1;
}
}


public void result ()
{
if ((stringAnswer.equals ("ROCK")) && (pRock > 0)) //correct
{
pRock = pRock - 1;
if (cChoice == 1)
{
tie ();
}
if (cChoice == 2)
{
lose ();
}
if (cChoice == 3)
{
win ();
}
}
else if ((stringAnswer.equals ("PAPER")) && (pPaper > 0)) //correct
{
pPaper = pPaper - 1;
if (cChoice == 2)
{
tie ();
}
if (cChoice == 3)
{
lose ();
}
if (cChoice == 1)
{
win ();
}
}
else if ((stringAnswer.equals ("SCISSORS")) && (pScissors > 0)) //correct
{
pScissors = pScissors - 1;
if (cChoice == 3)
{
tie ();
}
if (cChoice == 1)
{
lose ();
}
if (cChoice == 2)
{
win ();
}
}
else if ((stringAnswer.equals ("ROCK")) && !(pRock > 0)) //correct
{
failure ();
}
else if ((stringAnswer.equals ("PAPER")) && !(pPaper > 0)) //correct
{
failure ();
}
else if ((stringAnswer.equals ("SCISSORS")) && !(pScissors > 0)) //correct
{
failure ();
}
else
{
JOptionPane.showMessageDialog (null, "Sorry, i don't know that substance", "wow, way to throw in the towel", JOptionPane.PLAIN_MESSAGE);
pHealth = pHealth - 2;
}

}


public void win ()
{
JOptionPane.showMessageDialog (null, " You win! ", "wait whaaaaat?", JOptionPane.PLAIN_MESSAGE);
cHealth = cHealth - 2;
cUsage ();
}


public void lose ()
{
JOptionPane.showMessageDialog (null, " You lose! ", "soon, victory shall be mine", JOptionPane.PLAIN_MESSAGE);
pHealth = pHealth - 2;
cUsage ();
}


public void tie ()
{
JOptionPane.showMessageDialog (null, " It's a tie! ", "is it wacky tie day already?", JOptionPane.PLAIN_MESSAGE);
pHealth = pHealth - 1;
cHealth = cHealth - 1;
cUsage ();
}


public void failure ()
{
JOptionPane.showMessageDialog (null, "Your all out of that!", "yay! you used air! i win!", JOptionPane.PLAIN_MESSAGE);
pHealth = pHealth - 2;
}


public void cUsage ()
{
if (cChoice == 1)
{
cRock = cRock - 1;
}
if (cChoice == 2)
{
cPaper = cPaper - 1;
}
if (cChoice == 3)
{
cScissors = cScissors - 1;
}
}


public int getPHealth ()
{
//send score to main program
return pHealth;
}


public int getCHealth ()
{
//send score to main program
return cHealth;
}


public void intro (Graphics g)
{
rx = 160;
ry = -150;
px = 50;
py = 200;
sx = 375;
sy = 200;
//set the color
g.setColor (Color.black);
//code for drawing
g.fillRect (0, 0, 400, 400);
do
{
rock (g);
rx = rx + 1;
delay (10);
}
while (rx > 50);
delay (500);
do
{
paper (g);
g.setColor (Color.black);
g.fillRect (50, by, 75, 150);
by = by - 1;
delay (10);
}
while (by > 350);
scissors (g);
}


public void rock (Graphics g)
{
g.setColor (new Color (175, 175, 175));
g.fillOval (rx - 10, rx - 1, 80, 75);
g.setColor (Color.black);
g.fillOval (rx + 20, rx + 15, 30, 45);
g.setColor (new Color (175, 175, 175));
g.fillRect (rx, rx, 30, 150);
g.fillRect (rx, rx + 75, 50, 25);
g.fillRect (rx + 45, rx + 95, 15, 55);

}


public void paper (Graphics g)
{
g.setColor (new Color (255, 255, 255));
g.fillOval (px - 10, px - 1, 80, 75);
g.setColor (Color.black);
g.fillOval (px + 20, px + 15, 30, 45);
g.setColor (new Color (255, 255, 255));
g.fillRect (px, px, 30, 150);
}


public void scissors (Graphics g)
{
g.setColor (new Color (255, 255, 255));
g.drawLine (sx + 75, sy + 100, sx, sy + 150);
delay (50);
g.drawLine (sx + 75, sy + 100, sx, sy + 50);
delay (50);
g.drawLine (sx + 75, sy + 0, sx, sy + 50);
}


public static void delay (int ms) //create pause method
{
try
{
Thread.sleep (ms);
}
catch (Exception e)
{
;
}
} // delay
}

the method that needs to be added to the main program is the intro method and, while i've deleted anything pertaining to it here in the main program, i treid everything i could think of and none of it worked properly. thankyou, and please hurry, this is somewhat urgent.
 
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Jan 29, 2011 10:33 pm   Post subject: Re: deaparately need help with dialog boxes and graphics.

lord_dread @ Sat Jan 29, 2011 10:15 pm wrote:
all i need, is for a quick animation to pop up at the beginning of my game....

I would guess that the animation is independent from anything else, and should go before the "//begin the main game loop" part.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
 
lord_dread




PostPosted: Sun Jan 30, 2011 6:02 am   Post subject: RE:deaparately need help with dialog boxes and graphics.

yes, whenever i tried it, it was before utilising the instructions method and after calling the RPSExpertSup class. i'm going to try putting the animation in a separate class, then run the main game code from it.
 
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: