Guest User

Untitled

a guest
Jun 14th, 2014
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.58 KB | None | 0 0
  1. # Game Rating program with a basic login script v0.01
  2. # Created by Trilient
  3.  
  4. user_info = {
  5.     :trilient => "mypass01",
  6.     :admin => "adminpass"
  7. }
  8.  
  9. program = true
  10. login = false
  11.  
  12. while program == true
  13.  
  14. while login == false
  15. puts "What is your username?"
  16. usern = gets.chomp.downcase
  17. passwd = user_info[usern.to_sym]
  18.  
  19. if passwd then
  20.     puts "Enter password: "
  21.     input = gets.chomp
  22.     if input == passwd then
  23.     puts "Welcome #{usern}!"
  24.     login = true
  25.     else
  26.     puts "Incorrect password."
  27.     end
  28. else
  29.     puts "No such user: #{usern}"
  30.     puts "Would you like to register? (Yes/No)"
  31.         register = gets.chomp.downcase
  32.         if register == "yes"
  33.                 puts "Enter a new username:"
  34.                 new_usern = gets.chomp.downcase
  35.                     if user_info[new_usern.to_sym].nil?
  36.                     puts "Enter a password:"
  37.                     new_passw = gets.chomp
  38.                     user_info[new_usern.to_sym] = new_passw
  39.                     puts "Registration complete!"
  40.                     else
  41.                     puts "Username already exists!"
  42.                     end
  43.         if register == "no"
  44.             puts
  45.         end
  46. end
  47. end
  48.  
  49. while login == true
  50.  
  51. games = {
  52.     :Starcraft => 8,
  53.     :Skyrim => 9,
  54.     :Final_Fantasy_7 => 9
  55. }
  56.  
  57. puts "Welcome #{usern}, here's a list of commands:"
  58. puts "-- new"
  59. puts "-- list"
  60. puts "-- edit"
  61. puts "-- delete"
  62. puts "-- logout"
  63. puts "Please enter a command to continue:"
  64.     command = gets.chomp
  65.     case
  66.     when command == "new"
  67.         puts "Enter a new game to add to the database:"
  68.             new_game = gets.chomp
  69.             if games[new_game.to_sym].nil?
  70.                 puts "What rating would you like to give it?"
  71.                 new_rating = gets.chomp
  72.                 games[new_game.to_sym] = new_rating.to_i
  73.                 puts "Successfully added new game!"
  74.                 puts
  75.             else
  76.                 puts "Game already exists!"
  77.                 puts
  78.             end
  79.            
  80.     when command == "list"
  81.         games.each { |game, score|
  82.             puts "#{game.to_s}: #{score}"
  83.         }
  84.        
  85.     when command == "edit"
  86.         games.each { |game, score|
  87.             puts "#{game}: #{score}"
  88.         }
  89.         puts "Enter the name of a game to edit: (type 'back' to go back)"
  90.             edit_game = gets.chomp
  91.             if games[edit_game.to_sym].nil?
  92.                 puts "That game doesn't exist!"
  93.                 puts
  94.             elsif edit_game == "back"
  95.                 puts
  96.             else
  97.                 puts "Enter a new rating: (1 - 10)"
  98.                 new_rating = gets.chomp
  99.                 games[edit_game.to_sym] = new_rating.to_i
  100.                 puts "Updated successfully!"
  101.                 puts
  102.             end
  103.    
  104.     when command == "logout"
  105.         logout = true
  106.         while logout == true
  107.             puts "Are you sure you want to logout? (Yes/No)"
  108.                 sure = gets.chomp.downcase
  109.                 if sure == "yes"
  110.                     login = false
  111.                     logout = false
  112.                 elsif sure == "no"
  113.                     logout = false
  114.                     break
  115.                 end
  116.         end
  117.     else
  118.         puts "Not a valid command!"
  119.     end
  120.  
  121. end
  122. end
  123. end
Advertisement
Add Comment
Please, Sign In to add comment