Created
February 20, 2024 05:08
-
-
Save ehlzi/7912288b09f83ffb618fcd931cdab655 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Module main() | |
| // Declare variables to store the user's choice, the computer's choice, and the winner | |
| Declare String userChoice, computerChoice, winner | |
| Declare Integer randomNumber | |
| // Main game loop | |
| Do | |
| // Generate a random number between 1 and 3 for the computer's choice | |
| randomNumber = GenerateRandomNumber(1, 3) | |
| computerChoice = ConvertNumberToChoice(randomNumber) | |
| // Get the user's choice | |
| Display "Choose 'rock', 'paper', or 'scissors': " | |
| Input userChoice | |
| // Display the computer's choice | |
| Display "The computer chose ", computerChoice | |
| // Determine the winner | |
| winner = DetermineWinner(userChoice, computerChoice) | |
| // Display the result | |
| If winner = "tie" Then | |
| Display "It's a tie, play again." | |
| Else | |
| Display "The winner is ", winner | |
| End If | |
| Loop While winner = "tie" | |
| End Module | |
| Function String ConvertNumberToChoice(Integer number) | |
| // Convert the random number to the corresponding choice | |
| Select number | |
| Case 1: | |
| Return "rock" | |
| Case 2: | |
| Return "paper" | |
| Case 3: | |
| Return "scissors" | |
| End Select | |
| End Function | |
| Function String DetermineWinner(String userChoice, String computerChoice) | |
| // Determine the winner based on the rules of the game | |
| If userChoice = computerChoice Then | |
| Return "tie" | |
| Else If (userChoice = "rock" And computerChoice = "scissors") Or (userChoice = "scissors" And computerChoice = "paper") Or (userChoice = "paper" And computerChoice = "rock") Then | |
| Return "user" | |
| Else | |
| Return "computer" | |
| End If | |
| End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment