|
Simple Word Game |
This game is simple, fun, and can be expanded with more words or more complex rules to keep it challenging and engaging!
Code Explanation:
1. Comment:
This comment briefly describes the program as a simple word scramble game.
2. Array Declaration:
Declares an array word_list$ with 5 elements to store the words that will be scrambled.
3. Populate Word List:
Each element of the word_list$ array is assigned a word that will be used in the game. The words are apple, banana, grape, orange, and strawberry.
4. Score Initialization:
Initializes the score variable to 0. This variable will track the player's score throughout the game.
5. Start of Game:
Indicates the start of the main game logic.
6. Welcome Message:
Prints a welcome message to the player, introducing the game.
7. Game Instructions:
Prints instructions explaining that the player needs to unscramble words to score points. A hint option is mentioned, though it is not implemented in this version of the code.
8. Loop Through Words:
Starts a loop that iterates through the words in the word_list$ array. The loop runs 5 times, once for each word.
9. Select Word:
In each iteration of the loop, the word$ variable is assigned the current word from the word_list$ array.
10. Scramble Word:
Calls the scramble_word routine, passing the current word (word$) to it. The scrambled version of the word is returned and stored in the scrambled$ variable.
11. Initialize Hint Counter:
Initializes hint_used to 0 for the current round. This variable tracks whether a hint is used (not implemented in this version).
12. Display Scrambled Word:
Prints the scrambled version of the word for the player to see.
13. Player Input:
Prompts the player to enter their guess for the unscrambled word. The player's guess is stored in the guess$ variable.
14. Check Guess:
Converts both the player's guess (guess$) and the original word (word$) to lowercase using lcase$ to ensure the comparison is case-insensitive. If they match, the player guessed correctly.
15. Correct Guess Message:
If the guess is correct, prints a congratulatory message.
16. Update Score:
Updates the player's score by adding 10 points. If hints were used (not implemented here), the score would be reduced by 2 points per hint.
17. Incorrect Guess Condition:
If the player's guess is incorrect, this block is executed.
18. Incorrect Guess Message:
Prints a message informing the player that their guess was incorrect and reveals the correct word.
19. End of Guess Check Block:
Ends the conditional block that checks whether the player's guess was correct or incorrect.
20. Display Score:
Prints the player's current score after each round.
21. Next Word:
Ends the loop iteration and moves to the next word in the word_list$ array.
22. End of Game:
After all 5 words have been played, the game prints a message saying "Game over!" and displays the player's final score. The stop statement ends the program.
23. Scramble Word Routine:
Defines a private routine named scramble_word. It takes a word (word$) as input and returns the scrambled version of the word (scrambled$).
24. Get Word Length:
Calculates the length of the word using len(word$) and stores it in the len variable.
25. Initialize Scrambled Word:
Initializes the scrambled$ variable with the original word (word$). The scrambling process will modify this variable.
26. Scrambling Loop:
Starts a loop that iterates over each character in the word.
27. Get Character:
Extracts the character at position idx in scrambled$ and stores it in ch$.
28. Generate Random Index:
Generates a random index within the length of the word using rnd(len) and stores it in random_idx.
29. Get Random Character:
Extracts the character at the random_idx position in scrambled$ and stores it in temp$.
30. Swap Characters:
Swaps the character at position idx with the character at random_idx.
31. Complete Swap:
Completes the swap by placing the original idx character (stored in ch$) at the random_idx position.
32. Next Character:
Ends the loop iteration and moves to the next character in the word.
33. End of Scramble Routine:
Ends the scramble_word routine.
34. End Program:
Ends the program execution.
|
Hide Description
|
|
|
Enter or modify the code below, and then click on RUN |
|
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |