repl.it
@Pythonier/

Rock Paper Scissors

Python

This is a simple rock paper scissors game with added options.

fork
loading
Files
  • main.py
  • scores.txt
  • Packager files
  • poetry.lock
  • pyproject.toml
  • requirements.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
import sys, random, os
from replit import clear
from colors import red, green, yellow, blue, cyan
from time import sleep

def write(string):
  for char in string:
    sys.stdout.write(char)
    sys.stdout.flush()
    sleep(0.05)

clear()

print(cyan('Rock-Paper-Scissors\n'))
write("Have you played before? y/n \n")
start = input("").lower()

if start == 'y':
  input("\nPress Enter:")
else:
  clear()
  print(cyan("How to play:\n"))
  write("This is a simple rock paper scissors game. The goal is to beat the computer in rock, paper, scissors. If you want to see your scores input " +green("s")+ ". If you want to quit enter " + green('q')+ ". Otherwise, just enter " + cyan("rock, paper or scissors."))
  sleep(2)

rounds = 1
wins = 0
losses = 0
ties = 0
clear()
ex = False
while ex == False:
  clear()
  r = random.randint(1,3)
  if r == 1:
    computerChoice = 'scissors'
  elif r == 2:
    computerChoice = 'paper'
  elif r == 3:
    computerChoice = 'rock'
  print(cyan("Round ") + cyan(rounds))
  write("\nEnter Choice:\n")
  print(red('- rock, paper or scissors'))
  print(red('- Enter q for quit'))
  print(red('- Enter s to see scores\n'))
  userChoice = input("")
  userChoice = userChoice.strip()
  
  clear()
  write("Your Choice: " + cyan(userChoice) + "\n")
  userChoice = userChoice.lower()
  if userChoice == 'rock':
    if computerChoice == 'rock':
      write("Computer Choice: " + cyan(computerChoice) + "\n")
      sleep(.05)
      write('Tie!')
      ties += 1
    elif computerChoice == 'paper':
      write("Computer Choice: " + cyan(computerChoice) + "\n")
      sleep(.05)
      write(red('Computer Wins!'))
      losses += 1
    elif computerChoice == 'scissors':
      write("Computer Choice: " + cyan(computerChoice) + "\n")
      sleep(.05)
      write(green('You Win!'))
      wins += 1
  elif userChoice == 'paper':
    if computerChoice == 'rock':
      write("Computer Choice: " + cyan(computerChoice) + "\n")
      sleep(.05)
      write(green('You Win!'))
      wins += 1
    elif computerChoice == 'paper':
      write("Computer Choice: " + cyan(computerChoice) + "\n")
      sleep(.05)
      write('Tie')
      ties += 1
    elif computerChoice == 'scissors':
      write("Computer Choice: " + cyan(computerChoice) + "\n")
      sleep(.05)
      write(red('Computer Wins'))
      losses += 1
  elif userChoice == 'scissors':
    if computerChoice == 'rock':
      write("Computer Choice: " + cyan(computerChoice) + "\n")
      sleep(.05)
      write(red('Computer Wins!'))
      losses += 1
    elif computerChoice == 'paper':
      write("Computer Choice: " + cyan(computerChoice) + "\n")
      sleep(.05)
      write(green('You win!'))
      wins += 1
    elif computerChoice == 'scissors':
      write("Computer Choice: " + cyan(computerChoice) + "\n")
      sleep(.05)
      write('Tie!')
      ties += 1
  elif userChoice == 'q':
    clear()
    sleep(.5)
    score = wins - losses
    print("Do you want to save your score of " + cyan(score)+ " ? y/n")
    save = input("-")
    if save == 'y':
      score = wins - losses
      print("What is your repl.it username?")
      userName = input("")
      with open('scores.txt', 'a') as f:
        f.write(userName + ": " + str(score) + "\n")
    ex = True
  elif userChoice == 's':
    clear()
    print(red("Scores:\n"))
    rounds -= 1 
    print('Rounds Played: ' + cyan(rounds))
    print('Wins: ' + cyan(wins))
    print('Losses: ' + cyan(losses))
    print('Ties: ' + cyan(ties))
    score = wins - losses
    if score > 0:
      print("Score (Wins - Losses): " + green(score))
    elif score < 0: 
      print("Score (Wins - Losses): " + red(score))
    else:
      print("Score (Wins - Losses): " + cyan(score))
    input("\nPress enter to continue: ")
  else: 
    print(red("Invalid, please check your spelling or that you entered a valid choice."))
    sleep(.5)
  
  rounds += 1  
  sleep(1)
clear()
for i in range(1,3):
  print("saving")
  sleep(.5)
  clear()
  print("saving.")
  sleep(.5)
  clear()
  print("saving..")
  sleep(.5)
  clear()
  print("saving...")
  sleep(.5)
  clear()
print(green('Saved'))
?