[Refactor] Separate Round logic into its own file (#570)
* Everything works, need to clean up * cleanup * fix rebase issue * clang format * docs * clang format * clang format * address part of review * Protect against edge case when discarding at end of hand * Protect undiscard against popping a discarded card that doesn't exist * Protect against out of bounds access to the `played` cards stack * fix condition in `select_four_of_a_kind_cards_in_played_hand` * change `get_played_top() + 1` to `get_played_size()` * move `can_play/discard_hand` functions to round.c --------- Co-authored-by: MathisMartin31 <mathis.martin31@gmail.com>
This commit is contained in:
@@ -5,7 +5,7 @@ DEF_STATE_INFO(GAME_STATE_MAIN_MENU, game_main_menu_on_init, game_main_me
|
||||
DEF_STATE_INFO(GAME_STATE_OPTIONS_MENU, game_options_menu_on_init, game_options_menu_on_update, game_options_menu_on_exit)
|
||||
DEF_STATE_INFO(GAME_STATE_RUN_SETUP , game_run_setup_on_init, game_run_setup_on_update, game_run_setup_on_exit )
|
||||
DEF_STATE_INFO(GAME_STATE_GAME_START, noop, game_start, noop )
|
||||
DEF_STATE_INFO(GAME_STATE_PLAYING, game_round_on_init, game_playing_on_update, noop )
|
||||
DEF_STATE_INFO(GAME_STATE_ROUND, game_round_on_init, game_round_on_update, noop )
|
||||
DEF_STATE_INFO(GAME_STATE_ROUND_END, game_round_end_on_init, game_round_end_on_update, game_round_end_on_exit )
|
||||
DEF_STATE_INFO(GAME_STATE_SHOP, game_shop_on_init, game_shop_on_update, game_shop_on_exit )
|
||||
DEF_STATE_INFO(GAME_STATE_BLIND_SELECT, game_blind_select_on_init, game_blind_select_on_update, game_blind_select_on_exit)
|
||||
|
||||
+7
-28
@@ -51,19 +51,6 @@ enum GameState
|
||||
GAME_STATE_UNDEFINED
|
||||
};
|
||||
|
||||
enum PlayState
|
||||
{
|
||||
PLAY_STARTING,
|
||||
PLAY_BEFORE_SCORING,
|
||||
PLAY_SCORING_CARDS,
|
||||
PLAY_SCORING_CARD_JOKERS,
|
||||
PLAY_SCORING_HELD_CARDS,
|
||||
PLAY_SCORING_INDEPENDENT_JOKERS,
|
||||
PLAY_SCORING_HAND_SCORED_END,
|
||||
PLAY_ENDING,
|
||||
PLAY_ENDED
|
||||
};
|
||||
|
||||
// Game functions
|
||||
void game_init(void);
|
||||
|
||||
@@ -81,9 +68,6 @@ void game_update(void);
|
||||
void game_change_state(enum GameState new_game_state);
|
||||
enum GameState game_get_state(void);
|
||||
|
||||
CardObject** get_played_array(void);
|
||||
int get_played_top(void);
|
||||
int get_scored_card_index(void);
|
||||
bool is_joker_owned(int joker_id);
|
||||
bool card_is_face(Card* card);
|
||||
void add_joker(JokerObject* joker_object);
|
||||
@@ -92,19 +76,19 @@ List* get_jokers_list(void);
|
||||
List* get_expired_jokers_list(void);
|
||||
List* get_discarded_jokers_list(void);
|
||||
|
||||
int deck_get_size(void);
|
||||
int get_deck_top(void);
|
||||
void deck_push(Card* card);
|
||||
Card* deck_pop(void);
|
||||
void deck_shuffle(void);
|
||||
int get_num_discards_remaining(void);
|
||||
int get_num_hands_remaining(void);
|
||||
|
||||
void display_deck_size_max(void);
|
||||
u32 get_chips(void);
|
||||
void set_chips(u32 new_chips);
|
||||
void display_chips(void);
|
||||
u32 get_mult(void);
|
||||
void set_mult(u32 new_mult);
|
||||
void display_mult(void);
|
||||
void display_money(void);
|
||||
void set_retrigger(bool new_retrigger);
|
||||
void display_ante(void);
|
||||
|
||||
// joker specific functions
|
||||
bool is_shortcut_joker_active(void);
|
||||
@@ -112,16 +96,11 @@ int get_straight_and_flush_size(void);
|
||||
|
||||
void game_start(void);
|
||||
|
||||
// Temporary change for Refactor. Currently this compatibility binder is to allow
|
||||
// simultaneous integration of the new system in `common_ui` with the the existing
|
||||
// old system incrementally and without losing functionality.
|
||||
void change_background_legacy(enum BackgroundId id);
|
||||
|
||||
void display_round(void);
|
||||
|
||||
void reset_background(void);
|
||||
void display_hands(void);
|
||||
void display_discards(void);
|
||||
void display_temp_score(u32 value);
|
||||
void erase_temp_score(void);
|
||||
void display_score(u32 value);
|
||||
|
||||
#endif // GAME_H
|
||||
|
||||
@@ -24,6 +24,8 @@ enum BackgroundId
|
||||
BG_MAIN_MENU
|
||||
};
|
||||
|
||||
enum BackgroundId get_current_background(void);
|
||||
|
||||
/**
|
||||
* Change the background
|
||||
*
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* @file round.h
|
||||
* @brief API relative to the Rounds we play
|
||||
*/
|
||||
|
||||
#ifndef GAME_ROUND_H
|
||||
#define GAME_ROUND_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* @brief Checks whether the score that would result from the current Chips and Mult exceeds the
|
||||
* current Blind's score requirement, and applies the flaming effect if needed.
|
||||
*/
|
||||
void toggle_flaming_score(void);
|
||||
|
||||
/**
|
||||
* @brief Get the index of the last played card
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int get_played_top(void);
|
||||
|
||||
/**
|
||||
* @brief Get the number of cards played
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int get_played_size(void);
|
||||
|
||||
/**
|
||||
* @brief Get the index of the last discarded card
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int get_discard_top(void);
|
||||
|
||||
/**
|
||||
* @brief Get the index of the card that is currently being scored
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int get_scored_card_index(void);
|
||||
|
||||
/**
|
||||
* @brief Set whether the current card should get triggered again
|
||||
*
|
||||
* @param new_retrigger true if the card should trigger again, false if not
|
||||
*/
|
||||
void set_retrigger(bool new_retrigger);
|
||||
|
||||
/**
|
||||
* @brief Change to the round card selection background
|
||||
*/
|
||||
void game_round_change_background_selecting(void);
|
||||
|
||||
/**
|
||||
* @brief Change to the round card playing background
|
||||
*/
|
||||
void game_round_change_background_playing(void);
|
||||
|
||||
/**
|
||||
* @brief Round state initialization
|
||||
*/
|
||||
void game_round_on_init(void);
|
||||
|
||||
/**
|
||||
* @brief Round state update
|
||||
*/
|
||||
void game_round_on_update(void);
|
||||
|
||||
#endif // GAME_ROUND_H
|
||||
@@ -58,6 +58,8 @@ typedef struct
|
||||
s32 hands;
|
||||
s32 discards;
|
||||
u32 score;
|
||||
u32 chips;
|
||||
u32 mult;
|
||||
|
||||
Sprite* playing_blind_token;
|
||||
Sprite* round_end_blind_token;
|
||||
|
||||
Reference in New Issue
Block a user