Advertisement
oGoOgO

slot_machine.lua

Jun 3rd, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. ---Creates shuffled table copy
  2. ---@param t table
  3. ---@return table
  4. local function shuffle(t)
  5. local result = {}
  6. for i = 1, #t do
  7. result[i] = t[i]
  8. end
  9. -- Fisher–Yates shuffle
  10. for i = #result, 1, -1 do
  11. local j = math.random(1, i)
  12. result[i], result[j] = result[j], result[i]
  13. end
  14. return result
  15. end
  16.  
  17. local Symbol = {}
  18. function Symbol:new()
  19. local obj = {}
  20. obj.name = nil
  21. obj.nameColor = nil
  22. obj.sound = nil
  23. obj.image = nil
  24. obj.ratio = nil
  25.  
  26. setmetatable(obj, self)
  27. self.__index = self;
  28. return obj
  29. end
  30.  
  31. local Machine = {}
  32. function Machine:new()
  33. local obj = {}
  34. obj.symbols = nil
  35.  
  36. --- @return table
  37. function obj.rollColumn()
  38. return shuffle(obj.symbols)
  39. end
  40.  
  41. function obj.randomSymbol()
  42. return obj.symbols[math.random(1, #obj.symbols)]
  43. end
  44.  
  45. obj.spin = setmetatable(obj, self)
  46. self.__index = self;
  47. return obj
  48. end
  49.  
  50. local slot_machine = {}
  51. slot_machine.Symbol = Symbol
  52. slot_machine.Machine = Machine
  53. return slot_machine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement