Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- High or low
- By Konlab
- ]]
- --init
- local version = 1.1
- local w,h = term.getSize()
- local maxnum = 20
- local theme = 2
- local themes = {{"Old",colors.orange,colors.black},{"New",colors.lightBlue,colors.black},{"Dark & Blue",colors.blue,colors.black},{"Green",colors.green,colors.white},{"White",colors.white,colors.black}}
- local money = 0
- local configpath = "/.hilodata"
- --functions
- local function cl()
- term.setBackgroundColor(themes[theme][2])
- term.setTextColor(themes[theme][3])
- term.clear()
- term.setCursorPos(1,1)
- end
- local function loaddata()
- local file = fs.open(configpath,"r")
- maxnum = tonumber(file.readLine())
- theme = tonumber(file.readLine())
- money = tonumber(file.readLine())
- file.close()
- end
- local function savedata()
- local file = fs.open(configpath,"w")
- file.writeLine(maxnum)
- file.writeLine(theme)
- file.writeLine(money)
- file.close()
- end
- local function init()
- if fs.exists(configpath) then
- loaddata()
- else
- savedata()
- end
- end
- local function loadscreen()
- term.setBackgroundColor(colors.orange)
- term.setTextColor(colors.black)
- term.clear()
- local text = {"High or Low","By Konlab","version: "..version}
- for i=1,#text do
- term.setCursorPos(math.floor(w/2-#text[i]/2),math.floor(h/2-#text/2+i))
- term.write(text[i])
- end
- init()
- end
- local function choosetheme()
- cl()
- i = 0
- for k,v in pairs(themes) do
- i = i + 1
- term.setBackgroundColor(v[2])
- term.setTextColor(v[3])
- term.setCursorPos(2,i)
- term.write(v[1])
- if k == theme then
- term.write(" - selected")
- end
- end
- local _,_,_,y = os.pullEvent("mouse_click")
- if y < #themes + 1 then
- theme = y
- end
- end
- local function settings()
- cl()
- print([[Settings:
- Max number:
- ]])
- term.setCursorPos(1,h)
- term.write("click anywhere else to go back")
- term.setTextColor(colors.black)
- term.setCursorPos(1,4)
- term.setBackgroundColor(colors.white)
- term.clearLine()
- term.setCursorPos(2,4)
- term.write(maxnum)
- term.setCursorPos(1,6)
- term.clearLine()
- term.setCursorPos(1,6)
- term.write(" Choose a theme")
- local _,_,_,y = os.pullEvent("mouse_click")
- if y == 4 then
- term.setCursorPos(1,4)
- term.clearLine()
- term.setCursorPos(2,4)
- maxnum = math.floor(tonumber(read()))
- if maxnum < 5 then
- maxnum = 5
- elseif maxnum > 100 then
- maxnum = 100
- end
- elseif y == 6 then
- choosetheme()
- end
- savedata()
- end
- local function dIntf(currentNumber)
- cl()
- term.setBackgroundColor(themes[theme][2])
- term.setCursorPos(1,3)
- term.write("Number range: 1-" .. maxnum)
- term.setCursorPos(1,5)
- term.write("Current number: "..currentNumber)
- term.setCursorPos(1,h-1)
- term.write("Probability: "..(maxnum-currentNumber)* (math.floor(10000/maxnum)/100) .."% / " .. math.floor(10000/maxnum)/100 .. "% / " ..((currentNumber-1)*(math.floor(10000/maxnum)/100)).."%")
- term.setCursorPos(1,h-2)
- term.write("Money won: " .. tostring(money))
- term.setCursorPos(1,math.floor(h/2)-1)
- term.write("\\/")
- term.setCursorPos(1,math.floor(h/2)+1)
- term.write("/\\")
- term.clearLine()
- for j=0,math.floor(w/5) do
- term.setCursorPos(1+j*math.floor(w/5),math.floor(h/2))
- local k
- if currentNumber+j > maxnum then k = currentNumber+j - maxnum else k = currentNumber+j end
- term.write(k)
- end
- --not the same background
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- term.setCursorPos(1,1)
- term.clearLine()
- term.setCursorPos(1,1)
- term.write("High or Low")
- term.setCursorPos(w-2,1)
- term.write("S x")
- term.setCursorPos(1,h)
- term.setBackgroundColor(colors.green)
- term.write("High")
- term.setBackgroundColor(colors.red)
- term.setCursorPos(w-2,h)
- term.write("Low")
- term.setBackgroundColor(colors.white)
- term.setCursorPos(math.floor(w/2)-3,h)
- term.write("Equal")
- end
- local function animateNums(wonNumber,preNumber)
- term.setBackgroundColor(themes[theme][2])
- term.setTextColor(themes[theme][3])
- for i=preNumber,wonNumber+maxnum do
- term.clearLine()
- for j=0,math.floor(w/5) do
- term.setCursorPos(1+j*math.floor(w/5),math.floor(h/2))
- local k
- if i+j > maxnum then k = i+j - maxnum else k = i+j end
- term.write(k)
- end
- sleep(0.1)
- end
- end
- local function calculate(prevNumber,state)
- local nextNumber = math.random(1,maxnum)
- animateNums(nextNumber,prevNumber)
- if nextNumber < prevNumber then
- if state == 3 then
- money = money + math.floor(math.random(1,10000)^0.5)
- else
- money = math.floor(money - money/2)
- end
- elseif nextNumber > prevNumber then
- if state == 1 then
- money = money + math.floor(math.random(1,10000)^0.5)
- else
- money = math.floor(money - money/2)
- end
- else
- --equal
- if state == 2 then
- money = money + math.floor(math.random(10,100000)^0.5)--equal bonus :)
- else
- money = math.floor(money - money/2)
- end
- end
- return nextNumber
- end
- local function waitForActions(currentNumber)
- while true do
- dIntf(currentNumber)
- local _,b,x,y = os.pullEvent("mouse_click")
- local state
- if b == 1 and y == h then
- if x < 5 then state = 1 elseif x > w-3 then state = 3 elseif x > math.floor(w/2) - 3 and x < math.floor(w/2) + 3 then state = 2 end
- end
- if b == 1 and y == 1 and x == w then
- savedata()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- term.clear()
- error("Bye",0)
- end
- if b == 1 and y == 1 and x == w-2 then
- settings()
- currentNumber = math.ceil(maxnum/2)
- end
- if b == 2 then
- settings()
- currentNumber = math.ceil(maxnum/2)
- end
- if type(state) == "number" then currentNumber = calculate(currentNumber,state) end
- return currentNumber
- end
- end
- --main loop
- loadscreen()
- sleep(3)
- local currentNumber = math.ceil(maxnum/2)
- while true do
- currentNumber = waitForActions(currentNumber)
- sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement