Home > Back-end >  For years, some directions little girl!!!! Image is the use of random Numbers, and Numbers and pictu
For years, some directions little girl!!!! Image is the use of random Numbers, and Numbers and pictu

Time:09-19

Now want to do a small game, mora (, there are three button interface, point the first button, random draw two pictures, and according to the rules in the interface to the winning party scores increase 1, after the three innings before will score compared to the results,


Click on the round 1, produce two images, according to the rules, the winners scores increase or tie,

Problems now is that I don't know how to click on the round 1 generating images, and according to the rules of the comparison, fraction increased?? Click in round 2 to regenerate the pictures,,,,
I don't know how to put the following together??

The following is a block of code rule
If (j.i ndex==1 & amp; & W.i ndex==1) {
JOptionPane. ShowMessageDialog (null, "the bureau draw");
}
If (j.i ndex==1 & amp; & W.i ndex==2) {
J.s. core++;
JOptionPane. ShowMessageDialog (null, "this machine brother win");
}
If (j.i ndex==1 & amp; & W.i ndex==3) {
Baron core++;
JOptionPane. ShowMessageDialog (null, "the bureau Wei Xiong win");
}
If (j.i ndex==2 & amp; & W.i ndex==1) {
Baron core++;
JOptionPane. ShowMessageDialog (null, "the bureau Wei Xiong win");
}
If (j.i ndex==2 & amp; & W.i ndex==2) {
JOptionPane. ShowMessageDialog (null, "the bureau draw");
}
If (j.i ndex==2 & amp; & W.i ndex==3) {
J.s. core++;
JOptionPane. ShowMessageDialog (null, "this machine brother win");
}
If (j.i ndex==3 & amp; & W.i ndex==1) {
J.s. core++;
JOptionPane. ShowMessageDialog (null, "this machine brother win");
}
If (j.i ndex==3 & amp; & W.i ndex==2) {
Baron core++;
JOptionPane. ShowMessageDialog (null, "the bureau Wei Xiong win");
}
If (j.i ndex==3 & amp; & W.i ndex==3) {
JOptionPane. ShowMessageDialog (null, "the bureau draw");
}


The event monitor code
@ Override
Public void actionPerformed (an ActionEvent e) {
//TODO Auto - generated method stub
If (um participant etSource ()==play01) {

Judge ();

}


If (um participant etSource ()==play02) {

Judge ();

}

If (um participant etSource ()==play03) {
Judge ();
}


}


Drawing
@ Override
Public void paint (Graphics g) {
//TODO Auto - generated method stub
Super. Paint (g);
G.s etColor (Color BLACK);
G.s etFont (new Font (" regular script ", the Font, BOLD, 30));


G.d rawImage (j.i mg, j.x, j.y, j., j.h, null);
G.d rawImage (w.x w.i mg, w.y, w.w, w.h, null);
G.d rawString (" brother machine score: "+ j.s core, 250, 300);
G.d rawString (" Wei Xiong score: "+ baron core, 850, 300);
}

CodePudding user response:

Img first of all, you should be associated with the index, so should be an array or a hashmap
Should look like this when you take pictures j.i mg [j.i ndex - 1] w.i mg [w.i ndex - 1]

Then you judge () method begins to j.i ndex and w.i ndex fu random value
Similar to this:
The Random ran=new Random ();
J.i ndex=ran. NextInt (3) + 1;
W.i ndex=ran. NextInt (3) + 1;

Finally, the judge () method is the last call repaint (); The method, redrawn panel

CodePudding user response:

I and your ideas about the same, but, I don't know what happened, I always have a question, may I ask you, I send you my code

CodePudding user response:

reference 1st floor sunyiz response:
first of all, your img should be related to the index, so should be an array or a hashmap
Should look like this when you take pictures j.i mg [j.i ndex - 1] w.i mg [w.i ndex - 1]

Then you judge () method begins to j.i ndex and w.i ndex fu random value
Similar to this:
The Random ran=new Random ();
J.i ndex=ran. NextInt (3) + 1;
W.i ndex=ran. NextInt (3) + 1;

Finally, the judge () method is the last call repaint (); Methods, redrawn panel

I and your ideas about the same, but, I don't know what happened, I always have a question, may I ask you, I send you my code

CodePudding user response:

refer to the original poster Wu Xi ah response:
now want to do a small game, mora (, there are three button interface, point the first button, random draw two pictures, and according to the rules in the interface to the winning party scores increase 1, after the three innings before will score compared to the results,


Can give button to add a flag bit, never press is true, according to lead to false,
Monitor trigger judgment sign bit is true, perform two random number 1-3, flag to false, get photo to judge the outcome calculated points, then redraw, repaint, key monitor is additional a judgment sign bit is false, it is concluded that the final score, reset the sign bit

CodePudding user response:

reference 4 floor qq_39936465 response:
Quote: refer to the original poster Wu Xi ah response:

Now want to do a small game, mora (, there are three button interface, point the first button, random draw two pictures, and according to the rules in the interface to the winning party scores increase 1, after the three innings before will score compared to the results,


Can give button to add a flag bit, never press is true, according to lead to false,
Monitor trigger judgment sign bit is true, perform two random number 1-3, flag to false, get photo to judge the outcome calculated points, then redraw, repaint, key monitor is additional a judgment sign bit is false, it is concluded that the final score, reset the flag bit

I'm ready?? Said, but you just can change my game, my button can press repeatedly, according to a can also according to ha ha ha, but I although code can perform, but there are still wrong

CodePudding user response:

reference 4 floor qq_39936465 response:
Quote: refer to the original poster Wu Xi ah response:

Now want to do a small game, mora (, there are three button interface, point the first button, random draw two pictures, and according to the rules in the interface to the winning party scores increase 1, after the three innings before will score compared to the results,


Can give button to add a flag bit, never press is true, according to lead to false,
Monitor trigger judgment sign bit is true, perform two random number 1-3, flag to false, get photo to judge the outcome calculated points, then redraw, repaint, key monitor is additional a judgment sign bit is false, it is concluded that the final score, reset the flag bit

You said this problem, I'm using the index a piece to do, use the score++, according to the rules to compare three times, then judge a total score

CodePudding user response:

o f Wu Xi reference response:
you said the problem, I are done with the index a, use the score++, according to the rules to compare three times, then judge a total score


And index variables not conflict, I said your picture Numbers and the index values should be consistent, random number directly assigned to the index variable,
Button can only do a, original name is round1, add a counter to the initial value is 1, according to the counter plus 1 and update button after a name, name according to the count value, when the count=3 buttons initialization,nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related