Search for '{{search_term}}'

Exercise: Improve Number guessing game

CMOS is the Code-Maven Open Source podcast that also includes video interviews. Subscribe to this feed RSS feed with your Podcast listener app or via iTunes iTunes.

This is an extension of the Number guessing game exercise.

This exercise has several steps.

First of all, let the user guess several times (with responses each time), until she finds the hidden number.

Allow various special keys too:

  • n - skip the rest of this game (give up) and start a new game with new hidden number.
  • s - show the hidden value (cheat).
  • m - toggle: turn on/off move mode: When the move mode is on, after every guess the number can change by 2 in either direction.
  • d - toggle: turn on / off debug mode. In debug mode show the hidden number every time before you are asked to supply the guess.
  • x - exit

Now I can tell you that this is actually a 1 dimensional space fight. The number is your distance from the enemy space ship.

For training purposes limit the outer space to be between 0-200 so even when the move mode is on the space-ship won't fly off this area.

Finaly, keep track of the minimum and maximum score (number of guesses till hit) in a file.

Tools

Solutions

Comments

In the comments, please wrap your code snippets within <pre> </pre> tags and use spaces for indentation.
comments powered by Disqus