-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMinigame2.java
More file actions
64 lines (56 loc) · 1.62 KB
/
Minigame2.java
File metadata and controls
64 lines (56 loc) · 1.62 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
import java.awt.Graphics;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.lang.*;
public class Minigame2 {
private boolean arr[][];
private int score, timeLeft;
private SpriteSheet mopTiles;
public Minigame2(BufferedImage mt) {
mopTiles = new SpriteSheet(mt, 150, 150);
arr = new boolean [3][3];
reset();
}
public void reset(){
for(int c = 0; c < 3; c++){
for(int r = 0; r < 3; r++){
arr[r][c] = false;
}
}
timeLeft = 700;
score = 0;
}
public int getScore(){
return score;
}
public int getTime(){
return timeLeft;
}
public void clean(int row, int col){
arr[row][col] = false;
}
public void tick() {
for(int c = 0; c < 3; c++){
for(int r = 0; r < 3; r++){
if(arr[r][c] == false){
if((int)(Math.random()*300) == 1) arr[r][c] = true;
}
else{
score++;
}
}
}
timeLeft--;
if(Math.floor(timeLeft) <= 0) System.out.println(score);
}
public void render(Graphics g) {
for(int c = 0; c < 3; c++){
for(int r = 0; r < 3; r++){
BufferedImage temp = mopTiles.grabImage(r*3+c, (arr[r][c] == true ? 0 : 1), 150, 150);
g.drawImage(temp, 175 + 150*c, 40 + 150*r, null);
}
}
g.setColor(Color.RED);
g.fillRect(49, 10, (int)timeLeft, 20);
}
}