Files
basic1/games/monopoly/chance.h
2026-01-31 09:45:40 -05:00

56 lines
2.7 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef CHANCE_H
#define CHANCE_H
typedef enum {
CHANCE_ADVANCE, // Move to a specific index or category
CHANCE_EARN, // Add money
CHANCE_SPEND, // Subtract money
CHANCE_SPEND_EACH_PLAYER, // Pay every other player
CHANCE_BACK, // Move back X spaces
CHANCE_JAIL, // Go to jail
CHANCE_JAIL_FREE, // Keep a get out of jail free card
CHANCE_REPAIRS // Pay per house/hotel
} ChanceType;
// Sentinel values for "nearest" targets
#define TARGET_NEAREST_UTILITY -1
#define TARGET_NEAREST_RAILROAD -2
typedef struct {
const char* description;
ChanceType type;
int value; // Used for index, amount, or spaces back
int value2; // Specifically for repairs (Hotel cost)
} ChanceCard;
#define CHANCE_DECK_SIZE 16
static const ChanceCard CHANCE_DECK[CHANCE_DECK_SIZE] = {
{"Advance to Go", CHANCE_ADVANCE, 0, 0},
{"Advance to Illinois Ave", CHANCE_ADVANCE, 24, 0},
{"Advance to nearest Utility. If unowned, buy it. If owned, pay 10x dice.", CHANCE_ADVANCE, TARGET_NEAREST_UTILITY, 0},
{"Advance to nearest Railroad. If unowned, buy it. If owned, pay twice rental.", CHANCE_ADVANCE, TARGET_NEAREST_RAILROAD, 0},
{"Advance to St. Charles Place if you pass Go, collect $200", CHANCE_ADVANCE, 11, 0},
{"Bank pays you dividend of $50", CHANCE_EARN, 50, 0},
{"Get out of Jail free", CHANCE_JAIL_FREE, 0, 0},
{"Go back 3 spaces", CHANCE_BACK, 3, 0},
{"Go directly to Jail", CHANCE_JAIL, 0, 0},
{"Make general repairs - $25 per house, $100 per hotel", CHANCE_REPAIRS, 25, 100},
{"Pay poor tax of $15", CHANCE_SPEND, 15, 0},
{"Take a trip to Reading Railroad", CHANCE_ADVANCE, 5, 0},
{"Take a walk on the Boardwalk", CHANCE_ADVANCE, 39, 0},
{"Elected chairman of the board pay each player $50", CHANCE_SPEND_EACH_PLAYER, 50, 0},
{"Your building loan matures collect $150", CHANCE_EARN, 150, 0},
{"You have won a crossword competition - collect $100", CHANCE_EARN, 100, 0}
};
#endif
/*
Implementation Tips for your main.c:
Handling "Nearest": When you draw a card with TARGET_NEAREST_UTILITY, use a loop starting from the player's current position to find the next index where MONOPOLY_BOARD[i].type == TILE_UTILITY.
The Repair Card: When the type is CHANCE_REPAIRS, you'll need to look at the player's owned properties and count how many houses/hotels they have (once you implement the building logic), then multiply by value (25) and value2 (100).
Shuffling: In C, you can shuffle the deck at the start of the game using a Fisher-Yates shuffle algorithm on an array of indices [0...15].
*/