Question All codes in c# Iteration 2 - Players, Items, and Inventory The goal of this iteration will be to create the Player, Item, and Inventory classes and the ability to locate things within these objects. From this it should be possible to add items into the Play- er's inventory and then get the player to locate the item for us. Identifiable Object << abstract >> Game Object -_description : string - name : string + Game Object(string[] ids, string name, string desc) + Name : string <<readonly, property >> + ShortDescription : string << readonly, property >> + Full Description : String << virtual, readonly, property>> Item + Item(string[] idents, string name, string desc) Inventory items : List<Item> + Inventory() + Hasitem( string id): bool + Put(Item itm) : void + Take(string id) : Item + Fetch(string id): Item + ItemList : string <<readonly, property>> Player _inventory: Inventory + Player(String name, string desc) + Locate(string id) : GameObject + Full Description : string <coverride, readonly, property>> + Inventory: Inventory <creadonly, property>> Notes: • The Player constructor will call the GameObject constructor and pass up identifiers for "me" and "inventory" public Player (string name, string desc) : base( new string[] { "me", "inventory"} { ! name, desc) } Page 3 of 15 Object Oriented Programming Swin-Adventure C# Implementation Plan This iteration adds several classes that help create a number of key abstractions for the game. The Game Object class will be used to represent anything that the player can interact with. • Game Object - "anything" the player can interact with - Name - this is a short textual description of the game object . Description - a longer textual description of the game object Short Description - returns a short description made up of the name and the first id of the game object. This is used when referring to an object, rather than directly examin- ing the object. . Long Description - By default this is just the description, but it will be changed by child classes to include related items. Example from requirements document: Command -> inventory You are Fred the mighty programmer. You are carrying a shovel (shovel) a bronze sword (sword) a small computer (pc) The inventory command is the same as "look at me", so this shows the Full Description of the Player. It includes the short description if items the player is carrying, for exam "a shovel" is the name of an item the player is carrying. The first id of this item is "shovel", so its Short Descrip- tion is "a shovel (shovel)". In the design the Item class is a kind of Game Object. This is an abstraction of the "Items" the player can interact with in the game. Example item: Item shovel = new Item( new String[] {"shovel", "spade" }, "a shovel", "This is a might fine Player is also a kind of Game Object. This will be a object through which the player will inter- act with the game world. • Player - the players avatar in the game world . An Inventory object is used to manage the Player's items Full Description is overridden to include details of the items in the player's inventory. Locate "finds" a GameObject somewhere around the player. At this stage that includes the player themselves, or an item the player has in their inventory. See next page... A number of Game Objects will need to contain Items. This functionality is encapsulated in the Inventory class. This provides a managed list of items. . Inventory - a managed collection of items . Items can be added using Put, or removed by id using Take Fetch locates an item by id (using Are You) and returns it Page 4 of 15 The following UML sequence diagrams shows the sequence of messages involved in locat the player and their items. The player can "locate" themselves. p: Player Locate "inventory". Are You "inventory" Yes / True The player can locate items in their inventory. Note: pi is the player's inventory object. P: Player pi: Inventory gem:Item sword : Item Locate "sword Are You "sword" No / False Fetch "sword Are You "sword No / False Are You "sword" Yes / True sword sword When there are no items that match then null/nil is returned. p: Player pi: Inventory . Item Locate "club Are You "club" No / False Fetch "club" Loop [ for each item) Are You "club" No / False null/nil null/nil Item Unit Tests Test Item is Iden- The item responds correctly to "Are You" requests based on the identi- tifiable fiers it is created with Test Short De- The game object's short description returns the string "a name (first scription id)" eg: a bronze sword (sword) Test Full Descrip- Returns the item's description. tion Inventory Unit Tests Test Find Item The Inventory has items that are put in it. Test No Item Find The Inventory does not have items it does not contain. Test Fetch Item Returns items it has, and the item remains in the inventory. Test Take Item Returns the item, and the item is no longer in the inventory. Test Item List Returns a list of strings with one row per item. The rows contain tab indented short descriptions of the items in the Inventory. Player Unit Tests Test Player is the player responds correctly to "Are You" requests based on its de- Identifiable fault identifiers (me and inventory). Test Player Lo- The player can locate items in its inventory, this returns items the play- cates Items er has and the item remains in the player's inventory. Test Player Lo- The player returns itself if asked to locate "me" or "inventory". cates itself Test Player Lo- The player returns a null/nil object if asked to locate something it does cates nothing not have. Test Player Full The player's full description contains the text "You are carrying:" and Description the short descriptions of the items the player has (from its inventory's item list)

TK57NC The Asker · Computer Science

All codes in c#

Transcribed Image Text: Iteration 2 - Players, Items, and Inventory The goal of this iteration will be to create the Player, Item, and Inventory classes and the ability to locate things within these objects. From this it should be possible to add items into the Play- er's inventory and then get the player to locate the item for us. Identifiable Object << abstract >> Game Object -_description : string - name : string + Game Object(string[] ids, string name, string desc) + Name : string <> + ShortDescription : string << readonly, property >> + Full Description : String << virtual, readonly, property>> Item + Item(string[] idents, string name, string desc) Inventory items : List + Inventory() + Hasitem( string id): bool + Put(Item itm) : void + Take(string id) : Item + Fetch(string id): Item + ItemList : string <> Player _inventory: Inventory + Player(String name, string desc) + Locate(string id) : GameObject + Full Description : string > + Inventory: Inventory > Notes: • The Player constructor will call the GameObject constructor and pass up identifiers for "me" and "inventory" public Player (string name, string desc) : base( new string[] { "me", "inventory"} { ! name, desc) } Page 3 of 15 Object Oriented Programming Swin-Adventure C# Implementation Plan This iteration adds several classes that help create a number of key abstractions for the game. The Game Object class will be used to represent anything that the player can interact with. • Game Object - "anything" the player can interact with - Name - this is a short textual description of the game object . Description - a longer textual description of the game object Short Description - returns a short description made up of the name and the first id of the game object. This is used when referring to an object, rather than directly examin- ing the object. . Long Description - By default this is just the description, but it will be changed by child classes to include related items. Example from requirements document: Command -> inventory You are Fred the mighty programmer. You are carrying a shovel (shovel) a bronze sword (sword) a small computer (pc) The inventory command is the same as "look at me", so this shows the Full Description of the Player. It includes the short description if items the player is carrying, for exam "a shovel" is the name of an item the player is carrying. The first id of this item is "shovel", so its Short Descrip- tion is "a shovel (shovel)". In the design the Item class is a kind of Game Object. This is an abstraction of the "Items" the player can interact with in the game. Example item: Item shovel = new Item( new String[] {"shovel", "spade" }, "a shovel", "This is a might fine Player is also a kind of Game Object. This will be a object through which the player will inter- act with the game world. • Player - the players avatar in the game world . An Inventory object is used to manage the Player's items Full Description is overridden to include details of the items in the player's inventory. Locate "finds" a GameObject somewhere around the player. At this stage that includes the player themselves, or an item the player has in their inventory. See next page... A number of Game Objects will need to contain Items. This functionality is encapsulated in the Inventory class. This provides a managed list of items. . Inventory - a managed collection of items . Items can be added using Put, or removed by id using Take Fetch locates an item by id (using Are You) and returns it Page 4 of 15 The following UML sequence diagrams shows the sequence of messages involved in locat the player and their items. The player can "locate" themselves. p: Player Locate "inventory". Are You "inventory" Yes / True The player can locate items in their inventory. Note: pi is the player's inventory object. P: Player pi: Inventory gem:Item sword : Item Locate "sword Are You "sword" No / False Fetch "sword Are You "sword No / False Are You "sword" Yes / True sword sword When there are no items that match then null/nil is returned. p: Player pi: Inventory . Item Locate "club Are You "club" No / False Fetch "club" Loop [ for each item) Are You "club" No / False null/nil null/nil Item Unit Tests Test Item is Iden- The item responds correctly to "Are You" requests based on the identi- tifiable fiers it is created with Test Short De- The game object's short description returns the string "a name (first scription id)" eg: a bronze sword (sword) Test Full Descrip- Returns the item's description. tion Inventory Unit Tests Test Find Item The Inventory has items that are put in it. Test No Item Find The Inventory does not have items it does not contain. Test Fetch Item Returns items it has, and the item remains in the inventory. Test Take Item Returns the item, and the item is no longer in the inventory. Test Item List Returns a list of strings with one row per item. The rows contain tab indented short descriptions of the items in the Inventory. Player Unit Tests Test Player is the player responds correctly to "Are You" requests based on its de- Identifiable fault identifiers (me and inventory). Test Player Lo- The player can locate items in its inventory, this returns items the play- cates Items er has and the item remains in the player's inventory. Test Player Lo- The player returns itself if asked to locate "me" or "inventory". cates itself Test Player Lo- The player returns a null/nil object if asked to locate something it does cates nothing not have. Test Player Full The player's full description contains the text "You are carrying:" and Description the short descriptions of the items the player has (from its inventory's item list)
More
Transcribed Image Text: Iteration 2 - Players, Items, and Inventory The goal of this iteration will be to create the Player, Item, and Inventory classes and the ability to locate things within these objects. From this it should be possible to add items into the Play- er's inventory and then get the player to locate the item for us. Identifiable Object << abstract >> Game Object -_description : string - name : string + Game Object(string[] ids, string name, string desc) + Name : string <> + ShortDescription : string << readonly, property >> + Full Description : String << virtual, readonly, property>> Item + Item(string[] idents, string name, string desc) Inventory items : List + Inventory() + Hasitem( string id): bool + Put(Item itm) : void + Take(string id) : Item + Fetch(string id): Item + ItemList : string <> Player _inventory: Inventory + Player(String name, string desc) + Locate(string id) : GameObject + Full Description : string > + Inventory: Inventory > Notes: • The Player constructor will call the GameObject constructor and pass up identifiers for "me" and "inventory" public Player (string name, string desc) : base( new string[] { "me", "inventory"} { ! name, desc) } Page 3 of 15 Object Oriented Programming Swin-Adventure C# Implementation Plan This iteration adds several classes that help create a number of key abstractions for the game. The Game Object class will be used to represent anything that the player can interact with. • Game Object - "anything" the player can interact with - Name - this is a short textual description of the game object . Description - a longer textual description of the game object Short Description - returns a short description made up of the name and the first id of the game object. This is used when referring to an object, rather than directly examin- ing the object. . Long Description - By default this is just the description, but it will be changed by child classes to include related items. Example from requirements document: Command -> inventory You are Fred the mighty programmer. You are carrying a shovel (shovel) a bronze sword (sword) a small computer (pc) The inventory command is the same as "look at me", so this shows the Full Description of the Player. It includes the short description if items the player is carrying, for exam "a shovel" is the name of an item the player is carrying. The first id of this item is "shovel", so its Short Descrip- tion is "a shovel (shovel)". In the design the Item class is a kind of Game Object. This is an abstraction of the "Items" the player can interact with in the game. Example item: Item shovel = new Item( new String[] {"shovel", "spade" }, "a shovel", "This is a might fine Player is also a kind of Game Object. This will be a object through which the player will inter- act with the game world. • Player - the players avatar in the game world . An Inventory object is used to manage the Player's items Full Description is overridden to include details of the items in the player's inventory. Locate "finds" a GameObject somewhere around the player. At this stage that includes the player themselves, or an item the player has in their inventory. See next page... A number of Game Objects will need to contain Items. This functionality is encapsulated in the Inventory class. This provides a managed list of items. . Inventory - a managed collection of items . Items can be added using Put, or removed by id using Take Fetch locates an item by id (using Are You) and returns it Page 4 of 15 The following UML sequence diagrams shows the sequence of messages involved in locat the player and their items. The player can "locate" themselves. p: Player Locate "inventory". Are You "inventory" Yes / True The player can locate items in their inventory. Note: pi is the player's inventory object. P: Player pi: Inventory gem:Item sword : Item Locate "sword Are You "sword" No / False Fetch "sword Are You "sword No / False Are You "sword" Yes / True sword sword When there are no items that match then null/nil is returned. p: Player pi: Inventory . Item Locate "club Are You "club" No / False Fetch "club" Loop [ for each item) Are You "club" No / False null/nil null/nil Item Unit Tests Test Item is Iden- The item responds correctly to "Are You" requests based on the identi- tifiable fiers it is created with Test Short De- The game object's short description returns the string "a name (first scription id)" eg: a bronze sword (sword) Test Full Descrip- Returns the item's description. tion Inventory Unit Tests Test Find Item The Inventory has items that are put in it. Test No Item Find The Inventory does not have items it does not contain. Test Fetch Item Returns items it has, and the item remains in the inventory. Test Take Item Returns the item, and the item is no longer in the inventory. Test Item List Returns a list of strings with one row per item. The rows contain tab indented short descriptions of the items in the Inventory. Player Unit Tests Test Player is the player responds correctly to "Are You" requests based on its de- Identifiable fault identifiers (me and inventory). Test Player Lo- The player can locate items in its inventory, this returns items the play- cates Items er has and the item remains in the player's inventory. Test Player Lo- The player returns itself if asked to locate "me" or "inventory". cates itself Test Player Lo- The player returns a null/nil object if asked to locate something it does cates nothing not have. Test Player Full The player's full description contains the text "You are carrying:" and Description the short descriptions of the items the player has (from its inventory's item list)