Fix build error: Rename BOARD_SIZE to MONOPOLY_BOARD_SIZE to avoid macro collision
This commit is contained in:
@@ -1,198 +1,222 @@
|
||||
// DiceModalGame.h
|
||||
#pragma once
|
||||
#include "../../lib/game.h"
|
||||
#include "../../display/low_level_render.h"
|
||||
#include "../../display/low_level_gui.h"
|
||||
#include "input_manager.h"
|
||||
#include "MonopolyBoardRenderer.h"
|
||||
#include "../../display/low_level_render.h"
|
||||
#include "../../lib/game.h"
|
||||
#include "ModalButtonHelper.h"
|
||||
#include <stdlib.h>
|
||||
#include "MonopolyBoardRenderer.h"
|
||||
#include "input_manager.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
class DiceModalGame : public Game {
|
||||
int dice1, dice2;
|
||||
const BoardTile *from_tile, *to_tile;
|
||||
Player* players;
|
||||
int players_count;
|
||||
bool dismissed;
|
||||
int dice1, dice2;
|
||||
const BoardTile *from_tile, *to_tile;
|
||||
Player *players;
|
||||
int players_count;
|
||||
bool dismissed;
|
||||
|
||||
int from_pos;
|
||||
int correct_destination;
|
||||
int options[3];
|
||||
bool option_visible[3];
|
||||
int selected_choice;
|
||||
bool show_error;
|
||||
int from_pos;
|
||||
int correct_destination;
|
||||
int options[3];
|
||||
bool option_visible[3];
|
||||
int selected_choice;
|
||||
bool show_error;
|
||||
|
||||
void draw_die(int x, int y, int size, int value) {
|
||||
// Die base
|
||||
renderer->draw_rounded_rectangle(x, y, size, size, 4, true, false);
|
||||
// Shadow (offset 2,2)
|
||||
renderer->draw_line(x + size, y + 2, x + size, y + size, true);
|
||||
renderer->draw_line(x + 2, y + size, x + size, y + size, true);
|
||||
void draw_die(int x, int y, int size, int value) {
|
||||
// Die base
|
||||
renderer->draw_rounded_rectangle(x, y, size, size, 4, true, false);
|
||||
// Shadow (offset 2,2)
|
||||
renderer->draw_line(x + size, y + 2, x + size, y + size, true);
|
||||
renderer->draw_line(x + 2, y + size, x + size, y + size, true);
|
||||
|
||||
int dot_size = size / 6;
|
||||
int m = size / 2;
|
||||
int l = size / 4;
|
||||
int r = 3 * size / 4;
|
||||
int t = size / 4;
|
||||
int b = 3 * size / 4;
|
||||
int dot_size = size / 6;
|
||||
int m = size / 2;
|
||||
int l = size / 4;
|
||||
int r = 3 * size / 4;
|
||||
int t = size / 4;
|
||||
int b = 3 * size / 4;
|
||||
|
||||
auto draw_dot = [&](int dx, int dy) {
|
||||
renderer->draw_filled_rectangle(x + dx - dot_size / 2, y + dy - dot_size / 2, dot_size, dot_size, true, 1);
|
||||
};
|
||||
auto draw_dot = [&](int dx, int dy) {
|
||||
renderer->draw_filled_rectangle(x + dx - dot_size / 2,
|
||||
y + dy - dot_size / 2, dot_size, dot_size,
|
||||
true, 1);
|
||||
};
|
||||
|
||||
if (value % 2 == 1) draw_dot(m, m); // Center dot for 1, 3, 5
|
||||
if (value > 1) {
|
||||
draw_dot(l, t);
|
||||
draw_dot(r, b);
|
||||
}
|
||||
if (value > 3) {
|
||||
draw_dot(r, t);
|
||||
draw_dot(l, b);
|
||||
}
|
||||
if (value == 6) {
|
||||
draw_dot(l, m);
|
||||
draw_dot(r, m);
|
||||
}
|
||||
if (value % 2 == 1)
|
||||
draw_dot(m, m); // Center dot for 1, 3, 5
|
||||
if (value > 1) {
|
||||
draw_dot(l, t);
|
||||
draw_dot(r, b);
|
||||
}
|
||||
if (value > 3) {
|
||||
draw_dot(r, t);
|
||||
draw_dot(l, b);
|
||||
}
|
||||
if (value == 6) {
|
||||
draw_dot(l, m);
|
||||
draw_dot(r, m);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
DiceModalGame(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager, int d1, int d2, const BoardTile* from, const BoardTile* to, Player* p, int count)
|
||||
: Game(width, height, renderer, gui, input_manager), dice1(d1), dice2(d2), from_tile(from), to_tile(to), players(p), players_count(count), dismissed(false) {
|
||||
|
||||
// Find from_pos
|
||||
from_pos = 0;
|
||||
for(int i=0; i<40; i++) {
|
||||
if(&MONOPOLY_BOARD[i] == from_tile) {
|
||||
from_pos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
correct_destination = (from_pos + dice1 + dice2) % BOARD_SIZE;
|
||||
selected_choice = -1;
|
||||
show_error = false;
|
||||
for(int i=0; i<3; i++) option_visible[i] = true;
|
||||
DiceModalGame(uint16_t width, uint16_t height, LowLevelRenderer *renderer,
|
||||
LowLevelGUI *gui, InputManager *input_manager, int d1, int d2,
|
||||
const BoardTile *from, const BoardTile *to, Player *p,
|
||||
int count)
|
||||
: Game(width, height, renderer, gui, input_manager), dice1(d1), dice2(d2),
|
||||
from_tile(from), to_tile(to), players(p), players_count(count),
|
||||
dismissed(false) {
|
||||
|
||||
// Generate fake options
|
||||
int fake1 = (from_pos + (rand() % 11 + 2)) % BOARD_SIZE;
|
||||
if (fake1 == correct_destination) fake1 = (fake1 + 1) % BOARD_SIZE;
|
||||
|
||||
int fake2 = (from_pos + (rand() % 11 + 2)) % BOARD_SIZE;
|
||||
while (fake2 == correct_destination || fake2 == fake1) {
|
||||
fake2 = (from_pos + (rand() % 11 + 2)) % BOARD_SIZE;
|
||||
}
|
||||
// Find from_pos
|
||||
from_pos = 0;
|
||||
for (int i = 0; i < 40; i++) {
|
||||
if (&MONOPOLY_BOARD[i] == from_tile) {
|
||||
from_pos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
correct_destination = (from_pos + dice1 + dice2) % MONOPOLY_BOARD_SIZE;
|
||||
selected_choice = -1;
|
||||
show_error = false;
|
||||
for (int i = 0; i < 3; i++)
|
||||
option_visible[i] = true;
|
||||
|
||||
int rand_pos = rand() % 3;
|
||||
if (rand_pos == 0) {
|
||||
options[0] = correct_destination;
|
||||
options[1] = fake1;
|
||||
options[2] = fake2;
|
||||
} else if (rand_pos == 1) {
|
||||
options[0] = fake1;
|
||||
options[1] = correct_destination;
|
||||
options[2] = fake2;
|
||||
} else {
|
||||
options[0] = fake1;
|
||||
options[1] = fake2;
|
||||
options[2] = correct_destination;
|
||||
}
|
||||
// Generate fake options
|
||||
int fake1 = (from_pos + (rand() % 11 + 2)) % MONOPOLY_BOARD_SIZE;
|
||||
if (fake1 == correct_destination)
|
||||
fake1 = (fake1 + 1) % MONOPOLY_BOARD_SIZE;
|
||||
|
||||
int fake2 = (from_pos + (rand() % 11 + 2)) % MONOPOLY_BOARD_SIZE;
|
||||
while (fake2 == correct_destination || fake2 == fake1) {
|
||||
fake2 = (from_pos + (rand() % 11 + 2)) % MONOPOLY_BOARD_SIZE;
|
||||
}
|
||||
|
||||
void init() override {
|
||||
dismissed = false;
|
||||
selected_choice = -1;
|
||||
show_error = false;
|
||||
for(int i=0; i<3; i++) option_visible[i] = true;
|
||||
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
|
||||
int rand_pos = rand() % 3;
|
||||
if (rand_pos == 0) {
|
||||
options[0] = correct_destination;
|
||||
options[1] = fake1;
|
||||
options[2] = fake2;
|
||||
} else if (rand_pos == 1) {
|
||||
options[0] = fake1;
|
||||
options[1] = correct_destination;
|
||||
options[2] = fake2;
|
||||
} else {
|
||||
options[0] = fake1;
|
||||
options[1] = fake2;
|
||||
options[2] = correct_destination;
|
||||
}
|
||||
Type get_type() const override { return Type::MONOPOLY_DICE; }
|
||||
}
|
||||
|
||||
bool update(const InputEvent& event) override {
|
||||
if (event.type == INPUT_BUTTON_0) { // Select
|
||||
int start_choice = selected_choice;
|
||||
do {
|
||||
selected_choice = (selected_choice + 1) % 3;
|
||||
} while (!option_visible[selected_choice] && selected_choice != start_choice);
|
||||
|
||||
show_error = false;
|
||||
return true;
|
||||
}
|
||||
void init() override {
|
||||
dismissed = false;
|
||||
selected_choice = -1;
|
||||
show_error = false;
|
||||
for (int i = 0; i < 3; i++)
|
||||
option_visible[i] = true;
|
||||
ModalButtonHelper::set_monopoly_regions(input_manager, width, height);
|
||||
}
|
||||
Type get_type() const override { return Type::MONOPOLY_DICE; }
|
||||
|
||||
if (event.type == INPUT_BUTTON_1) {
|
||||
if (selected_choice == -1 || !option_visible[selected_choice]) return false;
|
||||
bool update(const InputEvent &event) override {
|
||||
if (event.type == INPUT_BUTTON_0) { // Select
|
||||
int start_choice = selected_choice;
|
||||
do {
|
||||
selected_choice = (selected_choice + 1) % 3;
|
||||
} while (!option_visible[selected_choice] &&
|
||||
selected_choice != start_choice);
|
||||
|
||||
if (options[selected_choice] == correct_destination) {
|
||||
dismissed = true;
|
||||
} else {
|
||||
option_visible[selected_choice] = false;
|
||||
show_error = true;
|
||||
selected_choice = -1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
show_error = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.type == INPUT_BUTTON_1) {
|
||||
if (selected_choice == -1 || !option_visible[selected_choice])
|
||||
return false;
|
||||
|
||||
if (options[selected_choice] == correct_destination) {
|
||||
dismissed = true;
|
||||
} else {
|
||||
option_visible[selected_choice] = false;
|
||||
show_error = true;
|
||||
selected_choice = -1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void draw() override {
|
||||
renderer->clear_buffer();
|
||||
|
||||
// Draw the restricted board perimeter
|
||||
MonopolyBoardRenderer::draw_board_perimeter(renderer, width, height, players, players_count, -1, -1, from_pos, (from_pos + 12) % BOARD_SIZE);
|
||||
void draw() override {
|
||||
renderer->clear_buffer();
|
||||
|
||||
// --- Inner UI (Center Area) ---
|
||||
int cw = width / 7;
|
||||
int ch = height / 7;
|
||||
int ix = cw + 2;
|
||||
int iy = ch + 2;
|
||||
int iw = width - 2 * cw - 4;
|
||||
int ih = height - 2 * ch - 4;
|
||||
|
||||
// Window background (White box)
|
||||
renderer->draw_filled_rectangle(ix, iy, iw, ih, false, 0);
|
||||
renderer->draw_rectangle(ix, iy, iw, ih, true, 2);
|
||||
renderer->draw_rectangle(ix + 3, iy + 3, iw - 6, ih - 6, true, 1);
|
||||
|
||||
// Header
|
||||
renderer->draw_filled_rectangle(ix + 4, iy + 4, iw - 8, 30, true, 1);
|
||||
// Draw the restricted board perimeter
|
||||
MonopolyBoardRenderer::draw_board_perimeter(
|
||||
renderer, width, height, players, players_count, -1, -1, from_pos,
|
||||
(from_pos + 12) % MONOPOLY_BOARD_SIZE);
|
||||
|
||||
// --- Inner UI (Center Area) ---
|
||||
int cw = width / 7;
|
||||
int ch = height / 7;
|
||||
int ix = cw + 2;
|
||||
int iy = ch + 2;
|
||||
int iw = width - 2 * cw - 4;
|
||||
int ih = height - 2 * ch - 4;
|
||||
|
||||
// Window background (White box)
|
||||
renderer->draw_filled_rectangle(ix, iy, iw, ih, false, 0);
|
||||
renderer->draw_rectangle(ix, iy, iw, ih, true, 2);
|
||||
renderer->draw_rectangle(ix + 3, iy + 3, iw - 6, ih - 6, true, 1);
|
||||
|
||||
// Header
|
||||
renderer->draw_filled_rectangle(ix + 4, iy + 4, iw - 8, 30, true, 1);
|
||||
renderer->set_text_color(false);
|
||||
renderer->draw_string_scaled(
|
||||
ix + (iw - (int)strlen("DICE CHALLENGE") * 12) / 2, iy + 10,
|
||||
"DICE CHALLENGE", 2);
|
||||
renderer->set_text_color(true);
|
||||
|
||||
// Dice
|
||||
int dice_size = 40;
|
||||
int dice_y = iy + 45;
|
||||
draw_die(ix + 20, dice_y, dice_size, dice1);
|
||||
draw_die(ix + 20 + dice_size + 10, dice_y, dice_size, dice2);
|
||||
|
||||
// --- Prompt ---
|
||||
int prompt_y = dice_y + dice_size + 10;
|
||||
renderer->draw_string_scaled(ix + 20, prompt_y, "WHERE WILL YOU LAND?", 1);
|
||||
|
||||
// --- Options ---
|
||||
int opt_y = prompt_y + 20;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!option_visible[i]) {
|
||||
opt_y += 25;
|
||||
continue;
|
||||
}
|
||||
char opt_buf[64];
|
||||
snprintf(opt_buf, sizeof(opt_buf), "%s %d: %s",
|
||||
(selected_choice == i ? ">" : " "), i + 1,
|
||||
MONOPOLY_BOARD[options[i]].name);
|
||||
|
||||
if (selected_choice == i)
|
||||
renderer->draw_filled_rectangle(ix + 15, opt_y - 2, iw - 30, 22, true,
|
||||
1);
|
||||
if (selected_choice == i)
|
||||
renderer->set_text_color(false);
|
||||
renderer->draw_string_scaled(ix + (iw - (int)strlen("DICE CHALLENGE") * 12) / 2, iy + 10, "DICE CHALLENGE", 2);
|
||||
renderer->set_text_color(true);
|
||||
|
||||
// Dice
|
||||
int dice_size = 40;
|
||||
int dice_y = iy + 45;
|
||||
draw_die(ix + 20, dice_y, dice_size, dice1);
|
||||
draw_die(ix + 20 + dice_size + 10, dice_y, dice_size, dice2);
|
||||
|
||||
// --- Prompt ---
|
||||
int prompt_y = dice_y + dice_size + 10;
|
||||
renderer->draw_string_scaled(ix + 20, prompt_y, "WHERE WILL YOU LAND?", 1);
|
||||
|
||||
// --- Options ---
|
||||
int opt_y = prompt_y + 20;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!option_visible[i]) {
|
||||
opt_y += 25;
|
||||
continue;
|
||||
}
|
||||
char opt_buf[64];
|
||||
snprintf(opt_buf, sizeof(opt_buf), "%s %d: %s", (selected_choice == i ? ">" : " "), i+1, MONOPOLY_BOARD[options[i]].name);
|
||||
|
||||
if (selected_choice == i) renderer->draw_filled_rectangle(ix + 15, opt_y - 2, iw - 30, 22, true, 1);
|
||||
if (selected_choice == i) renderer->set_text_color(false);
|
||||
|
||||
// Truncate name if too long
|
||||
if (strlen(opt_buf) > 30) opt_buf[30] = '\0';
|
||||
renderer->draw_string_scaled(ix + 20, opt_y, opt_buf, 2);
|
||||
renderer->set_text_color(true);
|
||||
opt_y += 25;
|
||||
}
|
||||
|
||||
if (show_error) {
|
||||
renderer->draw_string_scaled(ix + (iw - 10 * 12) / 2, iy + ih - 30, "TRY AGAIN!", 2);
|
||||
}
|
||||
|
||||
ModalButtonHelper::draw_virtual_buttons(renderer, input_manager);
|
||||
// Truncate name if too long
|
||||
if (strlen(opt_buf) > 30)
|
||||
opt_buf[30] = '\0';
|
||||
renderer->draw_string_scaled(ix + 20, opt_y, opt_buf, 2);
|
||||
renderer->set_text_color(true);
|
||||
opt_y += 25;
|
||||
}
|
||||
bool is_dismissed() const { return dismissed; }
|
||||
|
||||
if (show_error) {
|
||||
renderer->draw_string_scaled(ix + (iw - 10 * 12) / 2, iy + ih - 30,
|
||||
"TRY AGAIN!", 2);
|
||||
}
|
||||
|
||||
ModalButtonHelper::draw_virtual_buttons(renderer, input_manager);
|
||||
}
|
||||
bool is_dismissed() const { return dismissed; }
|
||||
};
|
||||
|
||||
@@ -6,154 +6,197 @@
|
||||
|
||||
class MonopolyBoardRenderer {
|
||||
public:
|
||||
static void draw_tile(LowLevelRenderer* renderer, int x, int y, int w, int h, int index, bool is_corner, Player* players, int players_count, int orientation = 0, int currentPlayerPos = -1, int observer_idx = -1) {
|
||||
if (index < 0 || index >= BOARD_SIZE) return;
|
||||
|
||||
// Find owner
|
||||
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] == index) {
|
||||
owner_id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (owner_id != -1) break;
|
||||
}
|
||||
|
||||
bool isInverted = false;
|
||||
if (observer_idx != -1) {
|
||||
isInverted = (owner_id == observer_idx);
|
||||
} else {
|
||||
isInverted = (index == currentPlayerPos);
|
||||
}
|
||||
|
||||
if (isInverted) {
|
||||
renderer->draw_filled_rectangle(x, y, w, h, true, 1);
|
||||
renderer->set_text_color(false); // Black text on white background
|
||||
} else {
|
||||
renderer->draw_rectangle(x, y, w, h, true, 1);
|
||||
}
|
||||
|
||||
const BoardTile& tile = MONOPOLY_BOARD[index];
|
||||
int content_x = x, content_y = y, content_w = w, content_h = h;
|
||||
|
||||
if (!is_corner && tile.type == TILE_PROPERTY) {
|
||||
int bar_size = 10;
|
||||
int bx = x, by = y, bw = w, bh = h;
|
||||
|
||||
if (orientation == 0) { // Bottom row (Bar on top)
|
||||
bh = bar_size;
|
||||
content_y += bar_size; content_h -= bar_size;
|
||||
} else if (orientation == 1) { // Left column (Bar on right)
|
||||
bx = x + w - bar_size; bw = bar_size;
|
||||
content_w -= bar_size;
|
||||
} else if (orientation == 2) { // Top row (Bar on bottom)
|
||||
by = y + h - bar_size; bh = bar_size;
|
||||
content_h -= bar_size;
|
||||
} else if (orientation == 3) { // Right column (Bar on left)
|
||||
bw = bar_size;
|
||||
content_x += bar_size; content_w -= bar_size;
|
||||
}
|
||||
|
||||
if (isInverted) {
|
||||
// Background is white, so bar is black
|
||||
renderer->draw_filled_rectangle(bx, by, bw, bh, false, 0);
|
||||
renderer->set_text_color(true); // White text
|
||||
} else {
|
||||
renderer->draw_filled_rectangle(bx, by, bw, bh, true, 1);
|
||||
renderer->set_text_color(false); // Black text
|
||||
}
|
||||
|
||||
// Group number
|
||||
char gbuf[2] = { (char)('0' + tile.group[0]), '\0' };
|
||||
renderer->draw_string_scaled(bx + (bw - 6) / 2, by + (bh - 8) / 2, gbuf, 1);
|
||||
|
||||
if (isInverted) renderer->set_text_color(false);
|
||||
else renderer->set_text_color(true);
|
||||
}
|
||||
|
||||
char short_name[10] = {0};
|
||||
int s_ptr = 0;
|
||||
bool isCurrentPos = (index == currentPlayerPos && observer_idx != -1);
|
||||
|
||||
if (isCurrentPos) short_name[s_ptr++] = '-';
|
||||
|
||||
// Add * if owned by someone else
|
||||
if (owner_id != -1 && observer_idx != -1 && owner_id != observer_idx) {
|
||||
short_name[s_ptr++] = '*';
|
||||
}
|
||||
|
||||
const char* full_name = tile.name;
|
||||
if (is_corner) {
|
||||
int len = strlen(full_name);
|
||||
if (len > 3) len = 3;
|
||||
for(int i=0; i<len; i++) short_name[s_ptr++] = full_name[i];
|
||||
} else {
|
||||
short_name[s_ptr++] = full_name[0];
|
||||
const char* space = strchr(full_name, ' ');
|
||||
if (space && space[1] != '\0') short_name[s_ptr++] = space[1];
|
||||
}
|
||||
|
||||
if (isCurrentPos) short_name[s_ptr++] = '-';
|
||||
short_name[s_ptr] = '\0';
|
||||
|
||||
for (int i = 0; short_name[i]; i++) if(short_name[i] >= 'a' && short_name[i] <= 'z') short_name[i] -= 32;
|
||||
|
||||
renderer->draw_string_scaled(content_x + (content_w - (int)strlen(short_name) * 6) / 2, content_y + (content_h - 8) / 2, short_name, 1);
|
||||
|
||||
// Draw player markers
|
||||
int p_count = 0;
|
||||
for (int i = 0; i < players_count; ++i) {
|
||||
if (players[i].position == index) {
|
||||
char mark[2] = { (players[i].token ? players[i].token[0] : 'P'), '\0' };
|
||||
renderer->draw_string_scaled(content_x + 2 + (p_count * 8), content_y + 2, mark, 1);
|
||||
p_count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (isInverted) {
|
||||
renderer->set_text_color(true);
|
||||
static void draw_tile(LowLevelRenderer *renderer, int x, int y, int w, int h,
|
||||
int index, bool is_corner, Player *players,
|
||||
int players_count, int orientation = 0,
|
||||
int currentPlayerPos = -1, int observer_idx = -1) {
|
||||
if (index < 0 || index >= MONOPOLY_BOARD_SIZE)
|
||||
return;
|
||||
|
||||
// Find owner
|
||||
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] == index) {
|
||||
owner_id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (owner_id != -1)
|
||||
break;
|
||||
}
|
||||
|
||||
static void draw_board_perimeter(LowLevelRenderer* renderer, int width, int height, Player* players, int players_count, int currentPlayerPos = -1, int observer_idx = -1, int limit_start = -1, int limit_end = -1) {
|
||||
int cw = width / 7; // Corner width
|
||||
int ch = height / 7; // Corner height
|
||||
int rw = (width - 2 * cw) / 9; // Regular tile width
|
||||
int rh = (height - 2 * ch) / 9; // Regular tile height
|
||||
|
||||
auto should_draw = [&](int index) {
|
||||
if (limit_start == -1 || limit_end == -1) return true;
|
||||
if (limit_start <= limit_end) {
|
||||
return index >= limit_start && index <= limit_end;
|
||||
} else {
|
||||
return index >= limit_start || index <= limit_end;
|
||||
}
|
||||
};
|
||||
|
||||
// --- Bottom Row: 0 to 10 (Right to Left) ---
|
||||
if (should_draw(0)) draw_tile(renderer, width - cw, height - ch, cw, ch, 0, true, players, players_count, 0, currentPlayerPos, observer_idx); // GO
|
||||
for (int i = 1; i < 10; ++i) {
|
||||
if (should_draw(i)) draw_tile(renderer, width - cw - i * rw, height - ch, rw, ch, i, false, players, players_count, 0, currentPlayerPos, observer_idx);
|
||||
}
|
||||
if (should_draw(10)) draw_tile(renderer, 0, height - ch, cw, ch, 10, true, players, players_count, 1, currentPlayerPos, observer_idx); // JAIL
|
||||
|
||||
// --- Left Column: 11 to 19 (Bottom to Top) ---
|
||||
for (int i = 11; i < 20; ++i) {
|
||||
if (should_draw(i)) draw_tile(renderer, 0, height - ch - (i - 10) * rh, cw, rh, i, false, players, players_count, 1, currentPlayerPos, observer_idx);
|
||||
}
|
||||
|
||||
// --- Top Row: 20 to 30 (Left to Right) ---
|
||||
if (should_draw(20)) draw_tile(renderer, 0, 0, cw, ch, 20, true, players, players_count, 2, currentPlayerPos, observer_idx); // FREE PARKING
|
||||
for (int i = 21; i < 30; ++i) {
|
||||
if (should_draw(i)) draw_tile(renderer, cw + (i - 21) * rw, 0, rw, ch, i, false, players, players_count, 2, currentPlayerPos, observer_idx);
|
||||
}
|
||||
if (should_draw(30)) draw_tile(renderer, width - cw, 0, cw, ch, 30, true, players, players_count, 3, currentPlayerPos, observer_idx); // GO TO JAIL
|
||||
|
||||
// --- Right Column: 31 to 39 (Top to Bottom) ---
|
||||
for (int i = 31; i < 40; ++i) {
|
||||
if (should_draw(i)) draw_tile(renderer, width - cw, ch + (i - 31) * rh, cw, rh, i, false, players, players_count, 3, currentPlayerPos, observer_idx);
|
||||
}
|
||||
bool isInverted = false;
|
||||
if (observer_idx != -1) {
|
||||
isInverted = (owner_id == observer_idx);
|
||||
} else {
|
||||
isInverted = (index == currentPlayerPos);
|
||||
}
|
||||
|
||||
if (isInverted) {
|
||||
renderer->draw_filled_rectangle(x, y, w, h, true, 1);
|
||||
renderer->set_text_color(false); // Black text on white background
|
||||
} else {
|
||||
renderer->draw_rectangle(x, y, w, h, true, 1);
|
||||
}
|
||||
|
||||
const BoardTile &tile = MONOPOLY_BOARD[index];
|
||||
int content_x = x, content_y = y, content_w = w, content_h = h;
|
||||
|
||||
if (!is_corner && tile.type == TILE_PROPERTY) {
|
||||
int bar_size = 10;
|
||||
int bx = x, by = y, bw = w, bh = h;
|
||||
|
||||
if (orientation == 0) { // Bottom row (Bar on top)
|
||||
bh = bar_size;
|
||||
content_y += bar_size;
|
||||
content_h -= bar_size;
|
||||
} else if (orientation == 1) { // Left column (Bar on right)
|
||||
bx = x + w - bar_size;
|
||||
bw = bar_size;
|
||||
content_w -= bar_size;
|
||||
} else if (orientation == 2) { // Top row (Bar on bottom)
|
||||
by = y + h - bar_size;
|
||||
bh = bar_size;
|
||||
content_h -= bar_size;
|
||||
} else if (orientation == 3) { // Right column (Bar on left)
|
||||
bw = bar_size;
|
||||
content_x += bar_size;
|
||||
content_w -= bar_size;
|
||||
}
|
||||
|
||||
if (isInverted) {
|
||||
// Background is white, so bar is black
|
||||
renderer->draw_filled_rectangle(bx, by, bw, bh, false, 0);
|
||||
renderer->set_text_color(true); // White text
|
||||
} else {
|
||||
renderer->draw_filled_rectangle(bx, by, bw, bh, true, 1);
|
||||
renderer->set_text_color(false); // Black text
|
||||
}
|
||||
|
||||
// Group number
|
||||
char gbuf[2] = {(char)('0' + tile.group[0]), '\0'};
|
||||
renderer->draw_string_scaled(bx + (bw - 6) / 2, by + (bh - 8) / 2, gbuf,
|
||||
1);
|
||||
|
||||
if (isInverted)
|
||||
renderer->set_text_color(false);
|
||||
else
|
||||
renderer->set_text_color(true);
|
||||
}
|
||||
|
||||
char short_name[10] = {0};
|
||||
int s_ptr = 0;
|
||||
bool isCurrentPos = (index == currentPlayerPos && observer_idx != -1);
|
||||
|
||||
if (isCurrentPos)
|
||||
short_name[s_ptr++] = '-';
|
||||
|
||||
// Add * if owned by someone else
|
||||
if (owner_id != -1 && observer_idx != -1 && owner_id != observer_idx) {
|
||||
short_name[s_ptr++] = '*';
|
||||
}
|
||||
|
||||
const char *full_name = tile.name;
|
||||
if (is_corner) {
|
||||
int len = strlen(full_name);
|
||||
if (len > 3)
|
||||
len = 3;
|
||||
for (int i = 0; i < len; i++)
|
||||
short_name[s_ptr++] = full_name[i];
|
||||
} else {
|
||||
short_name[s_ptr++] = full_name[0];
|
||||
const char *space = strchr(full_name, ' ');
|
||||
if (space && space[1] != '\0')
|
||||
short_name[s_ptr++] = space[1];
|
||||
}
|
||||
|
||||
if (isCurrentPos)
|
||||
short_name[s_ptr++] = '-';
|
||||
short_name[s_ptr] = '\0';
|
||||
|
||||
for (int i = 0; short_name[i]; i++)
|
||||
if (short_name[i] >= 'a' && short_name[i] <= 'z')
|
||||
short_name[i] -= 32;
|
||||
|
||||
renderer->draw_string_scaled(
|
||||
content_x + (content_w - (int)strlen(short_name) * 6) / 2,
|
||||
content_y + (content_h - 8) / 2, short_name, 1);
|
||||
|
||||
// Draw player markers
|
||||
int p_count = 0;
|
||||
for (int i = 0; i < players_count; ++i) {
|
||||
if (players[i].position == index) {
|
||||
char mark[2] = {(players[i].token ? players[i].token[0] : 'P'), '\0'};
|
||||
renderer->draw_string_scaled(content_x + 2 + (p_count * 8),
|
||||
content_y + 2, mark, 1);
|
||||
p_count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (isInverted) {
|
||||
renderer->set_text_color(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_board_perimeter(LowLevelRenderer *renderer, int width,
|
||||
int height, Player *players,
|
||||
int players_count, int currentPlayerPos = -1,
|
||||
int observer_idx = -1, int limit_start = -1,
|
||||
int limit_end = -1) {
|
||||
int cw = width / 7; // Corner width
|
||||
int ch = height / 7; // Corner height
|
||||
int rw = (width - 2 * cw) / 9; // Regular tile width
|
||||
int rh = (height - 2 * ch) / 9; // Regular tile height
|
||||
|
||||
auto should_draw = [&](int index) {
|
||||
if (limit_start == -1 || limit_end == -1)
|
||||
return true;
|
||||
if (limit_start <= limit_end) {
|
||||
return index >= limit_start && index <= limit_end;
|
||||
} else {
|
||||
return index >= limit_start || index <= limit_end;
|
||||
}
|
||||
};
|
||||
|
||||
// --- Bottom Row: 0 to 10 (Right to Left) ---
|
||||
if (should_draw(0))
|
||||
draw_tile(renderer, width - cw, height - ch, cw, ch, 0, true, players,
|
||||
players_count, 0, currentPlayerPos, observer_idx); // GO
|
||||
for (int i = 1; i < 10; ++i) {
|
||||
if (should_draw(i))
|
||||
draw_tile(renderer, width - cw - i * rw, height - ch, rw, ch, i, false,
|
||||
players, players_count, 0, currentPlayerPos, observer_idx);
|
||||
}
|
||||
if (should_draw(10))
|
||||
draw_tile(renderer, 0, height - ch, cw, ch, 10, true, players,
|
||||
players_count, 1, currentPlayerPos, observer_idx); // JAIL
|
||||
|
||||
// --- Left Column: 11 to 19 (Bottom to Top) ---
|
||||
for (int i = 11; i < 20; ++i) {
|
||||
if (should_draw(i))
|
||||
draw_tile(renderer, 0, height - ch - (i - 10) * rh, cw, rh, i, false,
|
||||
players, players_count, 1, currentPlayerPos, observer_idx);
|
||||
}
|
||||
|
||||
// --- Top Row: 20 to 30 (Left to Right) ---
|
||||
if (should_draw(20))
|
||||
draw_tile(renderer, 0, 0, cw, ch, 20, true, players, players_count, 2,
|
||||
currentPlayerPos, observer_idx); // FREE PARKING
|
||||
for (int i = 21; i < 30; ++i) {
|
||||
if (should_draw(i))
|
||||
draw_tile(renderer, cw + (i - 21) * rw, 0, rw, ch, i, false, players,
|
||||
players_count, 2, currentPlayerPos, observer_idx);
|
||||
}
|
||||
if (should_draw(30))
|
||||
draw_tile(renderer, width - cw, 0, cw, ch, 30, true, players,
|
||||
players_count, 3, currentPlayerPos, observer_idx); // GO TO JAIL
|
||||
|
||||
// --- Right Column: 31 to 39 (Top to Bottom) ---
|
||||
for (int i = 31; i < 40; ++i) {
|
||||
if (should_draw(i))
|
||||
draw_tile(renderer, width - cw, ch + (i - 31) * rh, cw, rh, i, false,
|
||||
players, players_count, 3, currentPlayerPos, observer_idx);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,72 +5,232 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum {
|
||||
TILE_GO,
|
||||
TILE_PROPERTY,
|
||||
TILE_COMMUNITY_CHEST,
|
||||
TILE_TAX,
|
||||
TILE_RAILROAD,
|
||||
TILE_CHANCE,
|
||||
TILE_JAIL,
|
||||
TILE_UTILITY,
|
||||
TILE_FREE_PARKING,
|
||||
TILE_GO_TO_JAIL
|
||||
TILE_GO,
|
||||
TILE_PROPERTY,
|
||||
TILE_COMMUNITY_CHEST,
|
||||
TILE_TAX,
|
||||
TILE_RAILROAD,
|
||||
TILE_CHANCE,
|
||||
TILE_JAIL,
|
||||
TILE_UTILITY,
|
||||
TILE_FREE_PARKING,
|
||||
TILE_GO_TO_JAIL
|
||||
} TileType;
|
||||
|
||||
typedef struct {
|
||||
const char* name;
|
||||
TileType type;
|
||||
bool is_corner;
|
||||
int cost; // 0 if not applicable
|
||||
const char* color; // Hex string, NULL if not property
|
||||
int rent[6]; // Base, 1H, 2H, 3H, 4H, Hotel
|
||||
int group[3]; // Group ID, Position in group, Total in group
|
||||
int house_cost; // Cost to build
|
||||
const char *name;
|
||||
TileType type;
|
||||
bool is_corner;
|
||||
int cost; // 0 if not applicable
|
||||
const char *color; // Hex string, NULL if not property
|
||||
int rent[6]; // Base, 1H, 2H, 3H, 4H, Hotel
|
||||
int group[3]; // Group ID, Position in group, Total in group
|
||||
int house_cost; // Cost to build
|
||||
} BoardTile;
|
||||
|
||||
#define BOARD_SIZE 40
|
||||
#define MONOPOLY_BOARD_SIZE 40
|
||||
|
||||
static const BoardTile MONOPOLY_BOARD[BOARD_SIZE] = {
|
||||
static const BoardTile MONOPOLY_BOARD[MONOPOLY_BOARD_SIZE] = {
|
||||
{"Go", TILE_GO, true, 0, NULL, {0}, {0}, 0},
|
||||
{"Mediterranean Avenue", TILE_PROPERTY, false, 60, "#955438", {2, 10, 30, 90, 160, 250}, {1, 1, 2}, 50},
|
||||
{"Mediterranean Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
60,
|
||||
"#955438",
|
||||
{2, 10, 30, 90, 160, 250},
|
||||
{1, 1, 2},
|
||||
50},
|
||||
{"Community Chest", TILE_COMMUNITY_CHEST, false, 0, NULL, {0}, {0}, 0},
|
||||
{"Baltic Avenue", TILE_PROPERTY, false, 60, "#955438", {4, 20, 60, 180, 320, 450}, {1, 2, 2}, 50},
|
||||
{"Baltic Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
60,
|
||||
"#955438",
|
||||
{4, 20, 60, 180, 320, 450},
|
||||
{1, 2, 2},
|
||||
50},
|
||||
{"Income Tax", TILE_TAX, false, 200, NULL, {0}, {0}, 0},
|
||||
{"Reading Railroad", TILE_RAILROAD, false, 200, NULL, {0}, {9, 1, 4}, 0},
|
||||
{"Rhode Island Avenue", TILE_PROPERTY, false, 100, "#aae0fa", {6, 30, 90, 270, 400, 550}, {2, 1, 3}, 50},
|
||||
{"Rhode Island Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
100,
|
||||
"#aae0fa",
|
||||
{6, 30, 90, 270, 400, 550},
|
||||
{2, 1, 3},
|
||||
50},
|
||||
{"Chance", TILE_CHANCE, false, 0, NULL, {0}, {0}, 0},
|
||||
{"Vermont Avenue", TILE_PROPERTY, false, 100, "#aae0fa", {6, 30, 90, 270, 400, 550}, {2, 2, 3}, 50},
|
||||
{"Connecticut Avenue", TILE_PROPERTY, false, 120, "#aae0fa", {8, 40, 100, 300, 450, 600}, {2, 3, 3}, 50},
|
||||
{"Vermont Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
100,
|
||||
"#aae0fa",
|
||||
{6, 30, 90, 270, 400, 550},
|
||||
{2, 2, 3},
|
||||
50},
|
||||
{"Connecticut Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
120,
|
||||
"#aae0fa",
|
||||
{8, 40, 100, 300, 450, 600},
|
||||
{2, 3, 3},
|
||||
50},
|
||||
{"Jail", TILE_JAIL, true, 0, NULL, {0}, {0}, 0},
|
||||
{"St. Charles Place", TILE_PROPERTY, false, 140, "#d93a96", {10, 50, 150, 450, 625, 750}, {3, 1, 3}, 100},
|
||||
{"St. Charles Place",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
140,
|
||||
"#d93a96",
|
||||
{10, 50, 150, 450, 625, 750},
|
||||
{3, 1, 3},
|
||||
100},
|
||||
{"Electric Company", TILE_UTILITY, false, 150, NULL, {0}, {10, 1, 2}, 0},
|
||||
{"States Avenue", TILE_PROPERTY, false, 140, "#d93a96", {10, 50, 150, 450, 625, 750}, {3, 2, 3}, 100},
|
||||
{"Virginia Avenue", TILE_PROPERTY, false, 160, "#d93a96", {12, 60, 180, 500, 700, 900}, {3, 3, 3}, 100},
|
||||
{"Pennsylvania Railroad", TILE_RAILROAD, false, 200, NULL, {0}, {9, 2, 4}, 0},
|
||||
{"St. James Place", TILE_PROPERTY, false, 180, "#f7941d", {14, 70, 200, 550, 750, 950}, {4, 1, 3}, 100},
|
||||
{"States Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
140,
|
||||
"#d93a96",
|
||||
{10, 50, 150, 450, 625, 750},
|
||||
{3, 2, 3},
|
||||
100},
|
||||
{"Virginia Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
160,
|
||||
"#d93a96",
|
||||
{12, 60, 180, 500, 700, 900},
|
||||
{3, 3, 3},
|
||||
100},
|
||||
{"Pennsylvania Railroad",
|
||||
TILE_RAILROAD,
|
||||
false,
|
||||
200,
|
||||
NULL,
|
||||
{0},
|
||||
{9, 2, 4},
|
||||
0},
|
||||
{"St. James Place",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
180,
|
||||
"#f7941d",
|
||||
{14, 70, 200, 550, 750, 950},
|
||||
{4, 1, 3},
|
||||
100},
|
||||
{"Community Chest", TILE_COMMUNITY_CHEST, false, 0, NULL, {0}, {0}, 0},
|
||||
{"Tennessee Avenue", TILE_PROPERTY, false, 180, "#f7941d", {14, 70, 200, 550, 750, 950}, {4, 2, 3}, 100},
|
||||
{"New York Avenue", TILE_PROPERTY, false, 200, "#f7941d", {16, 80, 220, 600, 800, 1000}, {4, 3, 3}, 100},
|
||||
{"Tennessee Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
180,
|
||||
"#f7941d",
|
||||
{14, 70, 200, 550, 750, 950},
|
||||
{4, 2, 3},
|
||||
100},
|
||||
{"New York Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
200,
|
||||
"#f7941d",
|
||||
{16, 80, 220, 600, 800, 1000},
|
||||
{4, 3, 3},
|
||||
100},
|
||||
{"Free Parking", TILE_FREE_PARKING, true, 0, NULL, {0}, {0}, 0},
|
||||
{"Kentucky Avenue", TILE_PROPERTY, false, 220, "#ed1b24", {18, 90, 250, 700, 875, 1050}, {5, 1, 3}, 150},
|
||||
{"Kentucky Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
220,
|
||||
"#ed1b24",
|
||||
{18, 90, 250, 700, 875, 1050},
|
||||
{5, 1, 3},
|
||||
150},
|
||||
{"Chance", TILE_CHANCE, false, 0, NULL, {0}, {0}, 0},
|
||||
{"Indiana Avenue", TILE_PROPERTY, false, 220, "#ed1b24", {18, 90, 250, 700, 875, 1050}, {5, 2, 3}, 150},
|
||||
{"Illinois Avenue", TILE_PROPERTY, false, 240, "#ed1b24", {20, 100, 300, 750, 925, 1100}, {5, 3, 3}, 150},
|
||||
{"Indiana Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
220,
|
||||
"#ed1b24",
|
||||
{18, 90, 250, 700, 875, 1050},
|
||||
{5, 2, 3},
|
||||
150},
|
||||
{"Illinois Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
240,
|
||||
"#ed1b24",
|
||||
{20, 100, 300, 750, 925, 1100},
|
||||
{5, 3, 3},
|
||||
150},
|
||||
{"B. & O. Railroad", TILE_RAILROAD, false, 200, NULL, {0}, {9, 3, 4}, 0},
|
||||
{"Atlantic Avenue", TILE_PROPERTY, false, 260, "#fef200", {22, 110, 330, 800, 975, 1150}, {6, 1, 3}, 150},
|
||||
{"Ventnor Avenue", TILE_PROPERTY, false, 260, "#fef200", {22, 110, 330, 800, 975, 1150}, {6, 2, 3}, 150},
|
||||
{"Atlantic Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
260,
|
||||
"#fef200",
|
||||
{22, 110, 330, 800, 975, 1150},
|
||||
{6, 1, 3},
|
||||
150},
|
||||
{"Ventnor Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
260,
|
||||
"#fef200",
|
||||
{22, 110, 330, 800, 975, 1150},
|
||||
{6, 2, 3},
|
||||
150},
|
||||
{"Water Works", TILE_UTILITY, false, 150, NULL, {0}, {10, 2, 2}, 0},
|
||||
{"Marvin Gardens", TILE_PROPERTY, false, 280, "#fef200", {24, 120, 360, 850, 1025, 1200}, {6, 3, 3}, 150},
|
||||
{"Marvin Gardens",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
280,
|
||||
"#fef200",
|
||||
{24, 120, 360, 850, 1025, 1200},
|
||||
{6, 3, 3},
|
||||
150},
|
||||
{"Go To Jail", TILE_GO_TO_JAIL, true, 0, NULL, {0}, {0}, 0},
|
||||
{"Pacific Avenue", TILE_PROPERTY, false, 300, "#1fb25a", {26, 130, 390, 900, 1100, 1275}, {7, 1, 3}, 200},
|
||||
{"North Carolina Avenue", TILE_PROPERTY, false, 300, "#1fb25a", {26, 130, 390, 900, 1100, 1275}, {7, 2, 3}, 200},
|
||||
{"Pacific Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
300,
|
||||
"#1fb25a",
|
||||
{26, 130, 390, 900, 1100, 1275},
|
||||
{7, 1, 3},
|
||||
200},
|
||||
{"North Carolina Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
300,
|
||||
"#1fb25a",
|
||||
{26, 130, 390, 900, 1100, 1275},
|
||||
{7, 2, 3},
|
||||
200},
|
||||
{"Community Chest", TILE_COMMUNITY_CHEST, false, 0, NULL, {0}, {0}, 0},
|
||||
{"Pennsylvania Avenue", TILE_PROPERTY, false, 320, "#1fb25a", {28, 150, 450, 1000, 1200, 1400}, {7, 3, 3}, 200},
|
||||
{"Pennsylvania Avenue",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
320,
|
||||
"#1fb25a",
|
||||
{28, 150, 450, 1000, 1200, 1400},
|
||||
{7, 3, 3},
|
||||
200},
|
||||
{"Short Line", TILE_RAILROAD, false, 200, NULL, {0}, {9, 4, 4}, 0},
|
||||
{"Chance", TILE_CHANCE, false, 0, NULL, {0}, {0}, 0},
|
||||
{"Park Place", TILE_PROPERTY, false, 350, "#0072bb", {35, 175, 500, 1100, 1300, 1500}, {8, 1, 2}, 200},
|
||||
{"Park Place",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
350,
|
||||
"#0072bb",
|
||||
{35, 175, 500, 1100, 1300, 1500},
|
||||
{8, 1, 2},
|
||||
200},
|
||||
{"Luxury Tax", TILE_TAX, false, 100, NULL, {0}, {0}, 0},
|
||||
{"Boardwalk", TILE_PROPERTY, false, 400, "#0072bb", {50, 200, 600, 1400, 1700, 2000}, {8, 2, 2}, 200}
|
||||
};
|
||||
{"Boardwalk",
|
||||
TILE_PROPERTY,
|
||||
false,
|
||||
400,
|
||||
"#0072bb",
|
||||
{50, 200, 600, 1400, 1700, 2000},
|
||||
{8, 2, 2},
|
||||
200}};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user