-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLock.java
More file actions
115 lines (103 loc) · 3.49 KB
/
Lock.java
File metadata and controls
115 lines (103 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import java.util.ArrayList;
import javax.swing.*;
import java.awt.*;
// COMBO = 10, 35, 30
public class Lock {
/**
* Lock class of Slide Into Highschool, creates the lock game for the maze stage of the game
*
* <h2>Course Info:</h2>
* ICS4UP with Krasteva, V.
* Date: June 4st, 2023
* Time Spent: 2 hrs
* @version 1
* @author Charlie To, Milena Mofrad
*/
JFrame frame;
public static int degrees = 0;
public static ArrayList<String> turns = new ArrayList<String>();
public static int curNum;
/**
* checkWinner method, checks for a win
*
* @return boolean Whether the game is won or not
*/
public static boolean checkWinner(){
String[] winCombo = { "up", "up", "up", "up", "up", "up", "up", "down", "down", "down", "down", "down", "down", "down", "down", "down","down","down"};
if (curNum == 30 && turns.size() > 18+1){
for (int x = turns.size()-1, i = 0; i < winCombo.length ;x--, i ++){
if (turns.get(x) == winCombo[i]){
continue;
}
else{
// System.out.println("no win");
return false;
}
}
// System.out.println("win");
return true;
}
return false;
}
/**
* Constructor method
*
* @param frame Takes JGrasp frame
*/
public Lock(JFrame frame) {
this.frame = frame;
// Clear the frame
Container contentPane = frame.getContentPane();
contentPane.removeAll();
this.frame.revalidate();
this.frame.repaint();
MainMenu.setIsLock(true);
}
public void run() {
frame.getContentPane().add(new Drawing());
curNum = (degrees/45)*5;
// System.out.println(curNum);
frame.setVisible(true);
}
class Drawing extends JComponent {
public void paint(Graphics g) {
super.paintComponent(g);
// BACKGROUND
g.setColor(Colours.darkerBlue);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Colours.backgroundBlue);
g.fillRect(20, 20, getWidth()-40, getHeight()-40);
g.setColor(Color.WHITE);
// INSTRUCTION TEXT
g.setFont(Colours.title);
g.drawString("Unlock the Lock", 250, 65);
g.setFont(new Font("Roboto", Font.BOLD, 25));
// g.drawString("Use 'S' and 'W' to rotate lock", 10, 100);
g.drawString("COMBO: 10, 35, 30", 280, 430);
// LOCK
g.setColor(Color.BLACK);
g.fillOval(240, 80, 320, 320);
g.setColor(Color.GRAY);
g.fillOval(250, 90, 300, 300);
g.setColor(Color.WHITE);
g.fillOval(365, 200, 70, 70);
// NUMBERS
g.setColor(Color.WHITE);
g.setFont(new Font("Roboto", Font.PLAIN, 30));
g.drawString("0", 395, 130);
g.drawString("5", 480, 170);
g.drawString("10", 505, 250);
g.drawString("15", 470, 340);
g.drawString("20", 385, 375);
g.drawString("25", 295, 340);
g.drawString("30", 260, 250);
g.drawString("35", 290, 170);
// ROTATING THING
Graphics2D g2d = (Graphics2D) g;
Rectangle rect2 = new Rectangle(385, 140, 30, 90);
g2d.rotate(Math.toRadians(degrees),385+15, 140+100);
g2d.draw(rect2);
g2d.fill(rect2);
}
}
}