Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- RPS - Made by brett122798
- -- If you're reading this, I am sorry for my sloppy code :P
- function round(number)
- if number-math.floor(number) > .5 then
- number1 = math.ceil(number)
- else
- number1 = math.floor(number)
- end
- end
- function mainmenu()
- term.clear()
- term.setCursorPos(1, 1)
- print(" Which type of game would you like to play? ")
- print("")
- print(" Singleplayer Multiplayer ")
- print(" (1) (2) ")
- print("-------------------------------------------------")
- write("Game Type: ")
- gametype = read()
- if gametype == "1" or gametype == "singleplayer" then
- menu()
- elseif gametype == "2" or gametype == "multiplayer" then
- hostconnect()
- end
- end
- function hostconnect()
- term.clear()
- term.setCursorPos(1, 1)
- print(" Multiplayer ")
- print("-------------------------------------------------")
- print(" Would you like to host a game, or connect to a ")
- print(" game? ")
- print("")
- print(" Host Connect ")
- print(" (1) (2) ")
- print("-------------------------------------------------")
- write("Connection Type: ")
- ct = read()
- if ct == "1" or ct == "host" then
- compid = os.getComputerID()
- term.clear()
- term.setCursorPos(1, 1)
- print(" Multiplayer ")
- print("-------------------------------------------------")
- print(" Waiting for a player to connect.. ")
- print("")
- print("Players can connect with this ID: "..compid)
- print("")
- print("")
- print("If you would like to leave, terminate the program")
- print(" (Ctrl+T)")
- repeat
- id, message = rednet.receive()
- until message == "letsplay"
- if message == "letsplay" then
- opcompid = id
- sleep(1)
- rednet.send(opcompid, username)
- id, message = rednet.receive()
- opusername = message
- term.clear()
- term.setCursorPos(1, 1)
- print(" Multiplayer ")
- print("-------------------------------------------------")
- print(" Player Found!")
- print("")
- sleep(0.5)
- print(" Your opponent is "..opusername.." (ID: "..opcompid..")")
- sleep(3)
- parallel.waitForAny(multiplayermenu, info1)
- if message == "imdone" then
- multiplayermenu()
- end
- multweap = true
- parallel.waitForAll(multiplayerweapon, info1)
- multiplayergame()
- end
- elseif ct == "2" or ct == "connect" then
- term.clear()
- term.setCursorPos(1, 1)
- print(" Multiplayer ")
- print("-------------------------------------------------")
- print(" Type in the computer ID of the server ")
- print("-------------------------------------------------")
- write("Computer ID: ")
- serverconnect = read()
- serverconnect = tonumber(serverconnect)
- print("")
- print("Waiting for reply from server..")
- rednet.send(serverconnect, "letsplay")
- id = 0
- id, message = rednet.receive(5)
- if id == serverconnect then
- opcompid = id
- opusername = message
- rednet.send(opcompid, username)
- print("")
- print("Connected to the server! Please wait..")
- sleep(2)
- parallel.waitForAny(multiplayermenu, info1)
- if message == "imdone" then
- multiplayermenu()
- end
- multweap = true
- parallel.waitForAll(multiplayerweapon, info1)
- multiplayergame()
- else
- print("")
- print("Failed to connect to server!")
- sleep(2)
- term.clear()
- term.setCursorPos(1, 1)
- end
- end
- end
- function multiplayercycle()
- parallel.waitForAny(multiplayermenu, info1)
- if message == "imdone" then
- multiplayermenu()
- end
- multweap = true
- parallel.waitForAll(multiplayerweapon, info1)
- multiplayergame()
- end
- function multiplayermenu()
- term.clear()
- term.setCursorPos(1, 1)
- print(" *MP* Rock Paper Scissors!! V. 1.0.3 ")
- print("-------------------------------------------------")
- print(" W: "..mpwins.." | L: "..mplosses)
- print("-------------------------------------------------")
- print(" Press enter to play, but if you would like to")
- print(" exit the game, type 'exit' then enter.")
- print("")
- if message == "imdone" then
- term.setCursorPos(1, 17)
- print(opusername.." has chosen their weapon!")
- term.setCursorPos(1, 8)
- end
- write("")
- entergame = read()
- if entergame == "exit" then
- os.reboot()
- else
- end
- end
- function info1()
- if message == "imdone" then
- term.setCursorPos(1, 17)
- print(opusername.." has chosen their weapon!")
- if multweap == true then
- term.setCursorPos(16, 6)
- multweap = false
- end
- else
- id, message = rednet.receive()
- term.setCursorPos(1, 17)
- print(opusername.." has chosen their weapon!")
- end
- end
- function multiplayerweapon()
- term.clear()
- term.setCursorPos(1, 1)
- print(" What's your choice of Weapon? ")
- print("")
- print(" Rock Paper Scissors ")
- print(" (1) (2) (3) ")
- print("-------------------------------------------------")
- write("Weapon Choice: ")
- term.setCursorPos(16, 6)
- choice = read()
- if choice == "1" or choice == "rock" then
- weapon = "rock"
- elseif choice == "2" or choice == "paper" then
- weapon = "paper"
- elseif choice == "3" or choice == "scissors" then
- weapon = "scissors"
- else
- weapon = "rock"
- end
- term.setCursorPos(1, 17)
- rednet.send(opcompid, "imdone")
- if message ~= "imdone" then
- print("Waiting for "..opusername.."..")
- end
- end
- function multiplayergame()
- parallel.waitForAll(oppick, pick)
- term.clear()
- term.setCursorPos(1, 1)
- count = 0
- repeat
- term.clear()
- term.setCursorPos(1, 1)
- count = count + 1
- if weapon == "rock" then
- print(" You chose Rock ")
- elseif weapon == "paper" then
- print(" You chose Paper ")
- elseif weapon == "scissors" then
- print(" You chose Scissors ")
- end
- print("-------------------------------------------------")
- term.setCursorPos(1, 5)
- if count == 1 then
- print(" Rock.. ")
- elseif count == 2 then
- print(" Rock.. Paper.. ")
- elseif count == 3 then
- print(" Rock.. Paper.. Scissors! ")
- end
- sleep(0.6)
- until count == 4
- term.clear()
- term.setCursorPos(1, 1)
- if weapon == opweapon then
- result = "tie"
- elseif weapon == "rock" and opweapon == "paper" then
- result = "lose"
- elseif weapon == "rock" and opweapon == "scissors" then
- result = "win"
- elseif weapon == "paper" and opweapon == "rock" then
- result = "win"
- elseif weapon == "paper" and opweapon == "scissors" then
- result = "lose"
- elseif weapon == "scissors" and opweapon == "rock" then
- result = "lose"
- elseif weapon == "scissors" and opweapon == "paper" then
- result = "win"
- end
- count = 5
- if result == "tie" then
- repeat
- term.clear()
- term.setCursorPos(1, 1)
- print(" Tie ")
- print("-------------------------------------------------")
- print(" Well, it's a tie! ")
- print("")
- print("You and "..opusername.." both got "..weapon.."!")
- print("")
- print("")
- print("Continuing in "..count.." seconds..")
- count = count - 1
- sleep(1)
- until count == 0
- elseif result == "win" then
- mpwins = mpwins + 1
- repeat
- term.clear()
- term.setCursorPos(1, 1)
- print(" Winner! ")
- print("-------------------------------------------------")
- print(" Congrats! You won the round! ")
- print("")
- print("Poor "..opusername.." got "..opweapon..".")
- print("")
- print("The Good News is that you got "..weapon.."!!")
- print("")
- print("")
- print("Continuing in "..count.." seconds..")
- count = count - 1
- sleep(1)
- until count == 0
- elseif result == "lose" then
- mplosses = mplosses + 1
- repeat
- term.clear()
- term.setCursorPos(1, 1)
- print(" Loser! ")
- print("-------------------------------------------------")
- print(" Oh no! You lost the round?! ")
- print("")
- print("Your poor choice was "..weapon..".")
- print("")
- print(opusername.."'s excellent choice was "..opweapon..".")
- print("")
- print("")
- print("Continuing in "..count.." seconds..")
- count = count - 1
- sleep(1)
- until count == 0
- end
- multiplayercycle()
- end
- function pick()
- if serverconnect == false then
- sleep(0.01)
- rednet.send(opcompid, weapon)
- else
- rednet.send(opcompid, weapon)
- end
- end
- function oppick()
- if serverconnect == true then
- sleep(0.01)
- id, message = rednet.receive()
- opweapon = message
- else
- id, message = rednet.receive()
- opweapon = message
- end
- end
- function menu()
- term.clear()
- term.setCursorPos(1, 1)
- percentage = wins/(wins+losses)
- if percentage == 1 then
- rank = "Mr. Perfect (Lvl. 11)"
- elseif percentage < 1 and percentage > 0.8999999 then
- rank = "RPS Legend (Lvl. 10)"
- elseif percentage < 0.9 and percentage > 0.7999999 then
- rank = "RPS Master (Lvl. 9)"
- elseif percentage < 0.8 and percentage > 0.6999999 then
- rank = "Big Winner (Lvl. 8)"
- elseif percentage < 0.7 and percentage > 0.5999999 then
- rank = "Winner (Lvl. 7)"
- elseif percentage < 0.6 and percentage > 0.4999999 then
- rank = "Slight Winner (Lvl. 6)"
- elseif percentage < 0.5 and percentage > 0.3999999 then
- rank = "Minor Loser (Lvl. 5)"
- elseif percentage < 0.4 and percentage > 0.2999999 then
- rank = "Loser (Lvl. 4)"
- elseif percentage < 0.3 and percentage > 0.1999999 then
- rank = "Huge Loser (Lvl. 3)"
- elseif percentage < 0.2 and percentage > 0.0999999 then
- rank = "Computer Puncher (Lvl. 2)"
- elseif percentage < 0.1 and percentage > 0 then
- rank = "Computer Smasher (Lvl. 1)"
- elseif percentage == 0 then
- rank = "Mr. Nonperfect (Lvl. 0)"
- else
- rank = "No Rank"
- end
- round(percentage*100)
- percentage = number1
- if wins == 0 and losses == 0 then
- print(" ---% Rock Paper Scissors!! V. 1.0.3 ")
- elseif percentage < 100 and percentage > 9.9999999 then
- print(" "..percentage.."% Rock Paper Scissors!! V. 1.0.3 ")
- elseif percentage < 10 then
- print(" "..percentage.."% Rock Paper Scissors!! V. 1.0.3 ")
- elseif percentage == 100 then
- print(" 100% Rock Paper Scissors!! V. 1.0.3 ")
- end
- print("-------------------------------------------------")
- print("Rank: "..rank)
- term.setCursorPos(33, 3)
- print("W: "..wins.." | L: "..losses)
- print("-------------------------------------------------")
- print(" Press enter to play, but if you would like to")
- print(" exit the game, type 'exit' then enter.")
- print("")
- write("")
- entergame = read()
- if entergame == "exit" then
- term.clear()
- term.setCursorPos(1, 1)
- else
- game()
- end
- end
- function game()
- term.clear()
- term.setCursorPos(1, 1)
- print(" What's your choice of Weapon? ")
- print("")
- print(" Rock Paper Scissors ")
- print(" (1) (2) (3) ")
- print("-------------------------------------------------")
- write("Weapon Choice: ")
- choice = read()
- if choice == "1" or choice == "rock" then
- weapon = "rock"
- elseif choice == "2" or choice == "paper" then
- weapon = "paper"
- elseif choice == "3" or choice == "scissors" then
- weapon = "scissors"
- else
- weapon = "rock"
- end
- count = 0
- repeat
- term.clear()
- term.setCursorPos(1, 1)
- count = count + 1
- if weapon == "rock" then
- print(" You chose Rock ")
- elseif weapon == "paper" then
- print(" You chose Paper ")
- elseif weapon == "scissors" then
- print(" You chose Scissors ")
- end
- print("-------------------------------------------------")
- term.setCursorPos(1, 5)
- if count == 1 then
- print(" Rock.. ")
- elseif count == 2 then
- print(" Rock.. Paper.. ")
- elseif count == 3 then
- print(" Rock.. Paper.. Scissors! ")
- end
- sleep(0.6)
- until count == 4
- term.clear()
- term.setCursorPos(1, 1)
- randnum = math.random(1, 3)
- if randnum == 1 then
- opweapon = "rock"
- elseif randnum == 2 then
- opweapon = "paper"
- elseif randnum == 3 then
- opweapon = "scissors"
- end
- if weapon == opweapon then
- result = "tie"
- elseif weapon == "rock" and opweapon == "paper" then
- result = "lose"
- elseif weapon == "rock" and opweapon == "scissors" then
- result = "win"
- elseif weapon == "paper" and opweapon == "rock" then
- result = "win"
- elseif weapon == "paper" and opweapon == "scissors" then
- result = "lose"
- elseif weapon == "scissors" and opweapon == "rock" then
- result = "lose"
- elseif weapon == "scissors" and opweapon == "paper" then
- result = "win"
- end
- if result == "tie" then
- print(" Tie ")
- print("-------------------------------------------------")
- print(" Well, it's a tie! ")
- print("")
- print("You and the computer both got "..weapon.."!")
- elseif result == "win" then
- wins = wins + 1
- file = io.open("/ProgramData/RPS/Wins", "w")
- file:write(wins)
- file:close()
- print(" Winner! ")
- print("-------------------------------------------------")
- print(" Congrats! You won the round! ")
- print("")
- print("The poor computer got "..opweapon..".")
- print("")
- print("The Good News is that you got "..weapon.."!!")
- elseif result == "lose" then
- losses = losses + 1
- file = io.open("/ProgramData/RPS/Losses", "w")
- file:write(losses)
- file:close()
- print(" Loser! ")
- print("-------------------------------------------------")
- print(" Oh no! You lost the round?! ")
- print("")
- print("Your poor choice was "..weapon..".")
- print("")
- print("The computer's excellent choice was "..opweapon..".")
- end
- print("")
- print("")
- sleep(2)
- write("Press Enter To Continue..")
- cont = read()
- menu()
- end
- if fs.exists("ProgramData/RPS") == false then
- fs.makeDir("ProgramData/RPS")
- term.clear()
- term.setCursorPos(1, 1)
- print(" Username Selection ")
- print("-------------------------------------------------")
- print(" Please type in a username that you would like ")
- print("")
- write("Username: ")
- username = read()
- file = io.open("/ProgramData/RPS/Username", "w")
- file:write(username)
- file:close()
- term.clear()
- term.setCursorPos(1, 1)
- print(" Modem Side Selection ")
- print("-------------------------------------------------")
- print(" What side is you wireless modem on? ")
- print("")
- print(" Top Bottom Left ")
- print(" (1) (2) (3) ")
- print("")
- print(" Right Front Back ")
- print(" (4) (5) (6) ")
- print("-------------------------------------------------")
- write("Modem Side: ")
- modemside = read()
- if modemside == "1" or modemside == "top" then
- file = io.open("/ProgramData/RPS/Modem_Side", "w")
- file:write("top")
- file:close()
- elseif modemside == "2" or modemside == "bottom" then
- file = io.open("/ProgramData/RPS/Modem_Side", "w")
- file:write("bottom")
- file:close()
- elseif modemside == "3" or modemside == "left" then
- file = io.open("/ProgramData/RPS/Modem_Side", "w")
- file:write("left")
- file:close()
- elseif modemside == "4" or modemside == "right" then
- file = io.open("/ProgramData/RPS/Modem_Side", "w")
- file:write("right")
- file:close()
- elseif modemside == "5" or modemside == "front" then
- file = io.open("/ProgramData/RPS/Modem_Side", "w")
- file:write("front")
- file:close()
- elseif modemside == "6" or modemside == "back" then
- file = io.open("/ProgramData/RPS/Modem_Side", "w")
- file:write("back")
- file:close()
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("Creating Save Files..")
- sleep(1.5)
- file = io.open("/ProgramData/RPS/Wins", "w")
- file:write("0")
- file:close()
- file = io.open("/ProgramData/RPS/Losses", "w")
- file:write("0")
- file:close()
- end
- file = fs.open("/ProgramData/RPS/Username", "r")
- username = file:readAll()
- file:close()
- file = fs.open("/ProgramData/RPS/Modem_Side", "r")
- modemside = file:readAll()
- file:close()
- rednet.open(modemside)
- file = fs.open("/ProgramData/RPS/Wins", "r")
- wins = file:readAll()
- file:close()
- file = fs.open("/ProgramData/RPS/Losses", "r")
- losses = file:readAll()
- file:close()
- wins = tonumber(wins)
- losses = tonumber(losses)
- mpwins = 0
- mplosses = 0
- serverconnect = false
- mainmenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement