Merge pull request #87 from voloved/higher-lower-port
Higher lower port
This commit is contained in:
@@ -75,4 +75,5 @@
|
|||||||
#include "wordle_face.h"
|
#include "wordle_face.h"
|
||||||
#include "blackjack_face.h"
|
#include "blackjack_face.h"
|
||||||
#include "endless_runner_face.h"
|
#include "endless_runner_face.h"
|
||||||
|
#include "higher_lower_game_face.h"
|
||||||
// New includes go above this line.
|
// New includes go above this line.
|
||||||
|
|||||||
@@ -50,4 +50,5 @@ SRCS += \
|
|||||||
./watch-faces/complication/deadline_face.c \
|
./watch-faces/complication/deadline_face.c \
|
||||||
./watch-faces/complication/blackjack_face.c \
|
./watch-faces/complication/blackjack_face.c \
|
||||||
./watch-faces/complication/endless_runner_face.c \
|
./watch-faces/complication/endless_runner_face.c \
|
||||||
|
./watch-faces/complication/higher_lower_game_face.c \
|
||||||
# New watch faces go above this line.
|
# New watch faces go above this line.
|
||||||
|
|||||||
@@ -30,19 +30,22 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "higher_lower_game_face.h"
|
#include "higher_lower_game_face.h"
|
||||||
#include "watch_private_display.h"
|
#include "watch_common_display.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define KING 12
|
||||||
|
#define QUEEN 11
|
||||||
|
#define JACK 10
|
||||||
|
|
||||||
#define TITLE_TEXT "Hi-Lo"
|
#define TITLE_TEXT "Hi-Lo"
|
||||||
#define GAME_BOARD_SIZE 6
|
#define GAME_BOARD_SIZE 6
|
||||||
#define MAX_BOARDS 40
|
#define MAX_BOARDS 40
|
||||||
#define GUESSES_PER_SCREEN 5
|
#define GUESSES_PER_SCREEN 5
|
||||||
#define WIN_SCORE (MAX_BOARDS * GUESSES_PER_SCREEN)
|
#define WIN_SCORE (MAX_BOARDS * GUESSES_PER_SCREEN)
|
||||||
#define STATUS_DISPLAY_START 0
|
|
||||||
#define BOARD_SCORE_DISPLAY_START 2
|
|
||||||
#define BOARD_DISPLAY_START 4
|
#define BOARD_DISPLAY_START 4
|
||||||
#define BOARD_DISPLAY_END 9
|
#define BOARD_DISPLAY_END 9
|
||||||
#define MIN_CARD_VALUE 2
|
#define MIN_CARD_VALUE 2
|
||||||
#define MAX_CARD_VALUE 14
|
#define MAX_CARD_VALUE KING
|
||||||
#define CARD_RANK_COUNT (MAX_CARD_VALUE - MIN_CARD_VALUE + 1)
|
#define CARD_RANK_COUNT (MAX_CARD_VALUE - MIN_CARD_VALUE + 1)
|
||||||
#define CARD_SUIT_COUNT 4
|
#define CARD_SUIT_COUNT 4
|
||||||
#define DECK_SIZE (CARD_SUIT_COUNT * CARD_RANK_COUNT)
|
#define DECK_SIZE (CARD_SUIT_COUNT * CARD_RANK_COUNT)
|
||||||
@@ -111,7 +114,6 @@ static void shuffle_deck(void) {
|
|||||||
|
|
||||||
static void reset_deck(void) {
|
static void reset_deck(void) {
|
||||||
current_card = 0;
|
current_card = 0;
|
||||||
stack_deck();
|
|
||||||
shuffle_deck();
|
shuffle_deck();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,8 +143,8 @@ static void reset_board(bool first_round) {
|
|||||||
|
|
||||||
static void init_game(void) {
|
static void init_game(void) {
|
||||||
watch_clear_display();
|
watch_clear_display();
|
||||||
watch_display_string(TITLE_TEXT, BOARD_DISPLAY_START);
|
watch_display_text(WATCH_POSITION_BOTTOM, TITLE_TEXT);
|
||||||
watch_display_string("GA", STATUS_DISPLAY_START);
|
watch_display_text(WATCH_POSITION_TOP_LEFT, "HL");
|
||||||
reset_deck();
|
reset_deck();
|
||||||
reset_board(true);
|
reset_board(true);
|
||||||
score = 0;
|
score = 0;
|
||||||
@@ -151,16 +153,23 @@ static void init_game(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void set_segment_at_position(segment_t segment, uint8_t position) {
|
static void set_segment_at_position(segment_t segment, uint8_t position) {
|
||||||
const uint64_t position_segment_data = (Segment_Map[position] >> (8 * (uint8_t) segment)) & 0xFF;
|
digit_mapping_t segmap;
|
||||||
const uint8_t com_pin = position_segment_data >> 6;
|
if (watch_get_lcd_type() == WATCH_LCD_TYPE_CUSTOM) {
|
||||||
const uint8_t seg = position_segment_data & 0x3F;
|
segmap = Custom_LCD_Display_Mapping[position];
|
||||||
|
} else {
|
||||||
|
segmap = Classic_LCD_Display_Mapping[position];
|
||||||
|
}
|
||||||
|
const uint8_t com_pin = segmap.segment[segment].address.com;
|
||||||
|
const uint8_t seg = segmap.segment[segment].address.seg;
|
||||||
watch_set_pixel(com_pin, seg);
|
watch_set_pixel(com_pin, seg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline size_t get_display_position(size_t board_position) {
|
||||||
|
return FLIP_BOARD_DIRECTION ? BOARD_DISPLAY_START + board_position : BOARD_DISPLAY_END - board_position;
|
||||||
|
}
|
||||||
|
|
||||||
static void render_board_position(size_t board_position) {
|
static void render_board_position(size_t board_position) {
|
||||||
const size_t display_position = FLIP_BOARD_DIRECTION
|
const size_t display_position = get_display_position(board_position);
|
||||||
? BOARD_DISPLAY_START + board_position
|
|
||||||
: BOARD_DISPLAY_END - board_position;
|
|
||||||
const bool revealed = game_board[board_position].revealed;
|
const bool revealed = game_board[board_position].revealed;
|
||||||
|
|
||||||
//// Current position indicator spot
|
//// Current position indicator spot
|
||||||
@@ -178,18 +187,18 @@ static void render_board_position(size_t board_position) {
|
|||||||
|
|
||||||
const uint8_t value = game_board[board_position].value;
|
const uint8_t value = game_board[board_position].value;
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 14: // A (≡)
|
case KING: // K (≡)
|
||||||
watch_display_character(' ', display_position);
|
watch_display_character(' ', display_position);
|
||||||
set_segment_at_position(A, display_position);
|
set_segment_at_position(A, display_position);
|
||||||
set_segment_at_position(D, display_position);
|
set_segment_at_position(D, display_position);
|
||||||
set_segment_at_position(G, display_position);
|
set_segment_at_position(G, display_position);
|
||||||
break;
|
break;
|
||||||
case 13: // K (=)
|
case QUEEN: // Q (=)
|
||||||
watch_display_character(' ', display_position);
|
watch_display_character(' ', display_position);
|
||||||
set_segment_at_position(A, display_position);
|
set_segment_at_position(A, display_position);
|
||||||
set_segment_at_position(D, display_position);
|
set_segment_at_position(D, display_position);
|
||||||
break;
|
break;
|
||||||
case 12: // Q (-)
|
case JACK: // J (-)
|
||||||
watch_display_character('-', display_position);
|
watch_display_character('-', display_position);
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
@@ -209,16 +218,16 @@ static void render_board_count(void) {
|
|||||||
// Render completed boards (screens)
|
// Render completed boards (screens)
|
||||||
char buf[3] = {0};
|
char buf[3] = {0};
|
||||||
snprintf(buf, sizeof(buf), "%2hhu", completed_board_count);
|
snprintf(buf, sizeof(buf), "%2hhu", completed_board_count);
|
||||||
watch_display_string(buf, BOARD_SCORE_DISPLAY_START);
|
watch_display_text(WATCH_POSITION_TOP_RIGHT, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void render_final_score(void) {
|
static void render_final_score(void) {
|
||||||
watch_display_string("SC", STATUS_DISPLAY_START);
|
watch_display_text_with_fallback(WATCH_POSITION_TOP, "SCORE", "SC ");
|
||||||
char buf[7] = {0};
|
char buf[7] = {0};
|
||||||
const uint8_t complete_boards = score / GUESSES_PER_SCREEN;
|
const uint8_t complete_boards = score / GUESSES_PER_SCREEN;
|
||||||
snprintf(buf, sizeof(buf), "%2hu %03hu", complete_boards, score);
|
snprintf(buf, sizeof(buf), "%2hu %03hu", complete_boards, score);
|
||||||
watch_set_colon();
|
watch_set_colon();
|
||||||
watch_display_string(buf, BOARD_DISPLAY_START);
|
watch_display_text(WATCH_POSITION_BOTTOM, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static guess_t get_answer(void) {
|
static guess_t get_answer(void) {
|
||||||
@@ -251,13 +260,13 @@ static void do_game_loop(guess_t user_guess) {
|
|||||||
// Render answer indicator
|
// Render answer indicator
|
||||||
switch (answer) {
|
switch (answer) {
|
||||||
case HL_GUESS_EQUAL:
|
case HL_GUESS_EQUAL:
|
||||||
watch_display_string("==", STATUS_DISPLAY_START);
|
watch_display_text(WATCH_POSITION_TOP_LEFT, "==");
|
||||||
break;
|
break;
|
||||||
case HL_GUESS_HIGHER:
|
case HL_GUESS_HIGHER:
|
||||||
watch_display_string("HI", STATUS_DISPLAY_START);
|
watch_display_text(WATCH_POSITION_TOP_LEFT, "HI");
|
||||||
break;
|
break;
|
||||||
case HL_GUESS_LOWER:
|
case HL_GUESS_LOWER:
|
||||||
watch_display_string("LO", STATUS_DISPLAY_START);
|
watch_display_text(WATCH_POSITION_TOP_LEFT, "LO");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,18 +277,22 @@ static void do_game_loop(guess_t user_guess) {
|
|||||||
// No score for two consecutive identical cards
|
// No score for two consecutive identical cards
|
||||||
} else {
|
} else {
|
||||||
// Incorrect guess, game over
|
// Incorrect guess, game over
|
||||||
watch_display_string("GO", STATUS_DISPLAY_START);
|
watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "End", "GO");
|
||||||
game_board[guess_position].revealed = true;
|
game_board[guess_position].revealed = true;
|
||||||
|
watch_display_text(WATCH_POSITION_BOTTOM, "------");
|
||||||
|
render_board_position(guess_position - 1);
|
||||||
render_board_position(guess_position);
|
render_board_position(guess_position);
|
||||||
|
if (game_board[guess_position].value == JACK && guess_position < GAME_BOARD_SIZE) // Adds a space in case the revealed option is '-'
|
||||||
|
watch_display_character(' ', get_display_position(guess_position + 1));
|
||||||
game_state = HL_GS_LOSE;
|
game_state = HL_GS_LOSE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (score >= WIN_SCORE) {
|
if (score >= WIN_SCORE) {
|
||||||
// Win, perhaps some kind of animation sequence?
|
// Win, perhaps some kind of animation sequence?
|
||||||
watch_display_string("WI", STATUS_DISPLAY_START);
|
watch_display_text_with_fallback(WATCH_POSITION_TOP_LEFT, "WIN", "WI");
|
||||||
watch_display_string(" ", BOARD_SCORE_DISPLAY_START);
|
watch_display_text(WATCH_POSITION_TOP_RIGHT, " ");
|
||||||
watch_display_string("------", BOARD_DISPLAY_START);
|
watch_display_text_with_fallback(WATCH_POSITION_BOTTOM, "WINNER", "winnEr");
|
||||||
game_state = HL_GS_WIN;
|
game_state = HL_GS_WIN;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -309,12 +322,12 @@ static void do_game_loop(guess_t user_guess) {
|
|||||||
break;
|
break;
|
||||||
case HL_GS_SHOW_SCORE:
|
case HL_GS_SHOW_SCORE:
|
||||||
watch_clear_display();
|
watch_clear_display();
|
||||||
watch_display_string(TITLE_TEXT, BOARD_DISPLAY_START);
|
watch_display_text(WATCH_POSITION_BOTTOM, TITLE_TEXT);
|
||||||
watch_display_string("GA", STATUS_DISPLAY_START);
|
watch_display_text(WATCH_POSITION_TOP_LEFT, "HL");
|
||||||
game_state = HL_GS_TITLE_SCREEN;
|
game_state = HL_GS_TITLE_SCREEN;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
watch_display_string("ERROR", BOARD_DISPLAY_START);
|
watch_display_text(WATCH_POSITION_BOTTOM, "ERROR");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,6 +357,7 @@ void higher_lower_game_face_activate(void *context) {
|
|||||||
(void) state;
|
(void) state;
|
||||||
// Handle any tasks related to your watch face coming on screen.
|
// Handle any tasks related to your watch face coming on screen.
|
||||||
game_state = HL_GS_TITLE_SCREEN;
|
game_state = HL_GS_TITLE_SCREEN;
|
||||||
|
stack_deck();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool higher_lower_game_face_loop(movement_event_t event, void *context) {
|
bool higher_lower_game_face_loop(movement_event_t event, void *context) {
|
||||||
@@ -353,8 +367,8 @@ bool higher_lower_game_face_loop(movement_event_t event, void *context) {
|
|||||||
switch (event.event_type) {
|
switch (event.event_type) {
|
||||||
case EVENT_ACTIVATE:
|
case EVENT_ACTIVATE:
|
||||||
// Show your initial UI here.
|
// Show your initial UI here.
|
||||||
watch_display_string(TITLE_TEXT, BOARD_DISPLAY_START);
|
watch_display_text(WATCH_POSITION_BOTTOM, TITLE_TEXT);
|
||||||
watch_display_string("GA", STATUS_DISPLAY_START);
|
watch_display_text(WATCH_POSITION_TOP_LEFT, "HL");
|
||||||
break;
|
break;
|
||||||
case EVENT_TICK:
|
case EVENT_TICK:
|
||||||
// If needed, update your display here.
|
// If needed, update your display here.
|
||||||
Reference in New Issue
Block a user