-
Notifications
You must be signed in to change notification settings - Fork 6
/
Board.java
71 lines (59 loc) · 1.92 KB
/
Board.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Board here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Board extends Actor
{
// instance variables - replace the example below with your own
public Plant[][] Board = new Plant[5][9];
public static final int xOffset = 212;
public static final int yOffset = 95;
public static final int xSpacing = 58;
public static final int ySpacing = 72;
/**
* Constructor for objects of class Board
*/
public Board()
{
}
public void placePlant(int x, int y, Plant plant) {
if (Board[y][x] == null) {
Board[y][x] = plant;
World MyWorld = getWorld();
MyWorld.addObject(plant, x*xSpacing+xOffset, y*ySpacing+yOffset);
AudioPlayer.play(80, "plant.mp3", "plant2.mp3");
}
}
public Plant getPlant(int x, int y) {
return Board[y][x];
}
public void removePlant(int x, int y) {
if (Board[y][x] != null) {
getWorld().removeObject(Board[y][x]);
Board[y][x] = null;
}
//plant.mp3 is not used for shovel???
AudioPlayer.play(80,"plant2.mp3");
}
public void updateBoard() {
for (int i = 0; i < Board.length; i++) {
for (int k = 0; k < Board[0].length; k++) {
if (Board[i][k] != null) {
World MyWorld = getWorld();
Plant temp = Board[i][k];
MyWorld.addObject(temp, k*xSpacing+xOffset, i*ySpacing+yOffset);
}
}
}
}
/**
* Act - do whatever the Board wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
}
}