1 / 43

MMTS Component-Level Design

MMTS Component-Level Design. <<static>>. GameController. MMTS. BankruptcyException. Entity. Broker. Bank. Space. Pit. PlayerInformation. -List<Space> board -List<Player> players -Player[] bankruptPlayers - boolean rentInJailRule - int roundsEndCount - int bankruptPlayersEndCount.

petra
Download Presentation

MMTS Component-Level Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MMTSComponent-Level Design

  2. <<static>> GameController MMTS BankruptcyException Entity Broker Bank Space Pit PlayerInformation -List<Space> board -List<Player> players -Player[] bankruptPlayers -booleanrentInJailRule -introundsEndCount -intbankruptPlayersEndCount Player -int id -int money -Space position -Card outOfJailChance -Card outOfJailChest -PlayerInformationreportInformation -booleaninJail -Player bankrupt -Player payee -intrentOwed -int money -List<Ownable> properties -void bankrupt(int rent) -void improve() +void updatePosition(Space newPos) +intgetTotalWorth() +void purchase(Property p) +void startTurn() +void rolledDoubles() -void completeGroup() +void unmortgage() +void payIn(int amount) +intpayOut(int amount) +void payIn(int amount) +intpayOut(intamount) +void transaction(Entity Payer, Entity Payee, int Amount) +void payIn(int amount) +intpayOut(int amount) [See Later Slide] +void payIn(int amount) +intpayOut(intamount) [See Later Slide] +void playGame() -void turn(Player p, intdiceValue) -void parseArguments(String[] args) +int main(String[] args) <<Abstract>> Exception

  3. <<Abstract>> Java.util.comparable Property Ownable IncomeTax LuxuryTax CardProxy Space Housable Go FreeParking GoToJail <<note>> Groupable -boolean mortgage -intpurchasePrice -Entity owner -int[] transactionAmount -List<Groupable> groupMemebers -Deck deck -int houses -inthousePrice -String name + void land(Player p) + void land(Player p) + void land(Player p) + void land(Player p) +void land(Player p) +hasHotel() +improve() +int disprove() + void land(Player p) +isMortgaged() +mortgage() +unMortgage() +compareTo() + void land(Player p) + void land(Player p) + void land(Player p) Just Visiting + void land(Player p) +void land(Player p) <<note>> <<note>> Railways, Utilities Normal Properties Deck -cards: List<Card> +void shuffle() +Card draw() +void remove(Card card) +void insert(Card card)

  4. <<Abstract>> GoToJail Card Movement GroupExpense Transaction Income NearestUtility AbsoluteMovement Expense GroupIncome NearestRailroad GetOutOfJail PropertyExpense <<note>> -Space position -Space position -Space position -int amount + use() + use() + use() + use() + use() + use() + use() + use() + use() + use() + use() + use() Pass Go Rules Always Apply +use()

  5. <<singleton>> Report -int boardCounts[] -int propertiesMortgaged -int propertiesUnmortgaged -int rentsCollected[] -PlayerInformation playerInformation[] PlayerInformation -intmostMoneyHeld -inttotalGrossExpenses -introundsCompleted -intsentToJailCount -intchanceDrawnCount -intchestDrawnCount -List<Property> propertiesBought -inthousesBought -inthotelsBought -intdoublesRolled -intgrossTurnIncome -intgrossTurnExpenses -inttotalNetIncome -inttotalNetWorth -inthighestGrossIncomeInTurn -inthighestGrossExpensesInTurn +void updateMostMoneyHeld(int amount) +void updateTotalGrossIncome(int amount) +void updateTotalGrossExpenses(int amount) +void updateRoundsCompleted() +voidupdateSentToJailCount() +void updateChanceDrawnCount() +void updateChestDrawnCount() +void updatePropertiesBought(Property p) +void updateHousesBought() +void updateHotelsBought() +void updateDoublesRolled() +void calculateNetTotals() +void startOfTurn() + void reset() + void generateReport() + void landedOnSquare() + void assessedRent() + void mortgagedProperty() + void unmortgagedProperty() <<singleton>> Dice -int[] dice +int[] getDice() +void roll() +booleanisDoubles()

  6. GameController -List<Space> board -List<Player> players -Player[] bankruptPlayers -booleanrentInJailRule -introundsEndCount -intbankruptPlayersEndCount +GameController(String[] args) Call GameController.parseArguments() to process the command-line arguments passed to the program. +void playGame() For each Player in play order Check for the end of game condition Call Player.startTurn() Roll the dice Call turn(Player) If the Player rolled Doubles Call Player.rolledDoubles() Call turn(Player) If the player rolls doubles 3 times Call Player.updatePosition(JailSpace) Catch a BankruptcyException and: Removes the appropriate Player from Play Order Calls Broker.transaction(payee, amount) to ensure that the payee receives their money Continues with the next player in play order

  7. GameController (continued) -void turn(Player p, intdiceValue) If the player is not in jail Calculate the new position of the player (Player.getPosition() + dice value) If they passed Go (List wrap around) (does not include landed on Go) Call Go.land(Player) Call Player.updatePosition(newPos) Call Space.land(Player) -void parseArguments(String[] args) Parse command-line arguments according to the IDD.

  8. <<static>> Broker +void transaction(Entity payer, Entity payee, int amount) Check that payer and payee are not the same Entity Call payer.payOut(amount) Call payee.payIn(amount)

  9. <<abstract>> Entity -List<Ownable> properties The properties this player owns (initially empty) +void payIn(int amount) +intpayOut(int amount)

  10. Pit -int money The money “in the pit” (intially zero) +Pit(OwnablefreeParking) The pit “owns” Free Parking. +void payIn(int amount) Adds amount to the currently held money. +intpayOut(int amount) Regardless of the amount requested return all the money “in the pit”, setting money to zero.

  11. Bank +void payIn(int amount) Return (do nothing) +intpayOut(intamount) Return the requested amount

  12. Player -int id The id of this player -int money The money this player possesses (cash), (intially 1500) -Space position The space this player is currently on -Card outOfJailChance A card from the Chance Deck -Card outOfJailChest A card from the Community Chest Deck -PlayerInformationreportInformation The report of the player’s activities -booleaninJail Whether the player is in jail or not +Player(intnewID, Position startingPosition) Constructs a new player with the given attributes -void bankrupt(int rent) Throw new BankruptcyException(this, rent) -void improve() +void updatePosition(Space newPos) Set player’s position to newPos +intgetTotalWorth() Returns the total worth of the player as defined in the requirements. +void purchase(Property p) If player has 2.0 times the amount needed Call Broker.transaction(Property.Owner, this, Property.purchasePrice)

  13. Player (continued) +void startTurn() Call Player.completeGroup() Call Player.improve() Call Player.unmortgage() +void completeGroup() If I own all but one of a property group and have 2.0 times the amount of money Purchase the remaining property -void improve() Step through the sorted properties list looking for the first where I own all of the group, and the property is unmortgaged. If I have 2.0 times the amount needed and all of the group Call Property.improve() on the property defined by the sort order +void unmortgage() Choose the first unmortgaged property in the sort order If I have 2.0 times the cash needed Call Property.unmortgage() +void rolledDoubles() Call PlayerReport.updateDoublesRolled() +void payIn(int amount) Add amount to player’s money +intpayOut(int amount) If calculateTotalMoneyAvailable() < amount Throw new BankruptcyException(this, amount) While money < amount Sell houses and/or properties in sort order +intcalculateTotalMoneyAvailable() Return cash on hand plus money gained if every house/hotel was sold and every (unmortgaged) property were sold.

  14. BankruptcyException -Player bankrupt The player that is going bankrupt -Player payee The player that is still owed money -intrentOwed The amount owed

  15. <<abstract>> Space -String name The name of this space +void land(Player p)

  16. Ownable -Entity owner The Entity that owns this -int[] transactionAmount Describes the amount to be paid when another player lands here + Ownable(Owner o, int[] newTransactionAmount) Creates a new Ownable + void land(Player p) Return (do nothing)

  17. Go + void land(Player player) Call Broker.transaction(banker, player, 200)

  18. GoToJail + void land(Player player) Call Player.setInJail(True) Call Player.updatePosition(Jail)

  19. LuxuryTax + void land(Player player) Call Broker.transaction(player, Pit, 75)

  20. FreeParking + void land(Player player) Call Broker.transaction(Pit, Player, 0)

  21. IncomeTax + void land(Player player) If Player.getTotalWorth() < 200 Call Broker.transaction(Player, Pit, 200) Else amount = floor ( Player.getTotalWorth() / 10 ) Call Broker.transaction(Player, Pit, amount)

  22. Property -boolean mortgage Whether this property is mortgaged or not -intpurchasePrice The price to buy this property +Property(String name, int[] transactionAmount, intpurchasePrice) Construct a new Property +void land(Player p) If mortgaged, do nothing and return If owned by bank, call Player.purchase(this) Otherwise, Calculate appropriate rent acording to the requirements Call Broker.transaction(Player, this.owner, rentAmount) +isMortgaged() Return mortgage flag +mortgage() Set mortgage flag to True +unMortgage() Set mortgage flag to False +compareTo(Property other) Compares to the other property as defined in the requirements

  23. Groupable -List<Groupable> groupMemebers A list of other members of this group + Groupable(String name, Entity owner, intpurchasePrice, int[] transactionAmount) Construct a Groupable + void land(Player player) If mortgaged, do nothing and return If owned by Bank, call Player.purchase(this) Otherwise, Calculate appropriate rent according to the requirements Call Broker.transaction(Player, this.owner, rentAmount)

  24. Housable -int houses -inthousePrice +Housable(String name, Entity owner, intpurchasePrice, int[] transactionAmount, inthousePrice) Construct a Housable +void land(Player player) If mortgaged, do nothing and return If owned by Bank, call Player.purchase(this) Otherwise, Calculate appropriate rent according to the requirements Call Broker.transaction(Player, this.owner, rentAmount) +booleanhasHotel() Returns True if the houses attribute equals 5 +void improve() Call Broker.transaction(Player, Bank, houseCost) Increase houses by 1. +int disprove() Call Broker.transaction(Bank, Player, houseCost) Decrease houses by 1.

  25. CardProxy -Deck deck + void land(Player p) card = deck.draw() if (card != get out of jail free){ card.use() } else { deck.remove(card) p.outOfJail{deck} = card }

  26. Deck -List<Card> cards -intpositionInDeck +void shuffle() Randomly shuffle all the cards as specified by RU-17 +Card draw() If (positionInDeck++ > deck.size()) { positionInDeck = 0 } return deck.get(positionInDeck) +void remove(Card card) cards.remove(card) +void insert(Card card) if (positionInDeck > 0) { cards.insert(positionInDeck – 1) } else { cards.insert(cards.size() – 1) }

  27. <<abstract>> Card +void use(Player p)

  28. <<abstract>> Movement + void use(Player p)

  29. AbsoluteMovement -Space position + void use(Player p) Set player p’s position to this.position

  30. AbsoluteMovement -Space position + void use(Player p) Sets player p’s position to nearest utility (traveling forward around the board)

  31. NearestRailroad + void use(Player p) Sets player p’s position to the nearest railroad (traveling forward around the board)

  32. GetOutOfJail -Space position + void use(Player p) Move player p to Just Visiting.

  33. GoToJail -Space position + void use(Player p) Move player p to Jail.

  34. <<abstract>> Transaction -int amount + void use(Player p)

  35. Expense + void use(Player p) Call Broker.transaction(p, Bank, amount)

  36. GroupExpense + void use(Player p) for each player { Call Broker.transaction(Bank, p, amount) }

  37. PropertyExpense + void use(Player p) Call Broker.transaction(Bank, p, cost), where cost = houseCost * p.numHouses + hotelCost * p.numHotels

  38. Income + void use(Player p) Call Broker.transaction(Bank, p, amount)

  39. GroupIncome + void use(Player p) for each player { Call Broker.transaction(Bank, p, amount) }

  40. <<singleton>> Dice -int[] dice +int[] getDice() Return dice +void roll() For each die, set the die to a new random number between 1 and 6, inclusive. +booleanisDoubles() Return dice[0] == dice[1]

  41. <<singleton>> Report -int boardCounts[] -int propertiesMortgaged -int propertiesUnmortgaged -int rentsCollected[] -PlayerInformation playerInformation[] + void reset() Reset all report information to 0 + void generateReport() Call PlayerInformation.calculateNetTotals() for each player Output the report to stdout as specified in Interface Design Description + void landedOnSquare(int index) Increment boardCounts[index] by 1. + void assessedRent(Property p, int amount) Add amount to the correct property index in rentsCollected. + void mortgagedProperty() Increment propertiesMortgaged by 1. + void unmortgagedProperty() Increment propertiesUnmortgaged by 1.

  42. PlayerInformation -intmostMoneyHeld -inttotalGrossIncome -inttotalGrossExpenses -introundsCompleted -intsentToJailCount -intchanceDrawnCount -intchestDrawnCount -List<Property> propertiesBought -inthousesBought -inthotelsBought -intdoublesRolled -intgrossTurnIncome -intgrossTurnExpenses -inttotalNetIncome -inttotalNetWorth -inthighestGrossIncomeInTurn -inthighestGrossExpensesInTurn +void updateMostMoneyHeld(int amount) If amount is > mostMoneyHeld, set mostMoneyHeldas amount. +void updateTotalGrossIncome(int amount) Add amount to totalGrossIncome Add amount to grossTurnIncome +void updateTotalGrossExpenses(int amount) Add amount to totalGrossExpenses Add amount to grossTurnExpenses

  43. PlayerInformation +void updateRoundsCompleted() Increment roundsCompleted by 1. +void updateSentToJailCount() Increment sentToJailCount by 1. +void updateChanceDrawnCount() Increment chanceDrawnCount by 1. +void updateChestDrawnCount() Increment chestDrawnCount by 1. +void updatePropertiesBought(Property p) Add property p to propertiesBought list. +void updateHousesBought() Increment housesBought by 1. +void updateHotelsBought() Increment hotelsBought by 1. +void updateDoublesRolled() Increment doublesRolled by 1. +void calculateNetTotals() Calculate total net income (gross income – gross expenses). Calculate total net worth. +void startOfTurn() If grossTurnIncome > highestGrossIncomeInTurn, update highestGrossIncomeInTurn with grossTurnIncome If grossTurnExpenses > highestGrossExpensesInTurn, update highestGrossExpensesInTurn with grossTurnExpenses Set both grossTurnIncome and grossTurnExpenses to 0

More Related