added another java file to generates the computers answer and made the rock button fully funcional ecpect the point system I haven't even started yet
This commit is contained in:
parent
794bfea6f6
commit
60c3e32f6c
@ -1,16 +1,16 @@
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
public class Rock_paper {
|
public class Screen {
|
||||||
static boolean rock = false;
|
static boolean rock = false;
|
||||||
static boolean scissors = false;
|
static boolean scissors = false;
|
||||||
static boolean paper = false;
|
static boolean paper = false;
|
||||||
boolean airock = false;
|
|
||||||
boolean aiscissors = false;
|
|
||||||
boolean aipaper = false;
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
JFrame frame = new JFrame("rock paper scissors");
|
JFrame frame = new JFrame("rock paper scissors");
|
||||||
@ -21,16 +21,38 @@ public class Rock_paper {
|
|||||||
JButton paperbutton = new JButton("paper");
|
JButton paperbutton = new JButton("paper");
|
||||||
JButton scissorsbutton = new JButton("scissors");
|
JButton scissorsbutton = new JButton("scissors");
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
|
JLabel Label = new JLabel("play");
|
||||||
|
|
||||||
|
|
||||||
panel.add(rockbutton);
|
panel.add(rockbutton);
|
||||||
panel.add(paperbutton);
|
panel.add(paperbutton);
|
||||||
panel.add(scissorsbutton);
|
panel.add(scissorsbutton);
|
||||||
|
panel.add(Label);
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
|
rockbutton.setAlignmentX(JButton.CENTER_ALIGNMENT);
|
||||||
|
paperbutton.setAlignmentX(JButton.CENTER_ALIGNMENT);
|
||||||
|
scissorsbutton.setAlignmentX(JButton.CENTER_ALIGNMENT);
|
||||||
|
Label.setAlignmentX(JLabel.CENTER_ALIGNMENT);
|
||||||
|
|
||||||
|
|
||||||
rockbutton.addActionListener(new ActionListener(){
|
rockbutton.addActionListener(new ActionListener(){
|
||||||
public void actionPerformed(ActionEvent e){
|
public void actionPerformed(ActionEvent e){
|
||||||
rock = true;
|
rock = true;
|
||||||
if(rock == true) {
|
if(rock == true) {
|
||||||
scissors = false;
|
scissors = false;
|
||||||
paper = false;
|
paper = false;
|
||||||
|
Thecomputer.generate(args);
|
||||||
System.out.println("rock is true");
|
System.out.println("rock is true");
|
||||||
|
if(Thecomputer.aipaper == true){
|
||||||
|
Label.setText("paper, you lose");
|
||||||
|
};
|
||||||
|
if(Thecomputer.airock == true){
|
||||||
|
Label.setText("rock, tie");
|
||||||
|
};
|
||||||
|
if(Thecomputer.aiscissors == true){
|
||||||
|
Label.setText("scissors, you win");
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -59,7 +81,6 @@ public class Rock_paper {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
frame.add(panel);
|
frame.add(panel);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
37
Thecomputer.java
Normal file
37
Thecomputer.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Thecomputer {
|
||||||
|
static boolean airock = false;
|
||||||
|
static boolean aipaper = false;
|
||||||
|
static boolean aiscissors = false;
|
||||||
|
public static void generate(String[] args) {
|
||||||
|
Random random = new Random();
|
||||||
|
int randomnumber = random.nextInt(3);
|
||||||
|
if(randomnumber == 1) {
|
||||||
|
aipaper = true;
|
||||||
|
if(aipaper = true) {
|
||||||
|
airock = false;
|
||||||
|
aiscissors = false;
|
||||||
|
System.out.println("aipaper is true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(randomnumber == 0) {
|
||||||
|
aiscissors = true;
|
||||||
|
if(aiscissors = true) {
|
||||||
|
airock = false;
|
||||||
|
aipaper = false;
|
||||||
|
System.out.println("aiscissors is true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(randomnumber == 2) {
|
||||||
|
airock = true;
|
||||||
|
if(airock = true) {
|
||||||
|
aiscissors = false;
|
||||||
|
aipaper = false;
|
||||||
|
System.out.println("airock is true");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user