Open avantika0001 opened 1 year ago
Here's an example of a Rock, Paper, Scissors game implemented using the Turtle graphics library in Python: import turtle import random
screen = turtle.Screen() screen.title("Rock, Paper, Scissors") screen.bgcolor("white")
player_turtle = turtle.Turtle() player_turtle.color("blue") player_turtle.shape("turtle") player_turtle.penup() player_turtle.goto(-100, 0)
computer_turtle = turtle.Turtle() computer_turtle.color("red") computer_turtle.shape("turtle") computer_turtle.penup() computer_turtle.goto(100, 0)
def play_game():
player_choice = screen.textinput("Rock, Paper, Scissors", "Choose: rock, paper, or scissors").lower()
# Generate a random choice for the computer
choices = ["rock", "paper", "scissors"]
computer_choice = random.choice(choices)
# Move the turtles
player_turtle.forward(100)
computer_turtle.forward(100)
# Display the choices
player_turtle.write(player_choice.capitalize(), align="center", font=("Arial", 16, "bold"))
computer_turtle.write(computer_choice.capitalize(), align="center", font=("Arial", 16, "bold"))
# Determine the winner
if player_choice == computer_choice:
result = "It's a tie!"
elif (player_choice == "rock" and computer_choice == "scissors") or \
(player_choice == "paper" and computer_choice == "rock") or \
(player_choice == "scissors" and computer_choice == "paper"):
result = "You win!"
else:
result = "Computer wins!"
# Display the result
result_turtle = turtle.Turtle()
result_turtle.color("green")
result_turtle.penup()
result_turtle.goto(0, -100)
result_turtle.write(result, align="center", font=("Arial", 24, "bold"))
result_turtle.hideturtle()
play_game()
turtle.exitonclick()
In this code, we use the Turtle library to create two turtles representing the player and the computer. The turtles move forward to indicate the choice made by each. The player is prompted to choose rock, paper, or scissors using the textinput function from the Turtle screen. The computer generates a random choice. The turtles write the choices on the screen, and the winner is determined based on the game logic. Finally, the result is displayed using another turtle. The game ends when you click on the screen.
Can this issue be assigned to me under gssoc 2023
@1e9abhi1e10 Do i start working on this issue? or should i make any further improvements?
Go Ahead @codewithavantika
Aim
Details