Files
basic1/games/monopoly/BoardModalGame.h

77 lines
2.7 KiB
C++

// BoardModalGame.h
#pragma once
#include "../../lib/game.h"
#include "../../display/low_level_render.h"
#include "../../display/low_level_gui.h"
#include "input_manager.h"
#include "monopoly_board.h"
#include "player.h"
#include "MonopolyBoardRenderer.h"
class BoardModalGame : public Game {
bool dismissed;
Player* players;
int players_count;
int observer_idx;
public:
BoardModalGame(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager, Player* p, int count, int current_idx)
: Game(width, height, renderer, gui, input_manager), dismissed(false), players(p), players_count(count), observer_idx(current_idx) {}
void init() override { dismissed = false; }
Type get_type() const override { return Type::MONOPOLY_BOARD; }
bool update(const InputEvent& event) override {
// Any button dismisses the board view
if (event.type == INPUT_BUTTON_0 || event.type == INPUT_BUTTON_1) {
dismissed = true;
return true;
}
return false;
}
void draw() override {
renderer->clear_buffer();
MonopolyBoardRenderer::draw_board_perimeter(renderer, width, height, players, players_count, -1, observer_idx);
// --- Inner UI ---
int cw = width / 7;
int ch = height / 7;
int ix = cw + 5, iy = ch + 5;
int iw = width - 2 * cw - 10, ih = height - 2 * ch - 10;
// Window Background
renderer->draw_filled_rectangle(ix, iy, iw, ih, false, 0);
renderer->draw_rectangle(ix, iy, iw, ih, true, 1);
// Title
renderer->draw_string_scaled(ix + (iw - 144) / 2, iy + 5, "== BOARD ==", 2);
// Stats for current player
Player& curr = players[observer_idx];
int total_wealth = curr.balance;
for (int i = 0; i < curr.property_count; ++i) {
total_wealth += MONOPOLY_BOARD[curr.properties_owned[i]].cost;
}
char wealth_buf[64];
snprintf(wealth_buf, sizeof(wealth_buf), "%s: Bal:$%d Wealth:$%d", curr.name, curr.balance, total_wealth);
renderer->draw_string_scaled(ix + 10, iy + 30, wealth_buf, 1);
// Legend for players
int ly = iy + 45;
for (int i = 0; i < players_count; ++i) {
char buf[128];
snprintf(buf, sizeof(buf), "%c:%s $%d", (players[i].token ? players[i].token[0] : 'P'), players[i].name, players[i].balance);
renderer->draw_string_scaled(ix + 5, ly, buf, 1);
ly += 12;
}
renderer->draw_string_scaled(ix + (iw - 120) / 2, iy + ih - 15, "PRESS B TO EXIT", 1);
}
public:
bool is_dismissed() const { return dismissed; }
};