Skip to content

Commit f0addb8

Browse files
authored
Merge pull request #6 from leedave/feature/colorguess_final
Feature/colorguess final
2 parents 590f63b + 2dea0f8 commit f0addb8

File tree

6 files changed

+121
-15
lines changed

6 files changed

+121
-15
lines changed

Games/color_guess/README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Flipper Zero Color Guessing Game
2-
<div style="text-align:center"><img src="assets/flipper_logo_orange.png"/></div>
2+
<div style="text-align:center">
3+
<img src="assets/flipper_logo_orange.png"/>
4+
<img src="assets/preview.jpg" />
5+
</div>
36

47
## What this is?
58
As a web developer I enjoy guessing colours by HEX Code. This game is targeted at other Devs and graphic designers<br>
@@ -8,7 +11,7 @@ that also enjoy this.
811

912
### Mode 1
1013
The LED will display a color and you must try and guess it by adjusting the HEX values on the screen. A timer will show<br>
11-
how fast you were.
14+
how fast you were. Three levels of difficulty are available. Vibro hints given to help you find the solution.
1215

1316
### Mode 2
1417
You can define a color using the HEX code on-screen and the LED will display this color

Games/color_guess/application.fam

+2
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ App(
1212
fap_icon="color_guess_10px.png",
1313
fap_icon_assets="icons",
1414
fap_category="Leed\Games",
15+
fap_author="Leed",
16+
fap_weburl="https://github.com/leedave/Leeds-Flipper-Zero-Applications",
1517
)

Games/color_guess/assets/preview.jpg

18.6 KB
Loading

Games/color_guess/helpers/color_guess_colors.h

+47
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ int colorsEasy[] = {
1515
0x500050,
1616
0x005050,
1717
0x505050,
18+
0x0000c0,
19+
0x010101,
20+
0xcccccc,
21+
0xcc00cc,
22+
0x00cccc,
23+
0xcccc00,
24+
0xcc0000,
25+
0x00cc00,
26+
0x0000cc,
27+
0x000000,
1828
};
1929

2030
int colorsNormal[] = {
@@ -33,6 +43,21 @@ int colorsNormal[] = {
3343
0xbc00ff,
3444
0xff6a00,
3545
0xc5c5c5,
46+
0xafafc0,
47+
0xcece00,
48+
0xcf6500,
49+
0x2b2b00,
50+
0x55ee11,
51+
0xff33ff,
52+
0x2266ff,
53+
0x530053,
54+
0x3399ff,
55+
0xff0033,
56+
0x99ff22,
57+
0xab00ab,
58+
0x55ff55,
59+
0x9999ff,
60+
0xe500e5,
3661
};
3762

3863
int colorsHard[] = {
@@ -47,4 +72,26 @@ int colorsHard[] = {
4772
0x8b3785,
4873
0x8b4137,
4974
0xffbdb5,
75+
0x3a3aa7,
76+
0x37a6bd,
77+
0xbd4737,
78+
0x621308,
79+
0x086238,
80+
0x2d4137,
81+
0x711761,
82+
0xdc26bc,
83+
0xdc266e,
84+
0x26dc81,
85+
0x8d4500,
86+
0xb8c22b,
87+
0x2bc2a0,
88+
0x9064c1,
89+
0x732bc2,
90+
0x5610a3,
91+
0xa31034,
92+
0xe50c41,
93+
0x6d001a,
94+
0x159bbc,
95+
0x32bc15,
96+
0x53e60c,
5097
};

Games/color_guess/views/color_guess_play.c

+66-12
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ typedef struct {
2323
int color;
2424
int time_spent;
2525
int timestamp_start;
26+
int prev_closeness;
2627
int closeness;
2728
int difficulty;
29+
int success;
2830
} ColorGuessPlayModel;
2931

3032
void color_guess_play_set_callback(
@@ -37,13 +39,36 @@ void color_guess_play_set_callback(
3739
instance->context = context;
3840
}
3941

42+
void play_happy_bop(void* context, ColorGuessPlayModel* model) {
43+
ColorGuess* app = context;
44+
if (model->success == 1) {
45+
for (int i = 0; i < 4; i++) {
46+
notification_message(app->notification, &sequence_set_vibro_on);
47+
furi_thread_flags_wait(0, FuriFlagWaitAny, 50);
48+
notification_message(app->notification, &sequence_reset_vibro);
49+
furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
50+
}
51+
} else if (model->closeness > model->prev_closeness) {
52+
notification_message(app->notification, &sequence_set_vibro_on);
53+
furi_thread_flags_wait(0, FuriFlagWaitAny, 20);
54+
notification_message(app->notification, &sequence_reset_vibro);
55+
} else if (model->closeness < model->prev_closeness) {
56+
notification_message(app->notification, &sequence_set_vibro_on);
57+
furi_thread_flags_wait(0, FuriFlagWaitAny, 100);
58+
notification_message(app->notification, &sequence_reset_vibro);
59+
}
60+
}
61+
4062
void color_guess_play_new_round(void* context, ColorGuessPlayModel* model) {
4163
furi_assert(context);
4264
ColorGuess* app = context;
4365
//Reset timer
4466
FuriHalRtcDateTime date_time;
4567
furi_hal_rtc_get_datetime(&date_time);
4668
model->timestamp_start = furi_hal_rtc_datetime_to_timestamp(&date_time);
69+
model->success = 0;
70+
model->closeness = 0;
71+
model->prev_closeness = 0;
4772

4873
//Set random color
4974
NotificationMessage notification_led_message_1;
@@ -65,8 +90,6 @@ void color_guess_play_new_round(void* context, ColorGuessPlayModel* model) {
6590
notification_led_message_2.data.led.value = ((model->color >> 8) & 0xFF);
6691
notification_led_message_3.data.led.value = ((model->color) & 0xFF);
6792

68-
//model->closeness = ((model->color >> 8) & 0xFF);
69-
7093
const NotificationSequence notification_sequence = {
7194
&notification_led_message_1,
7295
&notification_led_message_2,
@@ -79,7 +102,9 @@ void color_guess_play_new_round(void* context, ColorGuessPlayModel* model) {
79102
}
80103

81104
void color_guess_play_calculate_closeness(void* context, ColorGuessPlayModel* model) {
82-
UNUSED(context);
105+
furi_assert(context);
106+
ColorGuess* app = context;
107+
UNUSED(app);
83108
int userRed = (model->digit[0] * 16) + model->digit[1];
84109
int userGreen = (model->digit[2] * 16) + model->digit[3];
85110
int userBlue = (model->digit[4] * 16) + model->digit[5];
@@ -93,13 +118,15 @@ void color_guess_play_calculate_closeness(void* context, ColorGuessPlayModel* mo
93118
float percentageRed = 100 - ((distanceRed / 255.0) * 100); //make sure one number is float, otherwise C will calc wrong
94119
float percentageGreen = 100 - ((distanceGreen / 255.0) * 100);
95120
float percentageBlue = 100 - ((distanceBlue / 255.0) * 100);
121+
if (percentageRed == 100 && percentageGreen == 100 && percentageBlue == 100) {
122+
model->success = 1;
123+
}
96124
float fullPercentage = (percentageRed + percentageGreen + percentageBlue) / 3;
125+
model->prev_closeness = model->closeness;
97126
model->closeness = round(fullPercentage);
98127
}
99128

100129
void parse_time_str(char* buffer, int32_t sec) {
101-
//int seconds = sec % 60;
102-
//int minutes = (sec % (60 * 60)) / 60;
103130
snprintf(
104131
buffer,
105132
TIMER_LENGHT,
@@ -128,17 +155,38 @@ void drawDifficulty(Canvas* canvas, ColorGuessPlayModel* model) {
128155
}
129156

130157
void color_guess_play_draw(Canvas* canvas, ColorGuessPlayModel* model) {
158+
char timer_string[TIMER_LENGHT];
159+
if (model->success == 1) {
160+
parse_time_str(timer_string, model->time_spent);
161+
canvas_clear(canvas);
162+
canvas_set_color(canvas, ColorBlack);
163+
canvas_set_font(canvas, FontPrimary);
164+
canvas_draw_str_aligned(canvas, 64, 2, AlignCenter, AlignTop, "You won!!");
165+
canvas_set_font(canvas, FontSecondary);
166+
elements_button_center(canvas, "New Round");
167+
canvas_set_font(canvas, FontBigNumbers);
168+
canvas_draw_str_aligned(canvas, 64, 16, AlignCenter, AlignTop, timer_string);
169+
170+
canvas_draw_icon(canvas, 18, 32, digits[16]);
171+
canvas_draw_icon(canvas, 30, 32, digits[model->digit[0]]);
172+
canvas_draw_icon(canvas, 42, 32, digits[model->digit[1]]);
173+
canvas_draw_icon(canvas, 54, 32, digits[model->digit[2]]);
174+
canvas_draw_icon(canvas, 66, 32, digits[model->digit[3]]);
175+
canvas_draw_icon(canvas, 78, 32, digits[model->digit[4]]);
176+
canvas_draw_icon(canvas, 90, 32, digits[model->digit[5]]);
177+
178+
return;
179+
}
131180
const int cursorOffset = 30;
132181
const int newCursorPos = (model->cursorpos * 12) + cursorOffset;
133182
FuriHalRtcDateTime date_time;
134183
furi_hal_rtc_get_datetime(&date_time);
135184
uint32_t timestamp = furi_hal_rtc_datetime_to_timestamp(&date_time);
136185
uint32_t time_elapsed = timestamp - model->timestamp_start;
137-
138-
char timer_string[TIMER_LENGHT];
139-
char closeness_string[4];
140-
UNUSED(time_elapsed);
186+
model->time_spent = time_elapsed;
141187

188+
char closeness_string[4];
189+
142190
//snprintf(timer_string, TIMER_LENGHT, TIMER_FORMAT, date_time.minute, date_time.second);
143191
parse_time_str(timer_string, time_elapsed);
144192
snprintf(closeness_string, CLOSENESS_LENGTH, CLOSENESS_FORMAT, model->closeness);
@@ -224,6 +272,7 @@ bool color_guess_play_input(InputEvent* event, void* context) {
224272
model->digit[model->cursorpos] = 0;
225273
}
226274
color_guess_play_calculate_closeness(instance, model);
275+
play_happy_bop(instance->context, model);
227276
},
228277
true);
229278
break;
@@ -237,6 +286,7 @@ bool color_guess_play_input(InputEvent* event, void* context) {
237286
model->digit[model->cursorpos] = 15;
238287
}
239288
color_guess_play_calculate_closeness(instance, model);
289+
play_happy_bop(instance->context, model);
240290
},
241291
true);
242292
break;
@@ -245,9 +295,13 @@ bool color_guess_play_input(InputEvent* event, void* context) {
245295
instance->view,
246296
ColorGuessPlayModel* model,
247297
{
248-
model->difficulty++;
249-
if (model->difficulty > 2) {
250-
model->difficulty = 0;
298+
if (model->success == 1) {
299+
model->success = 0;
300+
} else {
301+
model->difficulty++;
302+
if (model->difficulty > 2) {
303+
model->difficulty = 0;
304+
}
251305
}
252306
color_guess_play_new_round(instance->context, model);
253307
},

Games/color_guess/views/color_guess_play.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
extern const Icon* digits[17];
77

88
#define TIMER_FORMAT "%02ld:%02ld" //"%.2d:%.2d"
9-
#define TIMER_LENGHT 12
9+
#define TIMER_LENGHT 13
1010
#define CLOSENESS_LENGTH 7
1111
#define CLOSENESS_FORMAT "%d%%"
1212
#define ARR_SIZE(arr) ( sizeof((arr)) / sizeof((arr[0])) )

0 commit comments

Comments
 (0)