Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

I have a C++ code about CLI version of Monopoly. I feel that my code has problems and is wrong. Please help me correct it

I have a C++ code about CLI version of Monopoly. I feel that my code has problems and is wrong. Please help me correct it and complete it to suit my project. You can also delete all my code and do it your way to suit my project's requirements! I really need your help! Please help me complete it all. Ton believes in you! Thank you so much! I am at Auctions right now but I do not think I did everything true! I posted the project requirements below the code pictures!

Here are my code:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

here are my project requires: A CLI version of Monopoly. The program should use OO design, and accomplish the following:

  • Moving two players (both human controlled) around the board
  • Buying properties (including utilities and railroads) and charging rent
  • Jail, Income Tax, and Luxury Tax
  • Bankruptcy and property mortgaging

Cards:

  • Level 1 Implement both Chance and Community Chest cards. They can be the real cards from the game or have effects of your choosing.
  • Level 2 Create a new type of Card that can reside in a player inventory and be used at any point during the player turn. Effects are of your choosing.

Houses:

  • Level 1 Allow the player to build houses on each property they own. Cost of houses and increases to rent are specified by the game. At this level, any amount of houses (up to four) can be built on any owned property.
  • Level 2 Follow the real Monopoly house rules. Houses must be evenly distributed between sets of properties. Hotels can be built after maxing out houses on all properties in a set.

Multiplayer:

  • Level 1 Add support for up to six players.

AI:

  • Level 1 Allow players to be controlled by AI. The AI can make decisions randomly.
  • Level 2 Add some intelligence to your AI. The AI should make buying/selling decisions based on some strategy.

Trading:

  • Level 1 Allow players to trade properties. Make sure multiple-for-one trades are possible.

Auctions:

  • Level 1 Implement the property auction rules when a player lands on a space but does not wish to purchase it.

Battle:

  • Level 1 When players land on the same space, implement a simple turn-based battle system. Base player stats on number of houses and properties owned. Winner gets X% of the losers money.
  • Level 2 Allow players to attack owned properties. This should start a simple battle mini-game. Difficulty should be based on the defending players stats, as described in LV1. If the attacker wins, s/he should be allowed to acquire the property for 2x standard cost.
  • Level 3 Allow players to build a new type of structure on squares turrets. Turrets significantly decrease the chance of losing a property to attack.

Doubles:

  • Level 1 Implement the extra turn for rolling doubles and three doubles in a row lands you in jail rules.

Railroad Travel:

  • Level 1 Allow players that land on railroads to travel to any other owned Railroad instead of rolling. If you pass Go, do not collect $200.

Cheats:

  • Level 1 Add in a cheats menu to speed up game-play and enable testing of various functions
\#pragma once \#include \#include \#include "Player.h" \#include "Property. h " \#include "Card.h" \#include Eclass Board \{ public: std: :vector players; std: :vector properties; Board(const std: :vector\& playerNames); void displayBoard() const; void playTurn(Player\& currentPlayer); void startGame(); // Add the equality comparison operator bool operator == (const Board\& other) const; \}; \#include "Board.h" \#include "Player.h" \#include BBoard: :Board(const std: :vector\& playerNames) \{ 1 for (const auto\& playerName : playerNames) \{ ; properties.push_back(Property ("New York Avenue", 300, 30)) properties.push_back(Property ("California Avenue", 250, 25)); properties. push_back(Property ("Florida Avenue", 180, 18)); properties.push_back(Property("Texas Avenue", 200, 20)); // Added Texas Avenue properties.push_back(Property("Illinois Avenue", 350, 35)); // Added Illinois Avenue properties.push_back(Property("Boardwalk", 400, 40)); // Added Boardwalk properties.push_back(Property("Park Place", 350, 35)); // Added Park Place [13 void Board: :displayBoard() const \{ std: :cout "Monopoly Board " for (const auto\& prop : properties) \{ prop.displayInfo(); for (const auto\& player : players) \{ i player.displayInfo(); Gvoid Board::playTurn(Player\& currentPlayer) \{ Card chanceCard("Advance to Go. Collect \$200."); chanceCard applyEffect(); Card communityChestCard("Bank error in your favor. Collect \$75."); communityChestCard .applyEffect(); void Board: :startGame() int maxTurns =100;// Set a maximum number of turns to avoid infinite loop for (int turn =1; turn 0 \&\& choice availableProperties; for (const auto\& prop : board.properties) \{ if (!prop.isowned()) \{ availableProperties.push_back(prop); i if (!prop.isowned()) \{ availableProperties . push_back(prop); \} \} if (!availableProperties.empty()) \{ makeAIDecision(availableProperties); \} ; void Player: :makeAIDecision(const std::vector\& availableProperties) \{ // Simple AI: Make random decisions srand(static_cast(time( (0))); int decision = rand ( \% 2; // 0 : Do nothing, 1: Buy property (if available) if (decision == 1 \&\& ! availableProperties.empty()) \{ int propertyIndex = rand () availableProperties.size( ); properties . push_back(availableProperties [propertyIndex]); money -= availableProperties[propertyIndex].cost; std: :cout name " bought " availableProperties[propertyIndex]. name std:: endl; \} else \{ std: :cout name " decided not to do anything this turn." std:: endl; \} ; Gvoid Player: :intelligentDecision(const std: :vector\& availableProperties) \{ // Evaluate properties and make a decision int maxScore=1; int bestPropertyIndex =1; for (int i=0; i maxScore) \{ maxScore = score; bestPropertyIndex =i; \} \} if (maxScore >0 \&\& bestPropertyIndex !=1 ) \{ properties . push_back(availableProperties[bestPropertyIndex]); money -= availableProperties[bestPropertyIndex].cost; std:: cout name " bought " availableProperties[bestPropertyIndex]. name std: : endl; \} else \{ std: :cout name " decided not to buy any property this turn." std:: endl; \} Player: : calculatePropertyScore(const Property\& property) const \{ // Implement your scoring logic here based on property characteristics // For example, you can consider factors like rent, cost, and number of houses return property.rent * property.numHouses - property.cost; void Player::initiateTrade(Player\& otherPlayer, Property\& offeredProperty, Property\& requestedProperty) \{ std: :cout name " initiates a trade with " otherPlayer.name std:: endl; // Display properties for trade std: :cout name "'s offered property: "; offeredProperty.displayInfo(); std: :cout otherPlayer. name "'s requested property: "; requestedProperty . displayInfo(); // Ask the other player if they accept the trade if (otherPlayer.acceptTrade(offeredProperty, requestedProperty)) \{ // Perform the trade std: :cout "Trade accepted. Properties exchanged." std: : endl; properties . push_back(requestedProperty); otherPlayer. properties . push_back(offeredProperty); // Remove properties from respective players properties.erase(std: :remove(properties.begin(), properties.end(), offeredProperty), properties.end()); otherPlayer . properties . erase ( std: :remove(otherPlayer. properties.begin(), otherPlayer.properties.end(), requestedProperty), otherPlayer . properties . end()); \} else \{ std cout "Trade neiected by " nthenplaven name std * endl] // Ask the player if they accept the trade std: : cout choice; return (choice ==1 ); \} std::string Player::getName() const \{ return name; i // Define the equality comparison operator Gbool Player: :operator==(const Player\& other) const \{ return name == other. name \&\& money == other.money \&\& properties == other.properties \&\& inventory == other.inventory; \} \#pragma once \#include \#include class Property \{ public: std::string name; int cost; int rent; int numHouses; bool owned; Property(std::string n, int c, int r ); void displayInfo() const; void buildHouse(); int getHouseCost() const; int getRentWithHouses() const; bool isowned() const; // Add the equality comparison operator bool operator==(const Property\& other) const; \}; Monopoly \#include "Property.h" Property::Property(std::string n, int c, int r): name( n),cost(c),rent(r), numHouses( ), owned(false) \{\} void Property: : displayInfo() const \{ std: :cout "Property: " name " Cost: " cost " Rent: " rent; if (numHouses >0 ) \{ std: : cout " Houses: " numHouses; \} std: : cout std: : endl; i void Property: :buildHouse() \{ if (numHouses == other. name && cost == other.cost && rent == other. rent \&\& numHouses == other. numHouses \&\& owned == other. owned

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions