Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var input : string
- var input2 : string
- var increase : int := 0
- class Item
- export var name, var description, var damage
- var name, description : string
- var damage : int
- var stackable : boolean
- var amount : int
- %other variables
- end Item
- var woodSword : ^Item
- new woodSword
- Item (woodSword).name := "wooden sword"
- Item (woodSword).description := "A weak sword made of wood."
- Item (woodSword).damage := 3
- var steelSword : ^Item
- new steelSword
- Item (steelSword).name := "steel sword"
- Item (steelSword).description := "A strong sword made of steel."
- Item (steelSword).damage := 6
- var inventorySlots : array 1 .. 10 of ^Item
- inventorySlots (1) := nil
- inventorySlots (2) := nil
- inventorySlots (3) := nil
- inventorySlots (4) := nil
- inventorySlots (5) := nil
- inventorySlots (6) := nil
- inventorySlots (7) := nil
- inventorySlots (8) := nil
- inventorySlots (9) := nil
- inventorySlots (10) := nil
- class Inventory
- import var Item, var inventorySlots, var steelSword, var woodSword, var input2
- export addItem, removeItem, displayInventory
- proc addItem (item : ^Item)
- for i : 1 .. upper (inventorySlots)
- if inventorySlots (i) = nil then
- end if
- /*if inventorySlots (i) = nil then
- if input2 = "steel sword" then
- inventorySlots (i) := steelSword
- elsif input2 = "wooden sword" then
- inventorySlots (i) := woodSword
- end if
- exit
- end if*/
- end for
- end addItem
- proc shiftItems
- for i : 1 .. upper (inventorySlots)
- if inventorySlots (i) not= nil then
- else
- for j : i .. upper (inventorySlots)
- if j not= upper (inventorySlots) then
- inventorySlots (j) := inventorySlots (j + 1)
- else
- inventorySlots (j) := nil
- end if
- end for
- end if
- end for
- end shiftItems
- proc removeItem (i : int)
- if Item (inventorySlots (i)).name = input2 then
- inventorySlots (i) := nil
- end if
- /*if inventorySlots (i) = steelSword then
- if input2 = "steel sword" then
- inventorySlots (i) := nil
- end if
- end if
- if inventorySlots (i) = woodSword then
- if input2 = "wooden sword" then
- inventorySlots (i) := nil
- end if
- end if*/
- shiftItems
- end removeItem
- proc displayInventory
- for i : 1 .. upper (inventorySlots)
- put i, ": " ..
- if inventorySlots (i) = nil then
- put "Empty"
- else
- put Item (inventorySlots (i)).name
- end if
- end for
- end displayInventory
- end Inventory
- var openInventory : ^Inventory
- new openInventory
- proc checkSlots
- for i : 1 .. 10
- if inventorySlots (i) = nil then
- elsif Item (inventorySlots (i)).name = input2 then
- Inventory (openInventory).removeItem (i)
- exit
- end if
- end for
- end checkSlots
- put "*** Use \"take\", \"drop\", and \"open inventory\" to test ***"
- put "There is a steel sword in this room."
- put "There is a wooden sword in this room."
- proc gameloop
- loop
- get input
- get input2 : *
- if input = "open" and input2 = "inventory" then
- put "You have:"
- Inventory (openInventory).displayInventory
- elsif input = "drop" then
- checkSlots
- elsif input = "take" and input2 = "steel sword" then
- Inventory (openInventory).addItem (steelSword)
- elsif input = "take" and input2 = "wooden sword" then
- Inventory (openInventory).addItem (woodSword)
- else
- put "That is not a valid command."
- end if
- end loop
- end gameloop
- gameloop
Advertisement
Add Comment
Please, Sign In to add comment