This repository has been archived by the owner on Jun 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainMenuView.java
102 lines (88 loc) · 2.68 KB
/
MainMenuView.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
import java.awt.Graphics;
import java.awt.image.BufferedImage;
/**
* This is the very first view the user will see.
* It should have cool pictures and sounds!
*/
public class MainMenuView extends Menu {
private static final long serialVersionUID = -9178274830210260069L;
private Clickable newGame;
private Clickable resumeEnable;
private Clickable resumeDisable;
private Clickable instructions;
private Clickable about;
private Clickable exit;
public MainMenuView() throws Exception {
super(BasicWars.GAME_NAME);
BufferedImage i = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics g = i.getGraphics();
Cell c = new Cell(40, 70, Cell.Type.EARTH);
c.paintCell(g);
for (int j=0; j<4; j++) {
c = c.generateNorthEast(Cell.Type.WATER);
c.paintCell(g);
c = c.generateSouthEast(Cell.Type.EARTH);
c.paintCell(g);
c = c.generateSouth(Cell.Type.SWAMP);
c.paintCell(g);
}
c = c.generateNorthEast(Cell.Type.EARTH);
c.paintCell(g);
newGame = new Clickable("New Game", true, i, null) {
@Override
public void onClick(BasicWars o) {
o.startNewGame();
}
};
resumeEnable = new Clickable("Resume Game") {
@Override
public void onClick(BasicWars o) {
o.resumeGame();
}
};
resumeDisable = new Clickable("Resume Game", false, null, null) {
@Override
public void onClick(BasicWars o) {
o.resumeGame();
}
};
instructions = new Clickable("Instructions", true, null, null) {
@Override
public void onClick(BasicWars o) {
o.loadInstructions();
}
};
i = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_3BYTE_BGR);
g = i.getGraphics();
g.setColor(BasicWars.TEXT_COLOR);
g.setFont(BasicWars.BOLD_FONT);
g.drawString("Hello", 85, 120);
about = new Clickable("About", true, i, null) {
@Override
public void onClick(BasicWars o) {
o.loadAbout();
}
};
i = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_3BYTE_BGR);
g = i.getGraphics();
g.setColor(BasicWars.HEAD_COLOR);
g.setFont(BasicWars.BOLD_FONT);
g.drawString("Goodbye", 65, 120);
exit = new Clickable("Exit", true, i , BasicWars.HEAD_COLOR) {
@Override
public void onClick(BasicWars o) {
System.exit(0);
}
};
setResumable(false); // build main menu with resume disabled
}
public void setResumable(boolean isResumable) {
clickables.clear();
Clickable resume = (isResumable) ? resumeEnable : resumeDisable;
clickables.add(newGame);
clickables.add(resume);
clickables.add(instructions);
clickables.add(about);
clickables.add(exit);
}
}