Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Game Rating program with a basic login script v0.01
- # Created by Trilient
- user_info = {
- :trilient => "mypass01",
- :admin => "adminpass"
- }
- games = {
- :Starcraft => 8,
- :Skyrim => 9,
- :Final_Fantasy_7 => 9
- }
- program = true
- login = false
- while program == true
- while login == false
- puts "What is your username?"
- usern = gets.chomp.downcase
- passwd = user_info[usern.to_sym]
- if passwd then
- puts "Enter password: "
- input = gets.chomp
- if input == passwd then
- puts "Welcome #{usern}!"
- login = true
- else
- puts "Incorrect password."
- end
- else
- puts "No such user: #{usern}"
- puts "Would you like to register? (Yes/No)"
- register = gets.chomp.downcase
- if register == "yes"
- puts "Enter a new username:"
- new_usern = gets.chomp.downcase
- if user_info[new_usern.to_sym].nil?
- puts "Enter a password:"
- new_passw = gets.chomp
- user_info[new_usern.to_sym] = new_passw
- puts "Registration complete!"
- else
- puts "Username already exists!"
- end
- if register == "no"
- puts
- end
- end
- end
- while login == true
- puts "Welcome #{usern}, here's a list of commands:"
- puts "-- new"
- puts "-- list"
- puts "-- edit"
- puts "-- delete"
- puts "-- logout"
- puts "Please enter a command to continue:"
- command = gets.chomp
- case command
- when "new"
- puts "Enter a new game to add to the database:"
- new_game = gets.chomp
- if games[new_game.to_sym].nil?
- puts "What rating would you like to give it?"
- new_rating = gets.chomp
- games[new_game.to_sym] = new_rating.to_i
- puts "Successfully added new game!"
- puts
- else
- puts "Game already exists!"
- puts
- end
- when "list"
- games.each { |game, score|
- puts "#{game.to_s}: #{score}"
- }
- when "edit"
- games.each { |game, score|
- puts "#{game}: #{score}"
- }
- puts "Enter the name of a game to edit: (type 'back' to go back)"
- edit_game = gets.chomp
- if games[edit_game.to_sym].nil?
- puts "That game doesn't exist!"
- puts
- elsif edit_game == "back"
- puts
- else
- puts "Enter a new rating: (1 - 10)"
- new_rating = gets.chomp
- games[edit_game.to_sym] = new_rating.to_i
- puts "Updated successfully!"
- puts
- end
- when "logout"
- logout = true
- while logout == true
- puts "Are you sure you want to logout? (Yes/No)"
- sure = gets.chomp.downcase
- if sure == "yes"
- login = false
- logout = false
- elsif sure == "no"
- logout = false
- break
- end
- end
- else
- puts "Not a valid command!"
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment