monopoly Main UI Changes

This commit is contained in:
Adolfo Reyna
2026-01-31 22:46:26 -05:00
parent 78b376ad5d
commit c6d7bd6c8c
4 changed files with 321 additions and 64 deletions
Binary file not shown.
+304 -60
View File
@@ -20,6 +20,8 @@ extern "C" {
#include "DiceModalGame.h" #include "DiceModalGame.h"
#include "PropertyModalGame.h" #include "PropertyModalGame.h"
#include "BoardModalGame.h" #include "BoardModalGame.h"
#include "ChanceModalGame.h"
#include "CommunityChestModalGame.h"
#include "MonopolyBoardRenderer.h" #include "MonopolyBoardRenderer.h"
@@ -45,15 +47,53 @@ void MonopolyGame::init() {
just_sent_to_jail = false; just_sent_to_jail = false;
selected_action = 0; selected_action = 0;
srand(time(NULL)); srand(time(NULL));
shuffle_chance_deck();
shuffle_community_deck();
if (active_modal) { delete active_modal; active_modal = nullptr; } if (active_modal) { delete active_modal; active_modal = nullptr; }
// TODO: Reset all board state, property ownership, etc. // TODO: Reset all board state, property ownership, etc.
} }
void MonopolyGame::shuffle_chance_deck() {
for (int i = 0; i < CHANCE_DECK_SIZE; i++) {
chance_deck[i] = i;
}
for (int i = CHANCE_DECK_SIZE - 1; i > 0; i--) {
int j = rand() % (i + 1);
int temp = chance_deck[i];
chance_deck[i] = chance_deck[j];
chance_deck[j] = temp;
}
current_chance_idx = 0;
}
void MonopolyGame::shuffle_community_deck() {
for (int i = 0; i < COMMUNITY_DECK_SIZE; i++) {
community_deck[i] = i;
}
for (int i = COMMUNITY_DECK_SIZE - 1; i > 0; i--) {
int j = rand() % (i + 1);
int temp = community_deck[i];
community_deck[i] = community_deck[j];
community_deck[j] = temp;
}
current_community_idx = 0;
}
// --- Handle input events (minimal: roll, buy, end turn) --- // --- Handle input events (minimal: roll, buy, end turn) ---
bool MonopolyGame::update(const InputEvent& event) { bool MonopolyGame::update(const InputEvent& event) {
Player* p = &players[current_player_idx]; Player* p = &players[current_player_idx];
bool needs_redraw = false; bool needs_redraw = false;
// Calculate available actions
int menu_count = 0;
if (!has_rolled) {
menu_count++; // Roll Dice
if (p->is_in_jail) menu_count++; // Pay $50
} else {
menu_count++; // End Turn
}
menu_count++; // View Board
// If a modal is active, delegate input and check for dismissal // If a modal is active, delegate input and check for dismissal
if (active_modal) { if (active_modal) {
bool modal_redraw = active_modal->update(event); bool modal_redraw = active_modal->update(event);
@@ -63,6 +103,8 @@ bool MonopolyGame::update(const InputEvent& event) {
DiceModalGame* dice_modal = (active_modal->get_type() == Game::Type::MONOPOLY_DICE) ? static_cast<DiceModalGame*>(active_modal) : nullptr; DiceModalGame* dice_modal = (active_modal->get_type() == Game::Type::MONOPOLY_DICE) ? static_cast<DiceModalGame*>(active_modal) : nullptr;
PropertyModalGame* prop_modal = (active_modal->get_type() == Game::Type::MONOPOLY_PROPERTY) ? static_cast<PropertyModalGame*>(active_modal) : nullptr; PropertyModalGame* prop_modal = (active_modal->get_type() == Game::Type::MONOPOLY_PROPERTY) ? static_cast<PropertyModalGame*>(active_modal) : nullptr;
BoardModalGame* board_modal = (active_modal->get_type() == Game::Type::MONOPOLY_BOARD) ? static_cast<BoardModalGame*>(active_modal) : nullptr; BoardModalGame* board_modal = (active_modal->get_type() == Game::Type::MONOPOLY_BOARD) ? static_cast<BoardModalGame*>(active_modal) : nullptr;
ChanceModalGame* chance_modal = (active_modal->get_type() == Game::Type::MONOPOLY_CHANCE) ? static_cast<ChanceModalGame*>(active_modal) : nullptr;
CommunityChestModalGame* community_modal = (active_modal->get_type() == Game::Type::MONOPOLY_COMMUNITY_CHEST) ? static_cast<CommunityChestModalGame*>(active_modal) : nullptr;
if (dice_modal && dice_modal->is_dismissed()) { if (dice_modal && dice_modal->is_dismissed()) {
delete active_modal; delete active_modal;
@@ -88,9 +130,164 @@ bool MonopolyGame::update(const InputEvent& event) {
bool can_afford = (p->balance >= MONOPOLY_BOARD[modal_property_index].cost); bool can_afford = (p->balance >= MONOPOLY_BOARD[modal_property_index].cost);
active_modal = new PropertyModalGame(width, height, renderer, gui, input_manager, &MONOPOLY_BOARD[modal_property_index], is_owned, owner_name, owner_id, can_afford, players, players_count); active_modal = new PropertyModalGame(width, height, renderer, gui, input_manager, &MONOPOLY_BOARD[modal_property_index], is_owned, owner_name, owner_id, can_afford, players, players_count);
modal_property_index = -1; modal_property_index = -1;
} else if (last_drawn_chance_idx >= 0) {
active_modal = new ChanceModalGame(width, height, renderer, gui, input_manager, &CHANCE_DECK[last_drawn_chance_idx], players, players_count, p->position);
// We'll apply the effect when ChanceModal is dismissed
} else if (last_drawn_community_idx >= 0) {
active_modal = new CommunityChestModalGame(width, height, renderer, gui, input_manager, &COMMUNITY_DECK[last_drawn_community_idx], players, players_count, p->position);
// We'll apply the effect when CommunityChestModal is dismissed
} }
return needs_redraw; return needs_redraw;
} else if (prop_modal && prop_modal->is_dismissed()) { } else if (chance_modal && chance_modal->is_dismissed()) {
const ChanceCard* card = &CHANCE_DECK[last_drawn_chance_idx];
last_drawn_chance_idx = -1;
// Apply card effects
bool position_changed = false;
int old_pos = p->position;
switch (card->type) {
case CHANCE_EARN:
p->balance += card->value;
break;
case CHANCE_SPEND:
p->balance -= card->value;
break;
case CHANCE_ADVANCE: {
int target = card->value;
if (target == TARGET_NEAREST_UTILITY) {
target = (p->position + 1) % BOARD_SIZE;
while (MONOPOLY_BOARD[target].type != TILE_UTILITY) {
target = (target + 1) % BOARD_SIZE;
}
force_utility_10x = true;
} else if (target == TARGET_NEAREST_RAILROAD) {
target = (p->position + 1) % BOARD_SIZE;
while (MONOPOLY_BOARD[target].type != TILE_RAILROAD) {
target = (target + 1) % BOARD_SIZE;
}
rent_multiplier = 2;
}
p->position = target;
if (p->position < old_pos) p->balance += 200;
position_changed = true;
break;
}
case CHANCE_BACK:
p->position = (p->position - card->value + BOARD_SIZE) % BOARD_SIZE;
position_changed = true;
break;
case CHANCE_JAIL:
p->position = 10; // Jail
p->is_in_jail = true;
break;
case CHANCE_JAIL_FREE:
p->jail_free_cards++;
break;
case CHANCE_SPEND_EACH_PLAYER:
for (int i = 0; i < players_count; i++) {
if (i != (int)current_player_idx) {
p->balance -= card->value;
players[i].balance += card->value;
}
}
break;
case CHANCE_REPAIRS:
// For now, simplify or implement if houses are tracked
break;
}
delete active_modal;
active_modal = nullptr;
needs_redraw = true;
if (position_changed) {
// If we moved, check if we landed on a property
const BoardTile* landed = &MONOPOLY_BOARD[p->position];
if (landed->type == TILE_PROPERTY || landed->type == TILE_RAILROAD || landed->type == TILE_UTILITY) {
bool is_owned = false;
const char* owner_name = nullptr;
int owner_id = -1;
for (int i = 0; i < players_count; ++i) {
for (int j = 0; j < players[i].property_count; ++j) {
if (players[i].properties_owned[j] == p->position) {
is_owned = true;
owner_name = players[i].name;
owner_id = i;
break;
}
}
}
bool can_afford = (p->balance >= landed->cost);
active_modal = new PropertyModalGame(width, height, renderer, gui, input_manager, landed, is_owned, owner_name, owner_id, can_afford, players, players_count);
}
}
return needs_redraw;
} else if (community_modal && community_modal->is_dismissed()) {
const CommunityCard* card = &COMMUNITY_DECK[last_drawn_community_idx];
last_drawn_community_idx = -1;
bool position_changed = false;
int old_pos = p->position;
switch (card->type) {
case COMMUNITY_EARN:
p->balance += card->value;
break;
case COMMUNITY_SPEND:
p->balance -= card->value;
break;
case COMMUNITY_ADVANCE:
p->position = card->value;
if (p->position < old_pos) p->balance += 200;
position_changed = true;
break;
case COMMUNITY_JAIL:
p->position = 10;
p->is_in_jail = true;
break;
case COMMUNITY_JAIL_FREE:
p->jail_free_cards++;
break;
case COMMUNITY_EARN_EACH_PLAYER:
for (int i = 0; i < players_count; i++) {
if (i != (int)current_player_idx) {
p->balance += card->value;
players[i].balance -= card->value;
}
}
break;
case COMMUNITY_REPAIRS:
// p->balance -= (houses * card->value) + (hotels * card->value2);
break;
}
delete active_modal;
active_modal = nullptr;
needs_redraw = true;
if (position_changed) {
const BoardTile* landed = &MONOPOLY_BOARD[p->position];
if (landed->type == TILE_PROPERTY || landed->type == TILE_RAILROAD || landed->type == TILE_UTILITY) {
bool is_owned = false;
const char* owner_name = nullptr;
int owner_id = -1;
for (int i = 0; i < players_count; ++i) {
for (int j = 0; j < players[i].property_count; ++j) {
if (players[i].properties_owned[j] == p->position) {
is_owned = true;
owner_name = players[i].name;
owner_id = i;
break;
}
}
}
bool can_afford = (p->balance >= landed->cost);
active_modal = new PropertyModalGame(width, height, renderer, gui, input_manager, landed, is_owned, owner_name, owner_id, can_afford, players, players_count);
}
}
return needs_redraw;
} else if (prop_modal && prop_modal->is_dismissed()) {
if (prop_modal->wants_to_buy()) { if (prop_modal->wants_to_buy()) {
const BoardTile* tile = &MONOPOLY_BOARD[p->position]; const BoardTile* tile = &MONOPOLY_BOARD[p->position];
if (p->balance >= tile->cost) { if (p->balance >= tile->cost) {
@@ -137,15 +334,25 @@ bool MonopolyGame::update(const InputEvent& event) {
} }
} }
} }
rent = (utility_count == 2) ? (total_dice * 10) : (total_dice * 4); if (force_utility_10x) {
rent = total_dice * 10;
} else {
rent = (utility_count == 2) ? (total_dice * 10) : (total_dice * 4);
}
} }
rent *= rent_multiplier;
int o_id = prop_modal->get_owner_id(); int o_id = prop_modal->get_owner_id();
if (o_id != -1 && (int)current_player_idx != o_id) { if (o_id != -1 && (int)current_player_idx != o_id) {
p->balance -= rent; p->balance -= rent;
players[o_id].balance += rent; players[o_id].balance += rent;
} }
} }
// Reset multipliers
rent_multiplier = 1;
force_utility_10x = false;
delete active_modal; delete active_modal;
active_modal = nullptr; active_modal = nullptr;
needs_redraw = true; needs_redraw = true;
@@ -158,54 +365,90 @@ bool MonopolyGame::update(const InputEvent& event) {
} }
switch (event.type) { switch (event.type) {
case INPUT_BUTTON_0: // Cycle options case INPUT_BUTTON_0:
selected_action = (selected_action + 1) % ACTION_COUNT; selected_action = (selected_action + 1) % menu_count;
needs_redraw = true; needs_redraw = true;
break; break;
case INPUT_BUTTON_1: // Select option case INPUT_BUTTON_1:
switch (selected_action) { if (p->is_in_jail && !has_rolled && selected_action == 1) {
case 0: // Context Action p->balance -= 50;
if (!has_rolled) { p->is_in_jail = false;
// Roll Dice p->jail_turns = 0;
if (!p->is_in_jail) { selected_action = 0;
int dice1 = (rand() % 6) + 1; needs_redraw = true;
int dice2 = (rand() % 6) + 1; return true;
int total = dice1 + dice2; }
int old_pos = p->position; if (active_modal) delete active_modal;
p->position = (p->position + total) % BOARD_SIZE; if (selected_action == (menu_count - 1)) {
if (p->position < old_pos) p->balance += 200; active_modal = new BoardModalGame(width, height, renderer, gui, input_manager, players, players_count);
has_rolled = true; needs_redraw = true;
needs_redraw = true; } else if (!has_rolled) {
// Store dice values and show dice modal roll_dice_logic:
last_dice1 = dice1; int d1 = (rand() % 6) + 1;
last_dice2 = dice2; int d2 = (rand() % 6) + 1;
if (active_modal) delete active_modal; bool is_db = (d1 == d2);
active_modal = new DiceModalGame(width, height, renderer, gui, input_manager, dice1, dice2, &MONOPOLY_BOARD[old_pos], &MONOPOLY_BOARD[p->position], players, players_count); int old_pos = p->position;
// Show property modal if landed on property/railroad/utility if (p->is_in_jail) {
const BoardTile* landed = &MONOPOLY_BOARD[p->position]; if (is_db) {
if (landed->type == TILE_PROPERTY || landed->type == TILE_RAILROAD || landed->type == TILE_UTILITY) { p->is_in_jail = false; p->jail_turns = 0;
modal_property_index = p->position;
}
}
} else { } else {
// End Turn p->jail_turns++;
current_player_idx = (current_player_idx + 1) % players_count; if (p->jail_turns >= 3) {
has_rolled = false; p->balance -= 50; p->is_in_jail = false; p->jail_turns = 0;
double_rolls = 0; } else {
just_sent_to_jail = false; has_rolled = true;
selected_action = 0; // Reset selection for next player last_dice1 = d1; last_dice2 = d2;
needs_redraw = true; active_modal = new DiceModalGame(width, height, renderer, gui, input_manager, d1, d2, &MONOPOLY_BOARD[old_pos], &MONOPOLY_BOARD[old_pos], players, players_count);
needs_redraw = true;
return true;
}
} }
break; } else if (is_db) {
case 1: // View Board double_rolls++;
if (active_modal) delete active_modal; if (double_rolls >= 3) {
active_modal = new BoardModalGame(width, height, renderer, gui, input_manager, players, players_count); p->position = 10; p->is_in_jail = true; p->jail_turns = 0;
needs_redraw = true; has_rolled = true; double_rolls = 0;
break; last_dice1 = d1; last_dice2 = d2;
active_modal = new DiceModalGame(width, height, renderer, gui, input_manager, d1, d2, &MONOPOLY_BOARD[old_pos], &MONOPOLY_BOARD[10], players, players_count);
needs_redraw = true;
return true;
}
} else {
double_rolls = 0;
}
int total = d1 + d2;
p->position = (p->position + total) % BOARD_SIZE;
if (p->position < old_pos) p->balance += 200;
has_rolled = !is_db;
last_dice1 = d1; last_dice2 = d2;
active_modal = new DiceModalGame(width, height, renderer, gui, input_manager, d1, d2, &MONOPOLY_BOARD[old_pos], &MONOPOLY_BOARD[p->position], players, players_count);
const BoardTile* lnd = &MONOPOLY_BOARD[p->position];
if (lnd->type == TILE_GO_TO_JAIL) {
p->position = 10; p->is_in_jail = true; p->jail_turns = 0;
has_rolled = true; double_rolls = 0;
} else if (lnd->type == TILE_PROPERTY || lnd->type == TILE_RAILROAD || lnd->type == TILE_UTILITY) {
modal_property_index = p->position;
} else if (lnd->type == TILE_CHANCE) {
last_drawn_chance_idx = chance_deck[current_chance_idx];
current_chance_idx = (current_chance_idx + 1) % CHANCE_DECK_SIZE;
if (current_chance_idx == 0) shuffle_chance_deck();
} else if (lnd->type == TILE_COMMUNITY_CHEST) {
last_drawn_community_idx = community_deck[current_community_idx];
current_community_idx = (current_community_idx + 1) % COMMUNITY_DECK_SIZE;
if (current_community_idx == 0) shuffle_community_deck();
} else if (lnd->type == TILE_TAX) {
p->balance -= lnd->cost;
}
needs_redraw = true;
} else {
current_player_idx = (current_player_idx + 1) % players_count;
has_rolled = false; double_rolls = 0; just_sent_to_jail = false; selected_action = 0;
needs_redraw = true;
} }
break; break;
default: default: break;
break;
} }
return needs_redraw; return needs_redraw;
} }
@@ -234,33 +477,34 @@ void MonopolyGame::draw() {
// Stats Window in center // Stats Window in center
char buf[128]; char buf[128];
renderer->draw_string_scaled(ix + 5, iy + 5, "Monopoly", 2); renderer->draw_string_scaled(ix + 70, iy + 180, "Monopoly", 3);
int content_y = iy + 25; int content_y = iy + 0;
snprintf(buf, sizeof(buf), "%s", p->name); snprintf(buf, sizeof(buf), "%s", p->name);
renderer->draw_string_scaled(ix + 5, content_y, buf, 3);
content_y += 40;
snprintf(buf, sizeof(buf), "BAL: $%d", p->balance);
renderer->draw_string_scaled(ix + 5, content_y, buf, 2); renderer->draw_string_scaled(ix + 5, content_y, buf, 2);
content_y += 20; content_y += 20;
snprintf(buf, sizeof(buf), "BAL: $%d", p->balance);
renderer->draw_string_scaled(ix + 5, content_y, buf, 1);
content_y += 12;
snprintf(buf, sizeof(buf), "POS: %s", tile->name); snprintf(buf, sizeof(buf), "POS: %s", tile->name);
renderer->draw_string_scaled(ix + 5, content_y, buf, 1); renderer->draw_string_scaled(ix + 5, content_y, buf, 2);
content_y += 15; content_y += 20;
// Draw action menu // Draw action menu
const char* actions[ACTION_COUNT]; const char* actions[3];
int menu_count = 0;
if (!has_rolled) { if (!has_rolled) {
actions[0] = "Roll Dice"; actions[menu_count++] = "Roll Dice";
if (p->is_in_jail) actions[menu_count++] = "Pay $50";
} else { } else {
actions[0] = "End Turn"; actions[menu_count++] = "End Turn";
} }
actions[1] = "View Board"; actions[menu_count++] = "View Board";
for (int i = 0; i < ACTION_COUNT; ++i) { for (int i = 0; i < menu_count; ++i) {
snprintf(buf, sizeof(buf), "%s%s", (i == selected_action) ? "> " : " ", actions[i]); snprintf(buf, sizeof(buf), "%s%s", (i == selected_action) ? "> " : " ", actions[i]);
renderer->draw_string_scaled(ix + 5, content_y, buf, 1); renderer->draw_string_scaled(ix + 5, content_y, buf, 2);
content_y += 12; content_y += 20;
} }
} }
+13 -2
View File
@@ -37,14 +37,25 @@ private:
bool just_sent_to_jail; bool just_sent_to_jail;
// UI selection state // UI selection state
int selected_action; // 0: Context action (Roll or End Turn), 1: View Board int selected_action; // 0: Context action, 1: Pay $50 (Jail), 2: View Board
static constexpr int ACTION_COUNT = 2; int current_action_count = 2;
// Modal games // Modal games
Game* active_modal = nullptr; Game* active_modal = nullptr;
int last_dice1 = 0; int last_dice1 = 0;
int last_dice2 = 0; int last_dice2 = 0;
int modal_property_index = -1; int modal_property_index = -1;
int chance_deck[CHANCE_DECK_SIZE];
int current_chance_idx;
int last_drawn_chance_idx = -1;
int community_deck[COMMUNITY_DECK_SIZE];
int current_community_idx;
int last_drawn_community_idx = -1;
int rent_multiplier = 1;
bool force_utility_10x = false;
void shuffle_chance_deck();
void shuffle_community_deck();
}; };
#endif // MONOPOLY_GAME_H #endif // MONOPOLY_GAME_H
+3 -1
View File
@@ -32,7 +32,9 @@ public:
BASE, BASE,
MONOPOLY_DICE, MONOPOLY_DICE,
MONOPOLY_PROPERTY, MONOPOLY_PROPERTY,
MONOPOLY_BOARD MONOPOLY_BOARD,
MONOPOLY_CHANCE,
MONOPOLY_COMMUNITY_CHEST
}; };
/** /**