Project 6

Number Guessing

Guessing numbers is pretty simple, but what happens when the person giving you clues isn’t telling the truth? In this project, you’ll write code in which the computer picks a number and the player tries to guess the number in the fewest moves.

This project introduces a new way to start to organize your code. You’ll learn more about objects and classes, which give you a way to store data and methods together in a way that helps you think more clearly about the problem you’re trying to solve. In the number guessing game, you’ll start by simply splitting the program into the player part and the game part.

image

Organizing a New Project

You’ll use Atom to create and edit your source code, and you’ll store this project in a single Ruby file. You’ll use the terminal program to run and play the number guessing game.

remember If you haven’t created a development folder already, refer to Project 2 for instructions.

Follow these steps to set up your source code directory and file for this project:

  1. Start your terminal program and enter the development folder:

    $ cd development

  2. Create a new directory for this project:

    $ mkdir project06

  3. Move in to the new directory:

    $ cd project06

  4. Start Atom by double-clicking its icon.
  5. Create a new source code file by choosing File ⇒ New ...

Get Ruby For Kids For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.