-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyWorld.java
75 lines (62 loc) · 2.23 KB
/
MyWorld.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @authors (Teodor Grigor & Scott Turner)
* @version (v1.0)
*/
public class MyWorld extends World
{
//declaring a new variable of counter type so we can pass it to other classes and to draw it
Counter counter = new Counter();
//declaring a variable for the goal event
GoalEvent goalEvent = new GoalEvent();
//declaring the baby speed of move and the ball speed
int babyMoveSpeed = 2, ballSpeed = 6;
//public method that helps us to access the same counter from other classes (actors)
public Counter getCounter()
{
return counter;
}
//public method that helps the babies to move
public int getBabySpeed() {
return babyMoveSpeed;
}
//public method that helps the ball to move
public int getBallSpeed() {
return ballSpeed;
}
//method that pass the team that scored to the goal event class
//method that reset the timer
public void goalScored(int team)
{
goalEvent.resetTimer(50, team);
}
//public method to initialise the class - MyWorld()
public MyWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
//this chunck of code should not be changes and MUST be included
//in your solution
super(600, 400, 1);
//creating the line (barrier) from the middle of the screen
for (int loop=0; loop<20; loop++)
{
addObject(new barrier(), 300, 20*loop);
}
//adding the counter to the screen
addObject(counter, 300, 25);
//adding the goal event
addObject(goalEvent, 300, 60);
//adding the babies
//adding team A (Baby 1 and Baby 3)
addObject(new baby1(), 150, 100);
addObject(new baby3(), 150, 300);
//adding team B (Baby 2 and Baby 4)
addObject(new baby2(), 450, 100);
addObject(new baby4(), 450, 300);
//adding the ball to the screen
addObject(new ball1(), 450, 100);
//End of code that must be included in your solution
}
}