Advertisement
Guest User

test

a guest
Feb 21st, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 KB | None | 0 0
  1. local w = require("w") -- allows interaction with krist websocket api (for realtime data)
  2. local r = require("r") -- makes http requests easier
  3. local k = require("k") -- the krist api itself
  4. local jua = require("jua") -- makes events easier
  5. os.loadAPI("json.lua") -- to parse data returned by the krist api
  6. local await = jua.await
  7. r.init(jua)
  8. w.init(jua)
  9. k.init(jua, json, w, r)
  10.  
  11.  
  12.  
  13. local function openWebsocket()
  14.   local success, ws = await(k.connect, k.toKristWalletFormat(6798332999))
  15.   assert(success, "Failed to get websocket URL")
  16.  
  17.   -- print("Connected to websocket.")
  18.  
  19.   -- here we subscribe to the 'transactions' event
  20.   local success = await(ws.subscribe, "transactions", function(data)
  21.     -- this function is called every time a transaction is made
  22.     local transaction = data.transaction
  23.  
  24.     --print("Transaction made:")
  25.     --print("From: " .. transaction.from)
  26.     --print("To: " .. transaction.to)
  27.     --print("Value: " .. transaction.value .. " KST")
  28.     -- Transactions have other properties, including "metadata", "id" and "time".
  29.     -- Metadata can be parsed using k.parseMeta
  30.   end)
  31.   assert(success, "Failed to subscribe to event")
  32. end
  33. --
  34. --
  35. --
  36. escore = 0
  37. py = 14
  38. ex, y1 = 50, 13
  39. y2 = 15
  40. function ggraphic()
  41.     while true do
  42.         term.setBackgroundColor(colors.lightBlue)
  43.         term.clear()
  44.         paintutils.drawFilledBox(1,11,51,19,colors.green)
  45.         paintutils.drawFilledBox(1,13,51,15,colors.black)
  46.         paintutils.drawPixel(ex, y1, colors.red)
  47.         paintutils.drawPixel(ex, y2, colors.red)
  48.         paintutils.drawPixel(10, py, colors.blue)
  49.         term.setBackgroundColor(colors.green)
  50.         term.setCursorPos(10,11)
  51.         term.write("Score: ")
  52.         term.write(escore)
  53.         sleep(0.1)
  54.     end
  55. end
  56. function gemove()
  57.     while true do
  58.     sleep()
  59.     if ex < 2 then
  60.     y1 = math.random(13,15)
  61.     y2 = math.random(13,15)
  62.     ex = 51
  63.     end
  64.     if y2 == y1 then
  65.     y2 = y2 + 1
  66.     end
  67.     if y2 == 16 then
  68.     y2 = 13
  69.     end
  70.         ex = ex - 1
  71.         if ex == 10 then
  72.         escore = escore + 1
  73.         end
  74.     end
  75. end
  76. function epmove()
  77.     while true do
  78.         e, k = os.pullEvent("key")
  79.         if k == 200 then
  80.             if py > 13 then
  81.                  py = py - 1
  82.              end
  83.         elseif k == 208 then
  84.             if py < 15 then
  85.                 py = py + 1
  86.             end
  87.         end
  88.     end
  89. end
  90. function egameend1()
  91.    repeat
  92.        sleep()
  93.    until ex == 10 and y1 == py or y2 == py and ex == 10
  94. end
  95.  
  96. --
  97. --
  98. --
  99.  
  100. jua.go(function()
  101.   openWebsocket()
  102.   parallel.waitForAny(ggraphic,gemove,epmove,egameend1)
  103.     paintutils.drawFilledBox(1,13,51,15,colors.black)
  104.     term.setBackgroundColor(colors.black)
  105.     term.setCursorPos(15,13)
  106.     write("Game Over! Insert 1KST to try again!")
  107. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement