Exerpad
🔥 0
0 XP
Exercise 1 · Chapter: BounceRequired+50 XP

Set It Up

Before anything can bounce, it needs to remember which way it's going.

Write new_game() so it returns a state with:

  • "x" starting at 5
  • "dx" starting at 1

Then make update move by state["dx"] instead of a hard-coded 1.

Nothing bounces yet — the dot just walks right. But the direction now lives in the state, which is the thing that makes bouncing possible at all.

Expected output
6/1 7/1 8/1 9/1
Need a hint?
3 available · costs 5 XP each
python
def new_game():
# Return a state with "x" at 5 and "dx" at 1.
return {}


def update(state, keys):
state["x"] = state["x"] + 1
return state


def draw(state):
grid = blank_grid()
grid[6][state["x"]] = "red"
return grid