diff --git a/Rock_paper.java b/Screen.java similarity index 68% rename from Rock_paper.java rename to Screen.java index ca4c007..7bbd808 100644 --- a/Rock_paper.java +++ b/Screen.java @@ -1,16 +1,16 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; +import javax.swing.JLabel; import javax.swing.JPanel; -public class Rock_paper { +public class Screen { static boolean rock = false; static boolean scissors = false; static boolean paper = false; - boolean airock = false; - boolean aiscissors = false; - boolean aipaper = false; + public static void main(String[] args) { JFrame frame = new JFrame("rock paper scissors"); @@ -21,16 +21,38 @@ public class Rock_paper { JButton paperbutton = new JButton("paper"); JButton scissorsbutton = new JButton("scissors"); JPanel panel = new JPanel(); + JLabel Label = new JLabel("play"); + + panel.add(rockbutton); panel.add(paperbutton); 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(){ public void actionPerformed(ActionEvent e){ rock = true; if(rock == true) { scissors = false; paper = false; + Thecomputer.generate(args); 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.setVisible(true); } diff --git a/Thecomputer.java b/Thecomputer.java new file mode 100644 index 0000000..e777f39 --- /dev/null +++ b/Thecomputer.java @@ -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"); + } + } + + } +}