interpreting monopoly as multi scree game

This commit is contained in:
Adolfo Reyna
2026-01-31 19:05:58 -05:00
parent 2165186b6b
commit 561f7c5951
7 changed files with 138 additions and 221 deletions

View File

@@ -11,8 +11,14 @@ extern "C" {
#ifdef __cplusplus
}
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "DiceModalGame.h"
#include "PropertyModalGame.h"
// --- Constructor ---
@@ -36,6 +42,8 @@ void MonopolyGame::init() {
double_rolls = 0;
just_sent_to_jail = false;
selected_action = 0;
srand(time(NULL));
if (active_modal) { delete active_modal; active_modal = nullptr; }
// TODO: Reset all board state, property ownership, etc.
}
@@ -44,11 +52,17 @@ bool MonopolyGame::update(const InputEvent& event) {
Player* p = &players[current_player_idx];
bool needs_redraw = false;
// If modal is open, any button closes it
if (show_property_modal) {
if (event.type == INPUT_BUTTON_0 || event.type == INPUT_BUTTON_1) {
show_property_modal = false;
modal_property_index = -1;
// If a modal is active, delegate input and check for dismissal
if (active_modal) {
bool modal_redraw = active_modal->update(event);
if (modal_redraw) needs_redraw = true;
// If modal is dismissed, delete and return control
// Use dynamic_cast to check for modal type and dismissal
auto dice_modal = dynamic_cast<DiceModalGame*>(active_modal);
auto prop_modal = dynamic_cast<PropertyModalGame*>(active_modal);
if ((dice_modal && dice_modal->is_dismissed()) || (prop_modal && prop_modal->is_dismissed())) {
delete active_modal;
active_modal = nullptr;
needs_redraw = true;
}
return needs_redraw;
@@ -71,11 +85,16 @@ bool MonopolyGame::update(const InputEvent& event) {
if (p->position < old_pos) p->balance += 200;
has_rolled = true;
needs_redraw = true;
// Store dice values and show dice modal
last_dice1 = dice1;
last_dice2 = dice2;
if (active_modal) delete active_modal;
active_modal = new DiceModalGame(width, height, renderer, gui, input_manager, dice1, dice2);
// Show property modal if landed on property/railroad/utility
const BoardTile* landed = &MONOPOLY_BOARD[p->position];
if (landed->type == TILE_PROPERTY || landed->type == TILE_RAILROAD || landed->type == TILE_UTILITY) {
show_property_modal = true;
modal_property_index = p->position;
// Queue property modal after dice modal is dismissed
}
// TODO: Handle doubles, jail, landing effects
}
@@ -111,27 +130,42 @@ bool MonopolyGame::update(const InputEvent& event) {
default:
break;
}
// If dice modal was just dismissed and a property modal is queued, show it
if (!active_modal && modal_property_index >= 0) {
active_modal = new PropertyModalGame(width, height, renderer, gui, input_manager, &MONOPOLY_BOARD[modal_property_index]);
modal_property_index = -1;
needs_redraw = true;
}
return needs_redraw;
}
// --- Draw game state (minimal: player info, current tile, actions) ---
void MonopolyGame::draw() {
// If a modal is active, draw it and return
if (active_modal) {
active_modal->draw();
return;
}
Player* p = &players[current_player_idx];
const BoardTile* tile = &MONOPOLY_BOARD[p->position];
// Title
renderer->draw_string_scaled(10, 10, "Monopoly (Minimal)", 2);
renderer->draw_string_scaled(10, 10, "Monopoly", 3);
// --- Player Stats (Right Side) ---
int stats_x = width - 180;
int y = 20;
int stats_x = width - 200;
int y = 40 + 15 * current_player_idx;
char buf[128];
// Name (Big)
renderer->draw_string_scaled(stats_x, y, p->name, 2);
y += 40;
// make a window showing player stats
LowLevelWindow* stats_win = gui->draw_new_window(stats_x - 10, y - 10 , 190, 120, p->name);
y += 20;
renderer->draw_string_scaled(stats_x, y, "Location:", 1);
renderer->draw_string_scaled(stats_x, y + 10, tile->name, 2);
y += 30;
// Money
snprintf(buf, sizeof(buf), "$%d", p->balance);
renderer->draw_string_scaled(stats_x, y, buf, 2);
renderer->draw_string_scaled(stats_x, y, "Money:", 1);
renderer->draw_string_scaled(stats_x, y + 10, buf, 2);
y += 30;
// Properties
int prop_count = 0;
@@ -140,8 +174,8 @@ void MonopolyGame::draw() {
if (prop_idx >= 0 && MONOPOLY_BOARD[prop_idx].type == TILE_PROPERTY) prop_count++;
}
snprintf(buf, sizeof(buf), "Properties: %d", prop_count);
renderer->draw_string_scaled(stats_x, y, buf, 2);
y += 30;
renderer->draw_string_scaled(stats_x, y, buf, 1);
y += 10;
// Monopoly count
int monopoly_count = 0;
// For each group, check if player owns all properties in group
@@ -158,49 +192,7 @@ void MonopolyGame::draw() {
if (group_total > 0 && group_total == group_owned) monopoly_count++;
}
snprintf(buf, sizeof(buf), "Monopolies: %d", monopoly_count);
renderer->draw_string_scaled(stats_x, y, buf, 2);
// --- Main Info (Left Side) ---
snprintf(buf, sizeof(buf), "Player: %s ($%d)", p->name, p->balance);
renderer->draw_string_scaled(10, 30, buf, 2);
snprintf(buf, sizeof(buf), "Location: %s", tile->name);
renderer->draw_string_scaled(10, 50, buf, 2);
// Show property modal window if needed
if (show_property_modal && modal_property_index >= 0) {
const BoardTile* mprop = &MONOPOLY_BOARD[modal_property_index];
int win_w = 320, win_h = 180;
int win_x = (width - win_w) / 2, win_y = (height - win_h) / 2;
LowLevelWindow* win = gui->draw_new_window(win_x, win_y, win_w, win_h, "Property Info");
// gui->current_font = renderer->get_current_font();
int py = win_y + 30;
char pbuf[128];
if (mprop->type == TILE_PROPERTY) {
snprintf(pbuf, sizeof(pbuf), "%s", mprop->name);
renderer->draw_string_scaled(win_x + 20, py, pbuf, 2);
py += 30;
snprintf(pbuf, sizeof(pbuf), "Color: %s", mprop->color ? mprop->color : "-");
renderer->draw_string_scaled(win_x + 20, py, pbuf, 2);
py += 25;
snprintf(pbuf, sizeof(pbuf), "Cost: $%d", mprop->cost);
renderer->draw_string_scaled(win_x + 20, py, pbuf, 2);
py += 25;
snprintf(pbuf, sizeof(pbuf), "Rent: $%d", mprop->rent[0]);
renderer->draw_string_scaled(win_x + 20, py, pbuf, 2);
py += 25;
snprintf(pbuf, sizeof(pbuf), "House Cost: $%d", mprop->house_cost);
renderer->draw_string_scaled(win_x + 20, py, pbuf, 2);
} else if (mprop->type == TILE_RAILROAD || mprop->type == TILE_UTILITY) {
snprintf(pbuf, sizeof(pbuf), "%s", mprop->name);
renderer->draw_string_scaled(win_x + 20, py, pbuf, 2);
py += 30;
snprintf(pbuf, sizeof(pbuf), "Cost: $%d", mprop->cost);
renderer->draw_string_scaled(win_x + 20, py, pbuf, 2);
}
renderer->draw_string_scaled(win_x + 20, win_y + win_h - 40, "Press any button...", 2);
return;
}
renderer->draw_string_scaled(stats_x, y, buf, 1);
// Draw action menu (highlight selected)
const char* actions[ACTION_COUNT] = {"Roll Dice", "Buy Property", "End Turn"};
@@ -210,8 +202,6 @@ void MonopolyGame::draw() {
renderer->draw_string_scaled(10, y, buf, 2);
}
// renderer->draw_string_scaled(10, height - 20, "BTN0: Next Option BTN1: Select", 2);
// TODO: Draw board, all players, property ownership, jail, chance, etc.
// TODO: Add win/lose/game over conditions
// TODO: Add touch support, more UI, etc.