Compare commits
No commits in common. "master" and "0.1" have entirely different histories.
116
Screen.java
116
Screen.java
@ -1,99 +1,115 @@
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import javax.swing.*;
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
public class Screen {
|
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;
|
||||||
static int score = 0; // Makes the variable and boolean
|
static int score = 0; //makes the variable and boolean
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); // Set OS theme
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
JFrame frame = new JFrame("Rock Paper Scissors");
|
JFrame frame = new JFrame("rock paper scissors");
|
||||||
frame.setSize(300,200);
|
frame.setSize(300,200);
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //makes the window and also makes it so when the window is closed the java stops
|
||||||
|
|
||||||
JButton rockbutton = new JButton("Rock");
|
JButton rockbutton = new JButton("rock");
|
||||||
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");
|
JLabel Label = new JLabel("play"); //makes the buttons, text, and panel
|
||||||
|
|
||||||
panel.add(rockbutton);
|
panel.add(rockbutton);
|
||||||
panel.add(paperbutton);
|
panel.add(paperbutton);
|
||||||
panel.add(scissorsbutton);
|
panel.add(scissorsbutton);
|
||||||
panel.add(label);
|
panel.add(Label);
|
||||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // adds everthing to the window and buts it in a form from top to bottom
|
||||||
|
|
||||||
rockbutton.setAlignmentX(JButton.CENTER_ALIGNMENT);
|
rockbutton.setAlignmentX(JButton.CENTER_ALIGNMENT);
|
||||||
paperbutton.setAlignmentX(JButton.CENTER_ALIGNMENT);
|
paperbutton.setAlignmentX(JButton.CENTER_ALIGNMENT);
|
||||||
scissorsbutton.setAlignmentX(JButton.CENTER_ALIGNMENT);
|
scissorsbutton.setAlignmentX(JButton.CENTER_ALIGNMENT);
|
||||||
label.setAlignmentX(JLabel.CENTER_ALIGNMENT);
|
Label.setAlignmentX(JLabel.CENTER_ALIGNMENT); //sets everyting in the window to the center
|
||||||
|
|
||||||
rockbutton.addActionListener(new ActionListener() {
|
|
||||||
|
rockbutton.addActionListener(new ActionListener(){ //sees if you click the button and makes the corresponding boolean true
|
||||||
public void actionPerformed(ActionEvent e){
|
public void actionPerformed(ActionEvent e){
|
||||||
rock = true;
|
rock = true;
|
||||||
|
if(rock == true) { //checks if the button is true and if it is then it forces the others to be false and you play your turn
|
||||||
scissors = false;
|
scissors = false;
|
||||||
paper = false;
|
paper = false;
|
||||||
Thecomputer.generate(args);
|
Thecomputer.generate(args);
|
||||||
System.out.println("Rock is true");
|
System.out.println("rock is true");
|
||||||
if (Thecomputer.aipaper) {
|
if(Thecomputer.aipaper == true){
|
||||||
score -= 1;
|
score += -1;
|
||||||
label.setText("Paper, you lose, score " + score);
|
Label.setText("paper, you lose, score " + score);
|
||||||
} else if (Thecomputer.airock) {
|
};
|
||||||
label.setText("Rock, tie, score " + score);
|
if(Thecomputer.airock == true){
|
||||||
} else if (Thecomputer.aiscissors) {
|
|
||||||
score += 1;
|
score += 1;
|
||||||
label.setText("Scissors, you win, score " + score);
|
Label.setText("rock, tie, score " + score);
|
||||||
}
|
};
|
||||||
|
if(Thecomputer.aiscissors == true){
|
||||||
|
Label.setText("scissors, you win, score " + score);//adds or removes 1 from the score
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
paperbutton.addActionListener(new ActionListener(){ //sees if you click the button and makes the corresponding boolean true
|
||||||
paperbutton.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e){
|
public void actionPerformed(ActionEvent e){
|
||||||
paper = true;
|
paper = true;
|
||||||
|
if(paper == true) { //checks if the button is true and if it is then it forces the others to be false and you play your turn
|
||||||
rock = false;
|
rock = false;
|
||||||
scissors = false;
|
scissors = false;
|
||||||
Thecomputer.generate(args);
|
Thecomputer.generate(args);
|
||||||
System.out.println("Paper is true");
|
System.out.println("paper is true");
|
||||||
if (Thecomputer.aipaper) {
|
if(Thecomputer.aipaper == true){
|
||||||
label.setText("Paper, tie, score " + score);
|
|
||||||
} else if (Thecomputer.airock) {
|
Label.setText("paper, you tie, score " + score);
|
||||||
|
};
|
||||||
|
if(Thecomputer.airock == true){
|
||||||
score += 1;
|
score += 1;
|
||||||
label.setText("Rock, you win, score " + score);
|
Label.setText("rock, you win, score " + score);
|
||||||
} else if (Thecomputer.aiscissors) {
|
};
|
||||||
score -= 1;
|
if(Thecomputer.aiscissors == true){
|
||||||
label.setText("Scissors, you lose, score " + score);
|
score += -1;
|
||||||
}
|
Label.setText("scissors, you lose, score " + score);//adds or removes 1 from the score
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
scissorsbutton.addActionListener(new ActionListener() {
|
scissorsbutton.addActionListener(new ActionListener(){ //sees if you click the button and makes the corresponding boolean true
|
||||||
public void actionPerformed(ActionEvent e){
|
public void actionPerformed(ActionEvent e){
|
||||||
scissors = true;
|
scissors = true;
|
||||||
|
if(scissors == true) { //checks if the button is true and if it is then it forces the others to be false and you play your turn
|
||||||
paper = false;
|
paper = false;
|
||||||
rock = false;
|
scissors = false;
|
||||||
Thecomputer.generate(args);
|
Thecomputer.generate(args);
|
||||||
System.out.println("Scissors is true");
|
System.out.println("Scirrors is true");
|
||||||
if (Thecomputer.aiscissors) {
|
if(Thecomputer.aiscissors == true){
|
||||||
label.setText("Scissors, tie, score " + score);
|
|
||||||
} else if (Thecomputer.airock) {
|
Label.setText("scissors, you tie, score " + score);
|
||||||
score -= 1;
|
};
|
||||||
label.setText("Rock, you lose, score " + score);
|
if(Thecomputer.airock == true){
|
||||||
} else if (Thecomputer.aipaper) {
|
score += -1;
|
||||||
|
Label.setText("rock, you lose, score " + score);
|
||||||
|
};
|
||||||
|
if(Thecomputer.aipaper == true){
|
||||||
score += 1;
|
score += 1;
|
||||||
label.setText("Paper, you win, score " + score);
|
Label.setText("paper, you win, score " + score); //adds or removes 1 from the score
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}});
|
||||||
});
|
|
||||||
|
|
||||||
frame.add(panel);
|
frame.add(panel);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);//make it so you can see window
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user