Python Forum
Designing Game Levels (Very Basic)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Designing Game Levels (Very Basic)
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help in designing a timestamp finder for chapter-less TV shows Daring_T 1 2,405 Oct-26-2020, 09:30 PM
Last Post: Daring_T
  Designing a "game" loop api pitosalas 2 3,265 Jun-07-2020, 03:20 PM
Last Post: pitosalas
  Parse XML - how to handle deep levels/hierarchy dwill 8 13,238 Apr-17-2018, 04:17 PM
Last Post: dwill
  Relative import multiple levels ? Windspar 3 5,459 Feb-02-2018, 11:55 PM
Last Post: Windspar
  Designing Hangman game spacetimeguy 2 6,100 Feb-02-2018, 08:55 PM
Last Post: spacetimeguy
  Need help designing a multi-threaded solver 4Dummies 8 7,432 Jun-18-2017, 08:39 PM
Last Post: 4Dummies

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020