-
Notifications
You must be signed in to change notification settings - Fork 3
/
MenuItem.java
154 lines (132 loc) · 3.9 KB
/
MenuItem.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
149
150
151
152
153
package com.danilchican.pacman;
import javafx.animation.FadeTransition;
import javafx.animation.ScaleTransition;
import javafx.geometry.Pos;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.util.Duration;
/**
* Contains info about item menu
*
* @author Vlad Danilchik
*
*/
public class MenuItem extends StackPane {
private Rectangle menuRect;
public static enum Options {
NEW_GAME, LEVELS, BOOT, BACK, QUIT, LEVEL_1, LEVEL_2, SAVES, PLAY_SAVED, SORTING, SORTING_LIST
}
/**
* MenuItem constructor
*
* @param name for menu item
* @param type of menu
* @see MenuItem#MenuItem(String, Options)
*/
public MenuItem(String name, Options type) {
menuRect = new Rectangle(300, 30);
menuRect.setFill(Color.WHITE);
menuRect.setOpacity(0.1);
Text text = new Text(name);
text.setFill(Color.ALICEBLUE);
text.setFont(Font.font(20));
setAlignment(Pos.TOP_CENTER);
getChildren().addAll(menuRect, text);
setOnMouseEntered(event -> {
ScaleTransition st = new ScaleTransition(Duration.millis(400), menuRect);
st.setByX(0.1f);
st.setByY(0.1f);
FadeTransition ft = new FadeTransition(Duration.millis(400), menuRect);
ft.setFromValue(0.1);
ft.setToValue(0.3);
ft.setAutoReverse(true);
ft.play();
st.play();
});
setOnMouseExited(event -> {
ScaleTransition st = new ScaleTransition(Duration.millis(400), menuRect);
st.setToX(1f);
st.setToY(1f);
FadeTransition ft = new FadeTransition(Duration.millis(400), menuRect);
ft.setToValue(0.1);
ft.setAutoReverse(true);
ft.play();
st.play();
});
setOnMousePressed(event -> {
text.setFill(Color.AZURE);
});
setOnMouseReleased(event -> {
text.setFill(Color.WHITE);
setActionMenu(type);
});
}
/**
* Set action on menu item
*
* @param type for setting action menu
* @see MenuItem#setActionMenu(Options)
*/
private void setActionMenu(Options type) {
switch (type) {
case QUIT:
System.exit(0);
break;
case NEW_GAME:
Constants.gamePlay = new GamePlay();
Constants.gamePlay.createThread(1);
Constants.save.openBufferForWrite();
Constants.save.addLevelNumber(1);
Constants.save.saveMove(3);
break;
case BOOT:
GamePlay.startBoot(Constants.currentLevel);
Constants.save.openBufferForWrite();
Constants.save.addLevelNumber(1);
Constants.save.saveMove(2);
break;
case LEVELS:
Constants.menu.hide();
Constants.subMenuLevels.show();
break;
case LEVEL_1:
Constants.gamePlay = new GamePlay();
Constants.gamePlay.createThread(1);
Constants.save.openBufferForWrite();
Constants.save.addLevelNumber(1);
Constants.save.saveMove(3);
break;
case LEVEL_2:
Constants.gamePlay = new GamePlay();
Constants.gamePlay.createThread(2);
Constants.save.openBufferForWrite();
Constants.save.addLevelNumber(2);
Constants.save.saveMove(3);
break;
case PLAY_SAVED:
Constants.save.openBufferForRead();
GamePlay.startGame(Constants.save.getIntFromFile(), Constants.save.getIntFromFile());
break;
case SAVES:
Constants.save.showSaves();
break;
case SORTING:
Constants.startSorting = true;
Thread sorting = new Thread(new LoadThread(true, "loading.gif", 70, 70, 70, 70, 900, 15));
sorting.start();
break;
case SORTING_LIST:
JavaSorting getList = new JavaSorting();
getList.showSortingList();
break;
case BACK:
Constants.subMenuLevels.hide();
Constants.menu.show();
default:
break;
}
}
}