Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Example gem-miner by 1lann
- if not term.isColor() then
- print("Not available for use on normal computers")
- end
- print("Mine all of the yellow gems!")
- sleep(3)
- local score = 0
- local yellows = {}
- local numYellows = 0
- local possibilities = {colors.orange, colors.lightBlue, colors.lime, colors.yellow}
- local function generateBoard()
- term.clear()
- term.setCursorBlink(false)
- local width, height = term.getSize()
- for y = 2, height do
- for x = 1, width do
- local curColor = possibilities[math.random(1,#possibilities)]
- if curColor == colors.yellow then
- yellows[tostring(x) .. "," .. tostring(y)] = true
- numYellows = numYellows+1
- end
- term.setCursorPos(x, y)
- term.setBackgroundColor(curColor)
- term.write(" ")
- end
- end
- end
- generateBoard()
- local function printScore(score)
- term.setCursorPos(37,1)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.write("Score: " .. tostring(score).."/"..tostring(numYellows))
- if score >= numYellows then return true end
- end
- local function mainGame()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.gray)
- term.clearLine()
- term.setTextColor(colors.red)
- term.write("[X] ")
- term.setTextColor(colors.white)
- term.write("Gem-miner example program!")
- printScore(0)
- while true do
- local e, _, x, y = os.pullEvent()
- if e == "mouse_click" then
- if yellows[tostring(x)..","..tostring(y)] then
- score=score+1
- if printScore(score) then
- break
- end
- term.setBackgroundColor(colors.black)
- term.setCursorPos(x,y)
- term.write(" ")
- yellows[tostring(x)..","..tostring(y)] = nil
- elseif (y == 1) and (x >= 1) and (x <= 3) then
- break
- end
- end
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setTextColor(colors.yellow)
- term.setCursorPos(1,1)
- if score >= numYellows then
- print("Congratulations, you win!")
- end
- print("Thanks for trying out gem-miner")
- return
- end
- mainGame()
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement