-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
148 lines (95 loc) · 2.64 KB
/
Main.java
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 processing.core.*;
public class Main extends PApplet {
// global variables
PImage moleImg;
Game moleGame;
Player player;
int count =0;
static Moles [] moleArray = new Moles[9];
public static void main(String[] args) {
PApplet.main("Main");
}
public void settings() {
size(500,550);
}
public void setup() {
// load the image
moleImg = loadImage("download-1.png");
// create the nine moles for the game board
createMoles();
moleGame = new Game();
player = new Player();
// green background
background(0,0,0);
//title
fill(255);
textSize(19);
text("Welcome to WHACK-A-MOLE Game", 90, 150);
text("Start", 210,300);
frameRate(1);
}
public void draw() {
// the board
displayBoard();
// random mole
int randomMole = (int)(Math.random()*9);
popUp(randomMole);
// checking if the game ended
if (moleGame.gameEnd() == true) {
noLoop();
}
}
// showing the 9 holes
public void displayBoard() {
background(0,290,0);
// displaying the nine brown holes
for (int y = 50; y<=350; y+=150)
{
for (int x = 150; x<=350; x += 100)
{
fill (150,75,0);
ellipse(x,y,50,50);
}
}
// displaying the players score as they play
int score = player.getScore();
fill(0);
textSize(30);
text("Scores: "+ score, 180, 450);
// display the time left in the 30 second game
fill(0);
textSize(30);
text("Timer: "+ (29 - moleGame.getTime()),180, 480);
}
// displaying the image of a mole at a random mole location
public void popUp(int i ) {
// location of the random mole
int moleX = moleArray[i].getMolesX();
int moleY = moleArray[i].getMolesY();
// displaying the mole image
image(moleImg, moleX , moleY , moleImg.width/11, moleImg.height/11);
// player gets one point if they clicked on the location of the mole image
if (mousePressed && dist(pmouseX, pmouseY, moleArray[i].getMolesX(), moleArray[i].getMolesY() ) <= 450) {
player.setScore(1);
}
}
public void mousePressed() {
}
// creating the nine moles for the game each with locations from the 9 mole holes
public void createMoles() {
int y,x;
int count = 0;
for (int i = 0; i< 3; i++){
for (int j = 0; j < 3; j++)
{
y = (j*150) + 25;
x = (i*100) + 125;
// instantiating each mole object
Moles moleObj = new Moles( x, y);
// adding each mole object to the mole array
moleArray [ count ] = moleObj;
count+=1;
}
}
}
}