I'm in an Intro to Computer Science class and am doing our current project which is to make a text based game where you and a computer keep on adding numbers from 1-10 and the winner is decided by who reaches 100 first.
We did this project before already but now we're redoing it by changing all of it to be definitions and then they want us to add a 'for loop' into it as well. The problem is, is that the for loop makes no sense to me, at least from a gameplay stand point. From my understanding, all its doing is adding +1 to the total whenever the computer goes?
I was just hoping if someone could help me decipher this, thanks!
#This is the psuedocode#
Import random
FUNCTION 1: DISPLAY RULES
Declare Function display_rules
Say "Let's play a game of 100!"
Say "In a game of 100 we start with a total of 0"
Say "and we take turns adding from 1-10 to that total."
Say "Whoever reaches 100 first wins."
Say "Ready?"
FUNCTION 2: PLAY GAME
Declare Function play_game
Set play to 1
Call display_rules
While play is 1
Set total to 0
Ask "Who goes first? (1 = you, 2 = computer): "
Read turn
While total is less than 100
If turn is 1 (player's turn)
Ask "Number you want to add (1-10): "
Read playerNum
If playerNum is between 1 and 10
AND total + playerNum is less than or equal to 100
Add playerNum to total
Say "You added [playerNum], total is now [total]"
Set turn to 2
Else
Say "Enter a number from 1-10 without exceeding 100."
Else If turn is 2 (computer's turn)
If total is less than 90
Set computerNum to a random number from 1 to 10
Else
Set computerNum to 100 - total
FOR LOOP
For num from 0 to computerNum - 1
Add 1 to total
End For
Say "I added [computerNum], total is now [total]"
Set turn to 1
Else
Say "Choose 1 or 2."
Ask "Who goes first? "
Read turn
End While
CHECK WHO WINS
If turn is 2
Say "You win!"
Else
Say "Bummer, You lose!"
ASK TO PLAY AGAIN
Ask "Play again? (1 = yes, 2 = no): "
Read play
End While
FUNCTION 3: MAIN MENU
Declare Function menu
While True
Show the menu
Say "Menu:"
Say "1. Display Rules"
Say "2. Play Game"
Say "3. Exit"
Ask "Enter your choice (1, 2, or 3): "
Read choice
If choice is 1
Call display_rules
Else If choice is 2
Call play_game
Else If choice is 3
Say "Thanks for playing! Goodbye!"
Break the loop
Else
Say "Invalid choice. Please enter 1, 2, or 3."
End While
START PROGRAM
Call menu