-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHallwayGame.java
More file actions
148 lines (139 loc) · 5.34 KB
/
HallwayGame.java
File metadata and controls
148 lines (139 loc) · 5.34 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import javax.swing.*;
import java.awt.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
public class HallwayGame {
/**
* HallwayGame class of Slide Into Highschool, Creates hallway game
*
* <h2>Course Info:</h2>
* ICS4UP with Krasteva, V.
* Date: June 4st, 2023
* Time Spent: 1 hrs
* @version 1
* @author Charlie To, Milena Mofrad
*/
JFrame frame;
public static ArrayList<String> items = new ArrayList<String>(4);
/**
* Constructor method
*
* @param frame Takes JGrasp frame
*/
public HallwayGame(JFrame frame) {
this.frame = frame;
Container contentPane = frame.getContentPane();
contentPane.removeAll();
this.frame.revalidate();
this.frame.repaint();
MainMenu.setIsHallwayGame(true);
}
/**
* checkWin method, checks if game is won
*
* @return boolean If game is won
*/
public static boolean checkWin() {
for (String i : items) {
if (i.equals("videoGame") || i.equals("dog") || i.equals("headphones")) {
return false;
}
}
return true;
}
/**
* runs the hallway game
*/
public void run() {
frame.getContentPane().add(new Drawing());
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);
g.setFont(Colours.title2);
g.drawString("Select 4 items you'll need for class", 120, 70);
g.setColor(Color.GRAY);
g.fillRect(180, 330, 440, 140);
// DRAW SELECTED ITEMS
int xPos = 180;
for (String i : items) {
try {
BufferedImage img = ImageIO.read(new File("images/items/" + i + ".png"));
Image newImage = img.getScaledInstance(110, 90, Image.SCALE_DEFAULT);
g.drawImage(newImage, xPos, 350, null);
xPos += 100;
} catch (Exception e) {
System.out.println("Error with image");
}
}
try {
BufferedImage img = ImageIO.read(new File("images/items/dog.png"));
Image newImage = img.getScaledInstance(110, 110, Image.SCALE_DEFAULT);
g.drawImage(newImage, 50, 100, null);
} catch (Exception e) {
System.out.println("Error with image");
}
try {
BufferedImage img = ImageIO.read(new File("images/items/notebook.png"));
Image newImage = img.getScaledInstance(140, 140, Image.SCALE_DEFAULT);
g.drawImage(newImage, 160, 80, null);
} catch (Exception e) {
System.out.println("Error with image");
}
try {
BufferedImage img = ImageIO.read(new File("images/items/headphones.png"));
Image newImage = img.getScaledInstance(140, 140, Image.SCALE_DEFAULT);
g.drawImage(newImage, 260, 85, null);
} catch (Exception e) {
System.out.println("Error with image");
}
try {
BufferedImage img = ImageIO.read(new File("images/items/textbooks.png"));
Image newImage = img.getScaledInstance(130, 130, Image.SCALE_DEFAULT);
g.drawImage(newImage, 380, 90, null);
} catch (Exception e) {
System.out.println("Error with image");
}
try {
BufferedImage img = ImageIO.read(new File("images/items/pencilCase.png"));
Image newImage = img.getScaledInstance(130, 130, Image.SCALE_DEFAULT);
g.drawImage(newImage, 520, 80, null);
} catch (Exception e) {
System.out.println("Error with image");
}
try {
BufferedImage img = ImageIO.read(new File("images/items/videoGame.png"));
Image newImage = img.getScaledInstance(130, 130, Image.SCALE_DEFAULT);
g.drawImage(newImage, 300, 200, null);
} catch (Exception e) {
System.out.println("Error with image");
}
try {
BufferedImage img = ImageIO.read(new File("images/items/water.png"));
Image newImage = img.getScaledInstance(110, 110, Image.SCALE_DEFAULT);
g.drawImage(newImage, 460, 200, null);
} catch (Exception e) {
System.out.println("Error with image");
}
if (!checkWin() && items.size() == 4){
g.setColor(Color.GRAY);
g.fillRect(180, 330, 440, 140);
g.setColor(Color.WHITE);
g.setFont(Colours.small);
g.drawString("Those are the incorrect items", 200, 370);
g.drawString("press any key to try again", 200, 400);
}
g.setColor(Colours.darkerBlue);
g.fillRect(0, getHeight()-20, getWidth(), 20);
}
}
}