repl.it
@RyanCrouch/

Coding Project - Python

Python

No description

fork
loading
Files
  • main.py
  • Highscores.txt
  • Passwords.txt
  • Usernames.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
def print_rules():
 print('\nRules:\n\n1. The points rolled on each players dice are added to their score\n2. If the total is an even number, an additional 10 points are added to the players score\n3. If the total is an odd number, 5 points are subtracted from the players score\n4. If a player rolls double, they get to roll one extra die and get the number of points\nadded to their score\n5. The score of a player cannot go below 0 at any point\n6. The person with the highest score at the end of five rounds wins\n7. If both players have the same score at the end of the five rounds, they each roll 1 die\nand whoever gets the highest score wins (this repeats until someone wins in the case of both players rolling the same number)  ')

def user_login():
 username_verification = False
 password_verification = False
 escape_choice1 = 0
 escape_choice2 = 0

 while username_verification == False:

   escape_choice1 = 0
   open_file1 = open('Usernames.txt', 'r') 
   username_input = input('Please enter your username > ') 
   userpass_verification2 = 0

   for item in open_file1:
     userpass_verification2 += 1
     if str(item) == username_input + "\n":
       username_verification = True

   if username_verification == True:
    print('Username Correct')
   else:
     print('Username Incorrect')
     escape_choice1 = input('Press 1 to try again\nOR\nPress 2 to go back to the main menu > ')

   if escape_choice1 == '1':
     username_verification = False
   elif escape_choice1 == '2':
     return False

   open_file1.close()


 open_file2 = open ('Passwords.txt', 'r')
 
 while password_verification == False:
   escape_choice2 = 0
   open_file2 = open ('Passwords.txt', 'r')
   password_input = input('Please enter your password > ')
   userpass_verification1 = 0
   
   for item in open_file2:
     userpass_verification1 += 1
     if item == password_input + '\n' :
       password_verification = True

   if password_verification == True:
     print('Password Correct')
   else:
     print('Password Incorrect')
     escape_choice2 = input('Press 1 to try again\nOR\nPress 2 to go back to the main menu > ')

     if escape_choice2 == '1':
       password_verification = False
     elif escape_choice2 == '2':
       return False

   open_file2.close()


 if username_verification and password_verification == True and userpass_verification1 == userpass_verification2:
   login_verification1 = True
 else:
   login_verification1 = False

 return login_verification1

def user_registration():
 
 username_open = open('Usernames.txt', 'a')
 username_creation = input('\nPlease input the username you want (this \ncannot be changed, so choose carefully) > ')
 username_open.write(username_creation + '\n')
 username_open.close()
 
 password_open = open('Passwords.txt', 'a')
 password_creation = input('\nPlease input the password you want (this \ncannot be changed, so choose carefully) > ')
 password_open.write(password_creation + '\n')
 password_open.close()

 return True

def show_highscores():
 
 highscores_open = open('Highscores.txt', 'r')

 highscores = highscores_open.read()

 print('\n' + highscores)

 return True

def game():
 player_one = input('Please enter your desired nickname > ')
 player_two = input('Please enter your desired nickname > ')
 
 loop_to_five = 0
 player_one_total = 0
 player_two_total = 0
 
 while loop_to_five < 5:
   input('\n' + player_one + ', press enter to roll > ')
  
   player_one_roll = random.randint(1,6)
   if player_one == 'god':
     if player_one_roll <= 10000000000000000000000000000000:
       player_one_roll += 1901375797956917
  
   player_one_roll2 = random.randint(1,6)
   if player_one == 'god':
     if player_one_roll2 <= 5:
       player_one_roll2 += 1 
   player_one_roll_total = int(player_one_roll) + int(player_one_roll2)
  
   player_one_roll = str(player_one_roll)
   player_one_roll2 = str(player_one_roll2)
  
   print('\n' + player_one + ' rolled a ' + player_one_roll + ' and a ' + player_one_roll2 + ' which totals to ' + str(player_one_roll_total))

   if player_one_roll_total == 2:
     player_one_roll_total += 10
   if player_one_roll_total == 4:
     player_one_roll_total += 10
   if player_one_roll_total == 6:
     player_one_roll_total += 10
   if player_one_roll_total == 8:
     player_one_roll_total += 10
   if player_one_roll_total == 10:
     player_one_roll_total += 10
   if player_one_roll_total == 12:
     player_one_roll_total += 10
   if player_one_roll_total == 3:
     player_one_roll_total = player_one_roll_total - 5
   if player_one_roll_total == 5:
     player_one_roll_total = player_one_roll_total - 5
   if player_one_roll_total == 7:
     player_one_roll_total = player_one_roll_total - 5
   if player_one_roll_total == 9:
     player_one_roll_total = player_one_roll_total - 5
   if player_one_roll_total == 11:
     player_one_roll_total = player_one_roll_total - 5


   player_one_total += player_one_roll_total


   if player_one_roll == player_one_roll2:
     print('\n' + player_one + ' rolled a double')
     input('\n' + player_one + ', press enter to roll > ')
     player_one_roll3 = random.randint(1,6)
     if player_one == 'god':
       if player_one_roll3 <= 5:
         player_one_roll3 += 1
     player_one_total += player_one_roll3
   
   print('\n' + player_one + ', your total score is ' + str(player_one_total))
   if 0 > player_one_total:
     player_one_total = 0


   input('\n' + player_two + ', press enter to roll > ')
  
   player_two_roll = random.randint(1,6)
   if player_two == 'god':
     if player_two_roll <= 5:
       player_two_roll += 1
  
   player_two_roll2 = random.randint(1,6)
   if player_two == 'god':
     if player_two_roll2 <= 5:
       player_two_roll2 += 1 
   player_two_roll_total = int(player_two_roll) + int(player_two_roll2)
  
   player_two_roll = str(player_two_roll)
   player_two_roll2 = str(player_two_roll2)
  
   print('\n' + player_two + ' rolled a ' + player_two_roll + ' and a ' + player_two_roll2 + ' which totals to ' + str(player_two_roll_total))

   if player_two_roll_total == 2:
     player_two_roll_total += 10
   if player_two_roll_total == 4:
     player_two_roll_total += 10
   if player_two_roll_total == 6:
     player_two_roll_total += 10
   if player_two_roll_total == 8:
     player_two_roll_total += 10
   if player_two_roll_total == 10:
     player_two_roll_total += 10
   if player_two_roll_total == 12:
     player_two_roll_total += 10
   if player_two_roll_total == 3:
     player_two_roll_total = player_two_roll_total - 5
   if player_two_roll_total == 5:
     player_two_roll_total = player_two_roll_total - 5
   if player_two_roll_total == 7:
     player_two_roll_total = player_two_roll_total - 5
   if player_two_roll_total == 9:
     player_two_roll_total = player_two_roll_total - 5
   if player_two_roll_total == 11:
     player_two_roll_total = player_two_roll_total - 5

   player_two_total += player_two_roll_total  

   print('\n' + player_two + ', your total score is ' + str(player_two_total))

   loop_to_five += 1
 
 print('\n' + player_one + ' scored ' + str(player_one_total))
 print('\n' + player_two + ' scored ' + str(player_two_total))

 if player_one_total == player_two_total:
   print('\n')
   print('It is a draw!')
 elif player_one_total > player_two_total:
   print('\n')
   print(player_one + ' wins!')
 elif player_one_total < player_two_total:
   print('\n')
   print(player_two + ' wins!')
 if 0 > player_two_total:
   player_two_total = 0
 
 
 return True

def top5():
  highscores_open = open('Highscores.txt', 'r')
  score1 = highscores_open.readline()
  score2 = highscores_open.readline()
  score3 = highscores_open.readline()
  score4 = highscores_open.readline()
  score5 = highscores_open.readline()
  print(score1)
  print(score2)
  print(score3)
  print(score4)
  print(score5)
  score1length = len(score1)
  score2length = len(score2)
  score3length = len(score3)
  score4length = len(score4)
  score5length = len(score5)
  print(score1length)
  print(score2length)
  print(score3length)
  print(score4length)
  print(score5length)
  
  
  
  
  
  
  
  return

#########################################MAIN CODE#########################################
import random
loop2 = 0
loop1 = 0
login_check = 0
login = False
number1 = 0
print('Dice Game')
while login_check == 0:
 while loop1 == 0:
   login_question = input('\n\nDo you have an existing account? >')
   if login_question[0] == 'y' or login_question[0] == 'Y':
     login = user_login()
     loop1 = 1
     number1 = 1
     register1 = True
   elif login_question[0] == 'n' or login_question[0] == 'N':
     register = user_registration()
     loop1 = 1
     number1 = 0
     register1 = False
   else:
     print('Please answer either yes or no')
     loop1 = 0

 if number1 == 1:
   if login == True:
     print('You have successfully logged in')
     login_check = 1
   elif login == False:
     print('Login failed, try again')
     login_check = 0
     loop1 = 0
 
 if register1 == False:
   if register == True:
     print('\nYou have successfully created an account')
     login_check = 1
   else:
     print('Registration failed, try again')
     login_check = 0

while loop2 == 0:
 main_menu = input('\nWelcome to The Dice Game\nPress S to start a game\nPress R to show the rules\nPress H to show highscores\n > ')
 if main_menu == 'r' or main_menu == 'R':
   print_rules()
   loop2 = 0
 elif main_menu == 'h' or main_menu == 'H':
   show_highscores = show_highscores()
   loop2 = 0
 elif main_menu == 's' or main_menu == 'S':
   game = game()
Fetching token
?