Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Copyright 2015 Max Thor <thormax5@gmail.com>
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- ]]--
- -- Variables
- local color = false
- local creds = 0
- local plusX = 0
- local w, h = term.getSize()
- function cWrite(txt,y)
- term.setCursorPos(math.floor(w-string.len(txt))/2+plusX, h/2)
- term.write(txt)
- plusX = plusX+1
- end
- function cWrite2(txt, y)
- term.setCursorPos(math.floor(w-string.len(txt))/2, y)
- term.write(txt)
- end
- function win(amt)
- creds = creds+amt
- if(color) then
- term.setTextColor(16)
- cWrite2("Won! "..amt, 2)
- else
- cWrite2("Won! "..amt, 2)
- end
- end
- function save()
- local h = fs.open(".slots/save", "w")
- h.write(creds)
- h.close()
- end
- function ui()
- if(color) then
- term.setCursorPos(1,1)
- term.setBackgroundColor(256)
- term.clearLine()
- term.setTextColor(1)
- term.write("Credits: "..creds)
- term.setBackgroundColor(32768)
- else
- term.setCursorPos(1,1)
- term.clearLine()
- term.setTextColor(1)
- term.write("Credits: "..creds)
- end
- end
- function spin()
- term.clear()
- local a = math.random(0, 3)
- local b = math.random(0, 3)
- local c = math.random(0, 3)
- if(a == 1) then
- if(color) then
- term.setTextColor(32)
- cWrite("X", 0)
- else
- cWrite("X", 0)
- end
- elseif(a == 2) then
- if(color) then
- term.setTextColor(2)
- cWrite("$", 0)
- else
- cWrite("$", 0)
- end
- elseif(a == 3) then
- if(color) then
- term.setTextColor(8)
- cWrite("O", 0)
- else
- cWrite("O", 0)
- end
- else
- if(color) then
- term.setTextColor(16384)
- cWrite("-",0)
- else
- cWrite("-", 0)
- end
- end
- if(b == 1) then
- if(color) then
- term.setTextColor(32)
- cWrite("X", 0)
- else
- cWrite("X", 0)
- end
- elseif(b == 2) then
- if(color) then
- term.setTextColor(2)
- cWrite("$", 0)
- else
- cWrite("$", 0)
- end
- elseif(b == 3) then
- if(color) then
- term.setTextColor(8)
- cWrite("O", 0)
- else
- cWrite("O", 0)
- end
- else
- if(color) then
- term.setTextColor(16384)
- cWrite("-",0)
- else
- cWrite("-", 0)
- end
- end
- if(c == 1) then
- if(color) then
- term.setTextColor(32)
- cWrite("X", 0)
- else
- cWrite("X", 0)
- end
- elseif(c == 2) then
- if(color) then
- term.setTextColor(2)
- cWrite("$", 0)
- else
- cWrite("$", 0)
- end
- elseif(c == 3) then
- if(color) then
- term.setTextColor(8)
- cWrite("O", 0)
- else
- cWrite("O", 0)
- end
- else
- if(color) then
- term.setTextColor(16384)
- cWrite("-",0)
- else
- cWrite("-", 0)
- end
- end
- if(a == 1 and b == 1 and c == 1) then
- win(5)
- elseif(a == 2 and b == 2 and c == 2) then
- win(10)
- elseif(a == 3 and b == 3 and c == 3) then
- win(15)
- end
- plusX = 0
- ui()
- end
- function main()
- term.clear()
- ui()
- while true do
- e, p1 = os.pullEventRaw()
- if(e == "key") then
- if(p1 == 57) then
- if(creds > 0) then
- creds = creds-1
- spin()
- end
- elseif(p1 == 1) then
- save()
- os.queueEvent("terminate")
- end
- elseif(e == "terminate") then
- term.setTextColor(1)
- term.setBackgroundColor(32768)
- term.clear()
- plusX = 0
- cWrite("Thanks for playing!")
- break
- end
- end
- end
- function setup()
- if(term.isColor()) then
- color = true
- end
- if(fs.exists(".slots/save")) then
- local h = fs.open(".slots/save", "r")
- creds = tonumber(h.readAll())
- h.close()
- main()
- else
- fs.makeDir(".slots")
- local h = fs.open(".slots/save", "w")
- h.write("10")
- h.close()
- end
- end
- setup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement