Guest User

Turing Game Inventory

a guest
Apr 21st, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. var input : string
  2. var input2 : string
  3. var increase : int := 0
  4.  
  5. class Item
  6. export var name, var description, var damage
  7. var name, description : string
  8. var damage : int
  9. var stackable : boolean
  10. var amount : int
  11. %other variables
  12. end Item
  13.  
  14. var woodSword : ^Item
  15. new woodSword
  16. Item (woodSword).name := "wooden sword"
  17. Item (woodSword).description := "A weak sword made of wood."
  18. Item (woodSword).damage := 3
  19.  
  20. var steelSword : ^Item
  21. new steelSword
  22. Item (steelSword).name := "steel sword"
  23. Item (steelSword).description := "A strong sword made of steel."
  24. Item (steelSword).damage := 6
  25.  
  26. var inventorySlots : array 1 .. 10 of ^Item
  27. inventorySlots (1) := nil
  28. inventorySlots (2) := nil
  29. inventorySlots (3) := nil
  30. inventorySlots (4) := nil
  31. inventorySlots (5) := nil
  32. inventorySlots (6) := nil
  33. inventorySlots (7) := nil
  34. inventorySlots (8) := nil
  35. inventorySlots (9) := nil
  36. inventorySlots (10) := nil
  37.  
  38. class Inventory
  39. import var Item, var inventorySlots, var steelSword, var woodSword, var input2
  40. export addItem, removeItem, displayInventory
  41.  
  42. proc addItem (item : ^Item)
  43. for i : 1 .. upper (inventorySlots)
  44. if inventorySlots (i) = nil then
  45.  
  46. end if
  47. /*if inventorySlots (i) = nil then
  48. if input2 = "steel sword" then
  49. inventorySlots (i) := steelSword
  50. elsif input2 = "wooden sword" then
  51. inventorySlots (i) := woodSword
  52. end if
  53. exit
  54. end if*/
  55. end for
  56. end addItem
  57.  
  58. proc shiftItems
  59. for i : 1 .. upper (inventorySlots)
  60. if inventorySlots (i) not= nil then
  61.  
  62. else
  63. for j : i .. upper (inventorySlots)
  64. if j not= upper (inventorySlots) then
  65. inventorySlots (j) := inventorySlots (j + 1)
  66. else
  67. inventorySlots (j) := nil
  68. end if
  69.  
  70. end for
  71. end if
  72. end for
  73. end shiftItems
  74.  
  75. proc removeItem (i : int)
  76. if Item (inventorySlots (i)).name = input2 then
  77. inventorySlots (i) := nil
  78. end if
  79.  
  80. /*if inventorySlots (i) = steelSword then
  81. if input2 = "steel sword" then
  82. inventorySlots (i) := nil
  83. end if
  84. end if
  85. if inventorySlots (i) = woodSword then
  86. if input2 = "wooden sword" then
  87. inventorySlots (i) := nil
  88. end if
  89. end if*/
  90. shiftItems
  91. end removeItem
  92.  
  93. proc displayInventory
  94. for i : 1 .. upper (inventorySlots)
  95. put i, ": " ..
  96. if inventorySlots (i) = nil then
  97. put "Empty"
  98. else
  99. put Item (inventorySlots (i)).name
  100. end if
  101. end for
  102. end displayInventory
  103.  
  104.  
  105. end Inventory
  106.  
  107. var openInventory : ^Inventory
  108. new openInventory
  109.  
  110. proc checkSlots
  111. for i : 1 .. 10
  112. if inventorySlots (i) = nil then
  113.  
  114. elsif Item (inventorySlots (i)).name = input2 then
  115. Inventory (openInventory).removeItem (i)
  116. exit
  117. end if
  118. end for
  119. end checkSlots
  120.  
  121.  
  122. put "*** Use \"take\", \"drop\", and \"open inventory\" to test ***"
  123. put "There is a steel sword in this room."
  124. put "There is a wooden sword in this room."
  125. proc gameloop
  126. loop
  127. get input
  128. get input2 : *
  129.  
  130. if input = "open" and input2 = "inventory" then
  131. put "You have:"
  132. Inventory (openInventory).displayInventory
  133. elsif input = "drop" then
  134. checkSlots
  135. elsif input = "take" and input2 = "steel sword" then
  136. Inventory (openInventory).addItem (steelSword)
  137. elsif input = "take" and input2 = "wooden sword" then
  138. Inventory (openInventory).addItem (woodSword)
  139. else
  140. put "That is not a valid command."
  141. end if
  142. end loop
  143. end gameloop
  144. gameloop
Advertisement
Add Comment
Please, Sign In to add comment