Python Forum

Full Version: Designing Game Levels (Very Basic)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In an online basic Python course I'm taking, there's a project where I have to create game levels for a typing game (using keyboards and a list of displayed words which the player has to type).

The project includes a module where the game mechanics consists of some functions (typer.py), along with a word bank (word_bank.py) module. I'm required to create at least 3 new functions within the typer.py module.

The game already has (what looks to me like) game levels: Easy, Medium, Hard modes. Each mode has 3 rounds of increasing difficulty (each round consists of words of the same length, but round 1 has only 1 word to type, round 2 has 2 words to type and round 3 has 3 words to type). These are levels, aren't they?

Anyway, the way the above game mechanics is coded is using a for loop (vide infra)

for round in range(1, 4):
    print("Round " + str(round))

    words_to_type = typer.pick_random_words(round, "easy")
    passed = typer.play_round(words_to_type, 10)
    if not passed:
        print("Oops!")
        break

print("Thanks for playing.")
The code in the typer.py module looks like below:
def pick_random_words(num_words, word_length):
    """Returns a random phrase containing the given number of words.""" 
    words = ""
    for word in range(num_words):
        word = get_random_word(word_length)
        words = words + " " + word

    return words.strip()
Couldn't I just replicate this method, use a single for loop to create my levels. That would require only 1 generic function (as we can see above for the rounds). I'm at a loss as to why I should define 3 functions as the instructions in this project say.