Guest User

Untitled

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