monopoly board
This commit is contained in:
@@ -5,43 +5,125 @@
|
||||
#include "../../display/low_level_gui.h"
|
||||
#include "input_manager.h"
|
||||
#include "monopoly_board.h"
|
||||
#include "player.h"
|
||||
#include "MonopolyBoardRenderer.h"
|
||||
|
||||
class PropertyModalGame : public Game {
|
||||
const BoardTile* property;
|
||||
bool dismissed;
|
||||
bool is_owned;
|
||||
const char* owner_name;
|
||||
bool can_afford;
|
||||
int selected_choice; // 0: Buy, 1: Cancel
|
||||
bool buy_requested;
|
||||
Player* players;
|
||||
int players_count;
|
||||
|
||||
public:
|
||||
PropertyModalGame(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager, const BoardTile* prop)
|
||||
: Game(width, height, renderer, gui, input_manager), property(prop), dismissed(false) {}
|
||||
void init() override { dismissed = false; }
|
||||
PropertyModalGame(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager, const BoardTile* prop, bool owned, const char* owner, bool affordable, Player* p_list = nullptr, int p_count = 0)
|
||||
: Game(width, height, renderer, gui, input_manager), property(prop), dismissed(false), is_owned(owned), owner_name(owner), can_afford(affordable), selected_choice(0), buy_requested(false), players(p_list), players_count(p_count) {
|
||||
if (is_owned || !can_afford) selected_choice = 1;
|
||||
}
|
||||
void init() override { dismissed = false; buy_requested = false; }
|
||||
bool update(const InputEvent& event) override {
|
||||
if (event.type == INPUT_BUTTON_0 || event.type == INPUT_BUTTON_1) {
|
||||
if (event.type == INPUT_BUTTON_0) { // BUTTON A -> BUY
|
||||
if (!is_owned && can_afford) {
|
||||
buy_requested = true;
|
||||
dismissed = true;
|
||||
return true;
|
||||
} else if (is_owned || !can_afford) {
|
||||
// If it's just the "OK" state, either button works?
|
||||
// Image shows >B CONTINUE in my code, so maybe Button 1.
|
||||
}
|
||||
}
|
||||
if (event.type == INPUT_BUTTON_1) { // BUTTON B -> AUCTION / DISMISS
|
||||
dismissed = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void draw() override {
|
||||
int win_w = 320, win_h = 180;
|
||||
int win_x = (width - win_w) / 2, win_y = (height - win_h) / 2;
|
||||
renderer->clear_buffer();
|
||||
int win_w = 160;
|
||||
int win_h = 160;
|
||||
int win_x = (width - win_w) / 2;
|
||||
int win_y = (height - win_h) / 2;
|
||||
char buf[128];
|
||||
snprintf(buf, sizeof(buf), "Property: %s", property->name);
|
||||
gui->draw_new_window(win_x, win_y, win_w, win_h, buf);
|
||||
int py = win_y + 30;
|
||||
char pbuf[128];
|
||||
if (property->type == TILE_PROPERTY) {
|
||||
snprintf(pbuf, sizeof(pbuf), "Cost: $%d", property->cost);
|
||||
renderer->draw_string_scaled(win_x + 20, py, pbuf, 2);
|
||||
py += 25;
|
||||
snprintf(pbuf, sizeof(pbuf), "Rent: $%d", property->rent[0]);
|
||||
renderer->draw_string_scaled(win_x + 20, py, pbuf, 2);
|
||||
py += 25;
|
||||
snprintf(pbuf, sizeof(pbuf), "House Cost: $%d", property->house_cost);
|
||||
renderer->draw_string_scaled(win_x + 20, py, pbuf, 2);
|
||||
} else if (property->type == TILE_RAILROAD || property->type == TILE_UTILITY) {
|
||||
snprintf(pbuf, sizeof(pbuf), "Cost: $%d", property->cost);
|
||||
renderer->draw_string_scaled(win_x + 20, py, pbuf, 2);
|
||||
|
||||
if (players && players_count > 0) {
|
||||
MonopolyBoardRenderer::draw_board_perimeter(renderer, width, height, players, players_count);
|
||||
}
|
||||
|
||||
// Window background (White box)
|
||||
renderer->draw_filled_rectangle(win_x, win_y, win_w, win_h, false, 0); // Clear background
|
||||
renderer->draw_rectangle(win_x, win_y, win_w, win_h, true, 2);
|
||||
renderer->draw_rectangle(win_x + 3, win_y + 3, win_w - 6, win_h - 6, true, 1);
|
||||
|
||||
// Header Title Bar
|
||||
renderer->draw_filled_rectangle(win_x + 4, win_y + 4, win_w - 8, 30, true, 1);
|
||||
renderer->set_text_color(false); // White text
|
||||
snprintf(buf, sizeof(buf), "%s", property->name);
|
||||
renderer->draw_string_scaled(win_x + (win_w - (int)strlen(buf) * 6) / 2, win_y + 8, buf, 1);
|
||||
renderer->set_text_color(true);
|
||||
|
||||
// Subtitle (Type)
|
||||
const char* type_str = "PROPERTY";
|
||||
if (property->type == TILE_RAILROAD) type_str = "RAILROAD";
|
||||
else if (property->type == TILE_UTILITY) type_str = "UTILITY";
|
||||
snprintf(buf, sizeof(buf), "%s", type_str);
|
||||
renderer->draw_string_scaled(win_x + (win_w - (int)strlen(buf) * 6) / 2, win_y + 40, buf, 1);
|
||||
|
||||
// Info box center
|
||||
int info_y = win_y + 60;
|
||||
// Price
|
||||
snprintf(buf, sizeof(buf), "PRICE: $%d", property->cost);
|
||||
renderer->draw_string_scaled(win_x + 15, info_y, buf, 1);
|
||||
info_y += 15;
|
||||
|
||||
// Rent
|
||||
if (property->type == TILE_PROPERTY) {
|
||||
snprintf(buf, sizeof(buf), "RENT: $%d", property->rent[0]);
|
||||
} else if (property->type == TILE_UTILITY) {
|
||||
snprintf(buf, sizeof(buf), "RENT: 4x DICE");
|
||||
} else if (property->type == TILE_RAILROAD) {
|
||||
snprintf(buf, sizeof(buf), "RENT: $25");
|
||||
}
|
||||
renderer->draw_string_scaled(win_x + 15, info_y, buf, 1);
|
||||
info_y += 15;
|
||||
|
||||
// Owner
|
||||
if (is_owned && owner_name) {
|
||||
snprintf(buf, sizeof(buf), "OWNER: %s", owner_name);
|
||||
} else {
|
||||
snprintf(buf, sizeof(buf), "OWNER: %s", is_owned ? "PLAYER" : "BANK");
|
||||
}
|
||||
renderer->draw_string_scaled(win_x + 15, info_y, buf, 1);
|
||||
|
||||
// Action Buttons
|
||||
int btn_y = win_y + win_h - 60;
|
||||
int btn_w = win_w - 30;
|
||||
int btn_h = 25;
|
||||
|
||||
if (is_owned || !can_afford) {
|
||||
// Only one option: CONTINUE (B)
|
||||
renderer->draw_filled_rectangle(win_x + 15, btn_y, btn_w, btn_h, true, 1);
|
||||
renderer->set_text_color(false);
|
||||
renderer->draw_string_scaled(win_x + 25, btn_y + 8, ">B CONTINUE", 1);
|
||||
renderer->set_text_color(true);
|
||||
} else {
|
||||
// Choice: Buy (A) or Auction (B)
|
||||
// Buy Button
|
||||
renderer->draw_filled_rectangle(win_x + 15, btn_y, btn_w, btn_h, true, 1);
|
||||
renderer->set_text_color(false);
|
||||
snprintf(buf, sizeof(buf), ">A BUY ($%d)", property->cost);
|
||||
renderer->draw_string_scaled(win_x + 20, btn_y + 8, buf, 1);
|
||||
renderer->set_text_color(true);
|
||||
|
||||
btn_y += 30;
|
||||
// Auction Button
|
||||
renderer->draw_string_scaled(win_x + 20, btn_y + 8, ">B AUCTION", 1);
|
||||
}
|
||||
renderer->draw_string_scaled(10, height - 20, "Press any button...", 2);
|
||||
}
|
||||
bool is_dismissed() const { return dismissed; }
|
||||
bool wants_to_buy() const { return buy_requested; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user