3. (00 Design) As part of writing a videogame, you need to define a collection of Rooms. Rooms connect to each other by
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
3. (00 Design) As part of writing a videogame, you need to define a collection of Rooms. Rooms connect to each other by
3. (00 Design) As part of writing a videogame, you need to define a collection of Rooms. Rooms connect to each other by bidirectional doors (you can pass through them either way). Some rooms also have money as a reward that a player could claim upon visiting that room. Here is part of the Room class designed to support this description: class Room( var money: Option [Int]) { var byDoor: ListBuffer (Room] = new ListBuffer() // a mutable list // add a door between this room and another room def connectDoor(to: Room) { this.byDoor.append(to) to.byDoor.append(this) } } Answer the following questions: a. Could the Room class take the door-connections as constructor inputs? Why or why not? b. Later in the design process, your team decides that Rooms should have different kinds of prizes, not just money. You need to generalize the name and type of this field to allow for this. There are two options (class headers) on the table: 1) class Room [T] (var prize: Option [T]) // use a plain generic with no annotations 2) class Room (var prize: IPrize) // use a trait (or interface) (The "generic with no annotations" means you have to use the header as written; e.g., you CANNOT add a constraint like Ordered to the type parameter) Your team is still arguing about what should happen with prizes. Their ideas are: i. Prizes can only get removed from rooms as players pick them up ii. Prizes can get traded as players come through (a player might pick up money but leave behind food) iii. Prizes can transform the player in the room (giving more energy, adding a shield, etc) For each of the two options for class headers, which of these three ideas could it support? You'll indicate your answer in one Canvas question and write your justification in the next question.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!