SHOW:
|
|
- or go back to the newest paste.
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 | - | puts "What is your username?" |
15 | + | |
16 | - | usern = gets.chomp.downcase |
16 | + | |
17 | - | passwd = user_info[usern.to_sym] |
17 | + | |
18 | ||
19 | while login == false | |
20 | puts "What is your username?" | |
21 | usern = gets.chomp.downcase | |
22 | - | if input == passwd then |
22 | + | passwd = user_info[usern.to_sym] |
23 | - | puts "Welcome #{usern}!" |
23 | + | |
24 | - | login = true |
24 | + | |
25 | puts "Enter password: " | |
26 | - | puts "Incorrect password." |
26 | + | |
27 | ||
28 | if input == passwd then | |
29 | puts "Welcome #{usern}!" | |
30 | login = true | |
31 | ||
32 | else | |
33 | ||
34 | puts "Incorrect password." | |
35 | end | |
36 | - | puts "Enter a password:" |
36 | + | |
37 | - | new_passw = gets.chomp |
37 | + | |
38 | - | user_info[new_usern.to_sym] = new_passw |
38 | + | |
39 | - | puts "Registration complete!" |
39 | + | |
40 | ||
41 | - | puts "Username already exists!" |
41 | + | |
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 | - | case |
65 | + | |
66 | - | when command == "new" |
66 | + | |
67 | puts "-- delete" | |
68 | - | new_game = gets.chomp |
68 | + | |
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 | - | when command == "list" |
80 | + | |
81 | games[new_game.to_sym] = new_rating.to_i | |
82 | puts "Successfully added new game!" | |
83 | puts | |
84 | ||
85 | - | when command == "edit" |
85 | + | |
86 | puts "Game already exists!" | |
87 | puts | |
88 | ||
89 | end | |
90 | ||
91 | - | if games[edit_game.to_sym].nil? |
91 | + | when "list" |
92 | - | puts "That game doesn't exist!" |
92 | + | |
93 | puts "#{game.to_s}: #{score}" | |
94 | - | elsif edit_game == "back" |
94 | + | |
95 | ||
96 | when "edit" | |
97 | - | puts "Enter a new rating: (1 - 10)" |
97 | + | |
98 | puts "#{game}: #{score}" | |
99 | - | games[edit_game.to_sym] = new_rating.to_i |
99 | + | |
100 | - | puts "Updated successfully!" |
100 | + | |
101 | edit_game = gets.chomp | |
102 | ||
103 | if games[edit_game.to_sym].nil? | |
104 | - | when command == "logout" |
104 | + | puts "That game doesn't exist!" |
105 | puts | |
106 | ||
107 | elsif edit_game == "back" | |
108 | puts | |
109 | - | if sure == "yes" |
109 | + | |
110 | - | login = false |
110 | + | else |
111 | - | logout = false |
111 | + | puts "Enter a new rating: (1 - 10)" |
112 | - | elsif sure == "no" |
112 | + | new_rating = gets.chomp |
113 | - | logout = false |
113 | + | games[edit_game.to_sym] = new_rating.to_i |
114 | - | break |
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 |