In this level, you will create the shop menu interface to browse the items in the store, it will limit the items displayed to 10 at a time.
The user will enter 'n' to see the next items listed and 'p' to go backwards and 'e' to exit.
Item# Name Damage Value
----- -------------------- ----- -----
1 scimitar blade 8 50
2 dagger 5 25
3 sword small 6 30
4 sword long 8 40
5 club 4 20
6 mace heavy 9 35
7 axe hand 5 25
8 axe battle 8 45
9 spear 6 30
10 staff 3 15
Press Enter or 'n' to go forward, 'p' to go back, or 'e' to exit:
Item# Name Damage Value
----- -------------------- ----- -----
1 flail 4 25
2 wand magic missile missiles 8 30
3 sword long 8 40
4 long sword 8 60
5 sword standard merc 7 40
6 dagger standard merc 5 25
7 mace standard merc 6 35
8 Sword of Power 12 1153
9 Axe of Fury 96 10229
10 Bow of Accuracy 21 1460
Press Enter or 'n' to go forward, 'p' to go back, or 'e' to exit:
HINT: you have a modelGood.bin in your HW directory, use it to help you understand the flow of the pagination.
- Creating a shop sub-menu within the MUD in
Shop::enter()
- Create a shop sub-menu in
Shop::enter()
- Wrap the call to
listItems
in a while loop that will exit when a user enters 'e'.
- Create a menu option for 'n' and 'p' that do nothing right now
- Upgrading
Shop::listItems
:
- The shop listing will show the items but only 10 items at a time.
- This is one way of handling the paging, there's other options you might explore.
- Modify
Shop::listItems
and add a parameter ShopItem * nextItemToShow
and have it return a ShopItem *
- If the current pointer at the end is not a nullptr return current otherwise return nextItemToShow
- Add a limiter that will only display 10 items from the current position.
- The numbering of the items will stay between 1 and 10 (i.e., it will reset to 1 for each page displayed)
- Updating
Shop::enter()
to handle 'n' and 'p'
- Add a new ShopItem pointer that will track the next Item to show the user (what should it be initialized to?)
- Update the
listItems
call to receive the next item pointer
- Create another ShopItem pointer that will hold the result temporarily of the
listItem
call
- if the player selects 'n' then set the next item pointer to the pointer result from
listItems
.
- if the player selects 'p' then
- Follow the previous chain backwards 10 nodes from the last next item pointer (since only updated if 'n', it should be the next item from the prior list)
- If the chain points results in a nullptr, then the front of the list was reached and should be handled accordingly.
- Example of using 'p'
- If it showed scimitar blade to staff, then flail to Bow of Accuracy.
- On a 'p', back track from the current next to be shown (scimitar blade) 10 nodes to scimitar blade
- Then set the next to be shown to flail, and it will display scimitar blade to staff