Code Monkey home page Code Monkey logo

odin-hangman's Introduction

odin-hangman

Toy command line Hangman game implemented with ruby using OOP and mixins. Includes I/O serialization/deserialization for saving and loading game state. πŸ‘‰Live demoπŸ‘ˆ.

Background

Example Game - With Saving

  +---+ β–ˆβ–ˆβ•—  β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•—
  |   | β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β• β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•‘
  O   | β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘
 /|\  | β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘
 / \  | β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•‘
      | β•šβ•β•  β•šβ•β•β•šβ•β•  β•šβ•β•β•šβ•β•  β•šβ•β•β•β• β•šβ•β•β•β•β•β• β•šβ•β•     β•šβ•β•β•šβ•β•  β•šβ•β•β•šβ•β•  β•šβ•β•β•β•
========================================================================


Enter any key to continue.


Menu:
    1: Play new game
    2. Continue last game
    3: Help/How to play
    4: Quit
3

R U L E S:  How to Play Hangman
    a. The computer picks a word of length N from the dictionary at random.
    b. The player must guess that word, which is comprised of letters from the alphabet (characters from a-z).
    c. The player gets at most 6 guesses to guess the correct word.
    d. The player may guess individual letters, or whole words.
    e. To guess whole words, precede the input with a '-w' flag.
    f. For example, to guess the word 'supercalifragilisticexpialidocious', enter:

         -w supercalifragilisticexpialidocious

    g. Have fun!
      

Menu:
    1: Play new game
    2. Continue last game
    3: Help/How to play
    4: Quit
1
New game selected!


  +---+
  |   |
      |
      |
      |
      |
=========
Guesses: 
_ _ _ _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
e

  +---+
  |   |
  O   |
      |
      |
      |
=========
Guesses: e
_ e _ _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
a

  +---+
  |   |
  O   |
  |   |
      |
      |
=========
Guesses: e, a
_ e a _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
-w dean
User enetered a word: ["dean"]

  +---+
  |   |
  O   |
 /|   |
      |
      |
=========
Guesses: e, a, dean
d e a n

Player wins!

Wins:1, Losses: 0
Computer chose a word: hans

Menu:
    1: Continue playing
    2. Save game
    3: Quit
1

  +---+
  |   |
      |
      |
      |
      |
=========
Guesses: 
_ _ _ _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
h

  +---+
  |   |
  O   |
      |
      |
      |
=========
Guesses: h
h _ _ _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
n

  +---+
  |   |
  O   |
  |   |
      |
      |
=========
Guesses: h, n
h _ n _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
o

  +---+
  |   |
  O   |
 /|   |
      |
      |
=========
Guesses: h, n, o
h _ n _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
e

  +---+
  |   |
  O   |
 /|\  |
      |
      |
=========
Guesses: h, n, o, e
h _ n _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
a

  +---+
  |   |
  O   |
 /|\  |
 /    |
      |
=========
Guesses: h, n, o, e, a
h a n _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
s

  +---+
  |   |
  O   |
 /|\  |
 / \  |
      |
=========
Guesses: h, n, o, e, a, s
h a n s 

Player wins!

Wins:2, Losses: 0
Computer chose a word: lyrics

Menu:
    1: Continue playing
    2. Save game
    3: Quit
2
#<Serializer:0x00007f2faf324660>
Successfully saved game...
**Excited R2D2 noises**

Menu:
    1: Continue playing
    2. Save game
    3: Quit
3

Exiting game. Bye!

Example Game - With Loading

  +---+ β–ˆβ–ˆβ•—  β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•—
  |   | β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β• β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•‘
  O   | β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘
 /|\  | β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘
 / \  | β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•‘
      | β•šβ•β•  β•šβ•β•β•šβ•β•  β•šβ•β•β•šβ•β•  β•šβ•β•β•β• β•šβ•β•β•β•β•β• β•šβ•β•     β•šβ•β•β•šβ•β•  β•šβ•β•β•šβ•β•  β•šβ•β•β•β•
========================================================================


Enter any key to continue.


Menu:
    1: Play new game
    2. Continue last game
    3: Help/How to play
    4: Quit
2
Load saved game selected!

Successfully loaded game...
**Excited R2D2 noises**

  +---+
  |   |
      |
      |
      |
      |
=========
Guesses: 
_ _ _ _ _ _ _ _ _ _ _ _ _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
i

  +---+
  |   |
  O   |
      |
      |
      |
=========
Guesses: i
i _ _ _ _ _ _ _ _ i _ _ _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
n

  +---+
  |   |
  O   |
  |   |
      |
      |
=========
Guesses: i, n
i n _ _ _ _ _ _ _ i _ n _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
-w intelligence
User enetered a word: ["intelligence"]

  +---+
  |   |
  O   |
 /|   |
      |
      |
=========
Guesses: i, n, intelligence
i n _ _ _ _ _ _ _ i _ n _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
o

  +---+
  |   |
  O   |
 /|\  |
      |
      |
=========
Guesses: i, n, intelligence, o
i n _ _ _ _ _ _ _ i o n _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
a

  +---+
  |   |
  O   |
 /|\  |
 /    |
      |
=========
Guesses: i, n, intelligence, o, a
i n _ _ a _ _ a _ i o n _ 

Enter a single letter A-Z, or a word using the -w flag: -w <your word>.
-w installations
User enetered a word: ["installations"]

  +---+
  |   |
  O   |
 /|\  |
 / \  |
      |
=========
Guesses: i, n, intelligence, o, a, installations
i n s t a l l a t i o n s

Player wins!

Wins:3, Losses: 0
Computer chose a word: blues

Menu:
    1: Continue playing
    2. Save game
    3: Quit
2
#<Serializer:0x00007f0151adad00>
Successfully saved game...
**Excited R2D2 noises**

Menu:
    1: Continue playing
    2. Save game
    3: Quit
3

Exiting game. Bye!

Future Improvements

  • Add option to save and query multiple save states
  • Add score/leaderboard
  • Add option to add words to the dictionary

odin-hangman's People

Contributors

kckuei avatar

Watchers

 avatar

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.