-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode
More file actions
48 lines (40 loc) · 1.51 KB
/
Copy pathCode
File metadata and controls
48 lines (40 loc) · 1.51 KB
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
#ROCK PAPER SISSORS BY LOUIS TDLT
#No Image version
import random
import pygame
from pygame.locals import *
pygame.init()
# Event loop
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
exit()
if event.type == MOUSEBUTTONDOWN:
mouse_position = pygame.mouse.get_pos()
if scissors_rect.collidepoint(mouse_position):
print("You chose scissors")
if paper_rect.collidepoint(mouse_position):
print("You chose paper")
if rock_rect.collidepoint(mouse_position):
print("You chose rock")
# Get user and computer actions
user_action = input("Enter a choice (rock, paper, scissors): ")
while user_action not in ["rock", "paper", "scissors"]:
print("Invalid input")
user_action = input("Enter a choice (rock, paper, scissors): ")
computer_action = random.choice(["rock", "paper", "scissors"])
print(f"\nYou chose {user_action}, computer chose {computer_action}.\n")
# Determine the winner
if user_action == computer_action:
print("It's a tie!")
elif user_action == "rock":
if computer_action == "scissors":
print("You win! Rock beats scissors.")
else:
print("You lose! Paper beats rock.")
elif user_action == "paper":
if computer_action == "rock":
print("You win! Paper beats rock.")
else:
print("You lose! Scissors beats paper.")