DEV Community

Komal Gilani
Komal Gilani

Posted on

Python 100 Days Challange: Day 6 Project Reeborg Maze Game

Expanding upon the concepts we covered on Day 6 of the 100-day Python course, where we delved into fundamental concepts like if/else conditions, loops (both for and while), and function declarations, we now have the opportunity to apply this knowledge to create an interactive game using Reeborg's World and Python. On Day 6, we honed our skills by crafting code for challenges such as Hurdle 1-4 and a complex Maze, culminating in a comprehensive final project.

To embark on this game-building journey with Reeborg's World, we must first establish a foundation by defining essential functions that will enable Reeborg the Robot to navigate through its environment effectively:

Turning 90 Degrees: We can command Reeborg to turn 90 degrees using the turn_left() function.

Turning Right: Achieving a right turn can be accomplished by executing the turn_left() command three times.

Moving Forward: To make forward progress, we employ the move() function.

Conditional Checks: Utilizing if/else conditions, we can determine whether the path ahead is clear or obstructed by a wall. We can also identify if there's a wall to the right.

While Loop: Incorporating a while loop allows us to execute instructions repeatedly until a specific goal is attained, ensuring that Reeborg reaches its destination as required by the game's mechanics.

Here is the code for the Maze Project:

`def turn_around():
    turn_left()


def turn_right():
    turn_left()
    turn_left()
    turn_left()

def maze():
    if right_is_clear():
        turn_right()
        move()
    elif front_is_clear():
        move()
    else:
        turn_left()

def jump_until():    # for hurdle 4 game --to handle dyanmic wall size ...change loop to try give it a try
    turn_left()
    while wall_on_right():
        move()
    turn_right()
    move()
    turn_right()
    while front_is_clear():
        move()
    turn_left()

while not at_goal():  #maze game
   maze()

`

Enter fullscreen mode Exit fullscreen mode

Top comments (0)