Code Monkey home page Code Monkey logo

hangman-challenge's Introduction

hangman-challenge

Make Hangman in Ruby.

Assumed knowledge:

  • Basic understanding of the terminal (bash/cmd)
  • Some knowledge of Ruby and programming concepts (variables, arrays, loops, if/else, etc)
  • Basic understanding of git (enough to clone this repo)

If anything in that list above is totally foreign to you, fear not! You can either try your hand at the guessing game challenge (which is still to be written), or pair program with someone who has more experience. If in doubt, ask for someone to help you on Slack.

Our end goal in this challenge is to create Hangman on the command line. There are quite a few different parts involved in that.

A key skill in programming is the ability to break down problems into smaller, more achievable steps. To help with that, I've outlined a series of iterations. Try getting each section to work before moving on to the next.

Getting started

You should clone this repository. You can do that by running git clone https://github.com/Railsn00bs/hangman-challenge. If you're Github savvy, I'd suggest forking this repo and cloning your own fork down. If you're unsure about how to clone a repo, ask for help on Slack.

Open up hangman.rb in the text editor of your choice. You'll notice a line of code that pulls a random word out of words.txt and assigns it to the variable word_to_guess.

Try adding puts word_to_guess at the end of the file and run ruby hangman.rb.

Hopefully, you'll see a random word and the program will quit.

Iteration 1 (displaying the word initially)

We should print out an underscore for each letter in the word to guess. For example, if the word to guess was "art", we should display this to the user:

Word to guess: _ _ _

Stuck? Click here for help!

Iteration 2 (guessing)

We should ask the user to guess a letter. If the letter they guess is in our word, we should reveal it. We should loop over these two steps

Stuck? Click here for help!

Iteration 3 (lives)

The user should start out with 7 lives.

We should display their lives remaining before each guess.

When the user guesses a letter, if their guess is incorrect, they should lose a life.

Stuck? Click here for help!

Iteration 4 (winning and losing)

If the user guesses all the letters in a word, they should be told they've won the game, and the program should end.

If the user has no lives remaining, they should be informed they've been hung and the program should exit.

Stuck? Click here for help!

Iteration 5 (make it pretty)

It's important for our programs to have a quality user interface. As such, our program should display a text based view of hangman. To help out with this I've provided a series of fantastic text based depictions of a cruel spelling related execution. Put them to use!

art = [
  <<-ART
/----
|   |
|
|
|
|
--------
  ART,
  <<-ART
/----
|   |
|   O
|
|
|
--------
  ART,
  <<-ART
/----
|   |
|   O
|   |
|
|
--------
  ART,
  <<-ART
/----
|   |
|   O
|  /|
|
|
--------
  ART,
  <<-ART
/----
|   |
|   O
|  /|\\
|
|
--------
  ART,
  <<-ART
/----
|   |
|   O
|  /|\\
|  /
|
--------
  ART,
  <<-ART
/----
|   |
|   O
|  /|\\
|  / \
|
--------
  ART
]

You can copy that into your application. You can print out the first image with puts art[0]. Feel free to make your own ascii art as well!

Stuck? Click here for help!

Stretch goals

There are lots of fine details to get right. For example, what happens when...

  • You enter a couple of letters as a guess
  • You enter a number as a guess
  • You guess the same letter over and over again
  • You enter nothing

Refactoring

Take a look at your code. Are you happy with it? Is it beautiful?

Is it clear what each part of the code does? Are the variable names long and descriptive? Polish your code up.

Code Review

Time to get some feedback. Push your code up and post it on the slack community, and get feedback from your fellow Railsn00bs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.