-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbak.pdeB
182 lines (148 loc) · 4.49 KB
/
bak.pdeB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
NotificationManager notificationManager = new NotificationManager();
notificationManager.add(NotificationType.SUCCESS, "Hallo");
notificationManager.draw();
public enum NotificationType
{
SUCCESS, ERROR, INFO
}
public enum NotificationState
{
STARTING, IDLE, ENDING
}
class Notification {
private NotificationType type;
private String text;
private NotificationState state = NotificationState.STARTING;
private int startTime = millis();
Notification(NotificationType notificationType, String text) {
this.type = notificationType;
this.text = text;
}
String getText() {
return text;
}
int getStartTime() {
return startTime;
}
void setStartTime(int startTime) {
this.startTime = startTime;
}
public NotificationState getState() {
return state;
}
public void setState(NotificationState state) {
this.state = state;
}
}
class NotificationManager {
Map<NotificationState, Integer> notificationTimeMap = new HashMap<NotificationState, Integer>() {{
put(NotificationState.STARTING, 300);
put(NotificationState.IDLE, 1000);
put(NotificationState.ENDING, 300);
} };
private List<Notification> notifications = new ArrayList<Notification>();
private Set<Notification> notificationsToRemove = new HashSet<Notification>();
public void add(NotificationType type, String text) {
Notification notification = new Notification(type, text);
this.notifications.add(notification);
}
void draw() {
if (notifications.size() == 0) {
return;
}
for (Notification notification : notifications) {
int time = millis();
if (time - notification.getStartTime() > notificationTimeMap.get(notification.getState())) {
switch(notification.getState()) {
case STARTING:
notification.setState(NotificationState.IDLE);
notification.setStartTime(time);
break;
case IDLE:
notification.setState(NotificationState.ENDING);
notification.setStartTime(time);
break;
case ENDING:
notificationsToRemove.add(notification);
break;
}
}
}
// if (notificationsToRemove.size() == notifications.size()) {
notifications.removeAll(notificationsToRemove);
notificationsToRemove.clear();
// }
for (int i = 0; i < notifications.size(); i++) {
Notification notification = notifications.get(i);
if (notificationsToRemove.contains(notification)) {
continue;
}
int alphaText = 255;
int alphaBox = 180;
switch(notification.getState()) {
case STARTING : {
float precentage = (millis() - notification.getStartTime()) / (float)notificationTimeMap.get(notification.getState());
alphaText = round(alphaText * precentage);
alphaBox = round(alphaBox * precentage);
break;
}
case ENDING : {
float precentage = (millis() - notification.getStartTime()) / (float)notificationTimeMap.get(notifications.get(i).getState());
alphaText = round(alphaText * (1 - precentage));
alphaBox = round(alphaBox * (1 - precentage));
break;
}
//float precentage = (millis()-notifications.getStartTime()) / (float)notificationTimeMap.get(notifications.get(i).getState());
}
int positionY = i * 200;
fill(0,255,64,alphaBox);
noStroke();
rect(100, positionY, 300, 195);
fill(0,0,0,alphaText);
textAlign(CENTER,CENTER);
text(notifications.get(i).getText(), 100 + 150, positionY + 100);
}
}
}
synchronized boolean solve_crme() {
for (int y = 0; y < 9; y++) {
for (int x = 0; x < 9; x++) {
if (board[y][x] == 0) {
//empty cell found
//all possible candidates
List<Integer> candidates = new ArrayList<Integer>();
Collections.addAll(candidates, 1, 2, 3, 4, 5, 6, 7, 8, 9);
//check y
for (int col = 0; col < 9; col++) {
if (board[y][col] != 0) {
candidates.remove(new Integer(board[y][col]));
}
}
//check x
for (int row = 0; row < 9; row++) {
if (board[row][x] != 0) {
candidates.remove(new Integer(board[row][x]));
}
}
//check minigrid
int startCol = x - (x % 3);
int startRow = y - (y % 3);
for (int row = 0; row < 3; row++) {
for (int col = 0; col < 3; col++) {
if (board[row + startRow][col + startCol] != 0) {
candidates.remove(new Integer(board[row + startRow][col + startCol]));
}
}
}
//candidates left:
//println("candidates: " +candidates);
//found single possible value for cell
if (candidates.size() == 1) {
board[y][x] = candidates.get(0);
return true;
}
}
}
}
return false;
}