Code Monkey home page Code Monkey logo

java-hangman's Introduction

java-hangman

A very basic Hangman game written in java. I made this project after "learning" Java in 5 days. It tooks like 2 hours to implement and write documentation. The game itself have just one word "HANGMAN" to guess, you can change the word by editing the main.java file variable theWord. It perform basic operations:

  • display a number of _ equals to the word length;
  • ask the user an input, it the user write a word (different from "quit" or "exit") the first character is checked;
  • the user have a total of 5 attempt;
  • if the letter is inside the word a message will be displayed and the _ in position of letter are replaced with actual letter;
  • if the letter is not inside the word a message will be displayed informing the player that the letter is not in the word and display the number of attempt left;
  • if the letter is not (or it is) inside the word and the user already tried this letter a message will inform that he will have no penalties and display number of attempt left;
  • if the user write "quit" / "exit" or just press enter without any input the game will quit, with a message informing that the game is over;
  • if the user have no more attempt the game will quit, with a message informing that the game is over;
  • if the user guess all the letter the game will quit, informing the user that he found the word.

logic

  • I used a char[] to represent the word. All letters and the user input are converted to their capitalized form .
  • I used a Set< Character > to store the guessed letters and a Set< String > containing QUIT and EXIT to control if the player want to quit.
  • I used a Map< Character, List< Integer > > that is populated with letters[... list of index] to speed up the control avoiding array cycle that are slower than looking inside a HashMap, when a letter is inside the map it just change the char[index] retrieved from the HashMap List, to replace the _ with actual letter.
  • When a letter is founded it is removed from map. When the map.size() is zero all letters have been found.

java-hangman's People

Contributors

matteoprat 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.