SlideShare a Scribd company logo
CS3 Project                   - HANGMAN
Objective:

    r    Create a Hangman console game
    o    Create a console application that allows the user to add/delete words to be used in the game

Deadline:

    r    Second week of January 2011 (first meeting of the week)

Other details:

    o    Lab pairings will be in effect.
    o    I   will give you the entire 1" week of January to do this but you might want to start during the
         brea k
    o    There will be 2 modules so you can work independently at the start then combine the modules
         at the end or work on both modules together.
    o    The emphasis will be handling inputs through console and external file     a-s   well as proper error
         handling.
    o    For any questions, email me at: paolo.santos@pshs.edu.ph or paolo.niccolo.santos@gmail.com



lnstructions:

    1.   Create a menu that displays:


         1. Manage Word Library
         2. Play Hdngman
         J. tlx] f,

         >l
    2.   When L is selected, the user is directed to module 1 (See next page).
    3.   When 2 is selected, the user is directed to module 2 (See page 3).
    4.   Selecting 3 ends the program.
Module 1: Creating the Word Library (File Reading/Writing Module)

     L.   Start by manually creating a text file containing the default list of words (each word
          separated by a new line). Name it wordlist.txt. The file should look like this:

          Merry
          Christmas
          Rudolph the red nosed reindeer



     2.   At the start of the module, load all the words into an array of Strings
     3.   Then, display the following menu:


          1. Display word library
          2. Add a word
          3. Delete a word
          4. Save current list
          5. Exit
     4.   When f. is selected, print the entire array of words.
     5.   When 2 is selected, prompt the user for a word then add it to the array.
     6.   When 3 is selected, print the entire array of words in this manner:


          I.   Merry
          2.   Christmas
          3.   Rudolph the red nosed reindeer



          Then prompt the user for a NIJMBER. Delete the word that corresponds to that number
          (example if the user enters 1, delete Merry from the array).


     7.   When 4 is selected, save the words contained in the array to wordlist.txt
     8.   When 5 is selected, return the user to the previous menu.
Module 2: Creating the game (Console Inputs Module)

        1.   You will need the file HangmanWord.java (located at the end of this document) for this
             module.
        2.   Start with an arrav of words and use the random class to generate a random number to
             randomly pick a word from the list.
        3.   Once a word is selected, you now need to transform it into a HangmanWord
                 a. To create a HangmanWord, simply input the String into the constructor:
                       new HangmanWord(<String value>);
                 b.    How to use a HangmanWord Object:
                           i.    When the object is created, it automatically geneterates a String that
                                 contains the blanks of the word. Meaning if you entered new
                                 HangmanWord("hello"), it generates "           ".
                                                                         ----
                           ii.   To output the String of blanks, use the outputBlanksfl function.
                          iii.   You can use the use the guess(char letter)or guess(String letter)function to
                                 guess a letter that is contained in the word. lt outputs true if the letter is
                                 contained in the word, false otherwise. lt is CASE SENSITIVE. lf the letter is
                          .      contained in the word, the blank is replaced by the letter.
                          iv.    Calling the isGuessed0 function returns true if the word is successfully
                                 guessed, and false otherwise.
        4.   OnCe yOu've made       your hangman wOrd, set hOw many "lives" your user has tO guess the
             word.
        5.   Output the blanks

                                                               (example the word is snowman)

        6.   Prompt the user for an input (either String or char)
             >s
        7.   Use the guessfl     function of the HangmanWord o.bject
                 a.    lf it returns true, output the blanks


                 b.    lf it returns false, subtract a "life" from the user then output the blanks
                 c.    lf the word is fully guessed (no more blanks)go back to 1.
                 d.    lf the user is out of lives, output the word then go back to the main menu.
    '            e,    lf the user is not out of lives and the word still contains blanks, go back to 5.
public cfass Hanqmanword {
    private String inword;
    nriv,atc Strino outword;
     nri vafe i nt I etters I eft;

    nrrl.rlin       llanam:nfaTnrd/af   Vvgl4rrY
                                                    rina       r^rnrrl   t

             inword : word;
             outword : "";
             Ietters feft : 0;
             for(int i:0;     i < word.IengthO; i++;1
                  1f((word.charAt(i):: ' ') I | (word.charAt(i):= '. ',                                    I   I


                    (word.charAt(i):: ', ') | I (word.charAt(i):: 'e'1 |                               t


                    (word.charAt(i)::'l')   | I (word.charAt(i):: "")   |                              l


                    (word.charAt (i)::'"  )){
                       outword : outv/ord + word.charAt(i) ;
                  ) else {
                     outword : outword         ;
                     Ietters_left++;
                          )

                ]
     )


    public boofean giress (char letLer)                                       {

       boofean hasletter : false;
        for(int i = 0; i < inword.lengtho; i++11
             if ( (lnword. charAt (i) := letter) && (outword. charAt (i) :: '_')                                   )i
                   outhrord: outword.substring(0,i) + fetter +
                                                         outword. substri-ng ( i+1, outword. lenqth ( ) ) ;
                              L--T                   *     +vr,^.
                              IIOJ!V ^tt^, LgI
                                        L
                              letters_left--;

                ]


         .   return has{.etter;
     t
     t


     pub-Iic boo}ean guess (St ring letter ) {
             if(letter.lengthO    != 1) t
                   SysLem.out.println ("lnvalid guess. ")                           ;
                    return false;
                ]


             boolean hasLetter : false;
             for(int i:0;        i < inword.lengthO; i++11
                  if  ( (Ietter.equals (inword.substring(i, i+1) ) )                          &&
                     ("_".equals (outword. substring (i,i+t1 ; I 1                       1




                       outword : outword. substring (0, i) + fetter +
                              outword. substring (i+1, outword. length ( ) ) ;
                              hasLetter : true;
                              fetters_left--;
/

                                                                                       -


            return hasLetter;
    )



    public void seLWorl (String word)          {

        inword : word;
        outword : "";
             letters_left : O;
            for(int   i = 0; i < word.lengthO; i++11
                    if((word.charAt(i):= ' ') ll (word.charAt-(i)::'.')       ll
                            (word.charAt(i):= ', ', I I (word.charAt(i):: '?') i
                                                                               i


                            (word.charAt(i):= ttt; ll (word.charAt(i):: "'t, 1l
                            (word'charAt (i)::' " ) ) {
                      outword: outword + word.charAt(i) ;
                 l else   1


                    outword : outword + "_" ;
                    f ette rs_le ft ++;
                      l
            I
    )


    n'ht in qts,,n^ ^rll-^ufBlanks()       {

         String   out : tr tt -

            for(int i:0;    i < outworcl.lengthO; i++;1
                 our : our + outword. charAt (i) + rr II'
            )



            return out. trin   (   )   ;
        )



    public boolean isGuessedO {
        return (letters left- :: 0);
        l




                                                                                   5

More Related Content

PDF
Python idiomatico
PDF
Os Goodger
PPSX
Programming with Python
PPTX
FUNDAMENTALS OF PYTHON LANGUAGE
PDF
Learn 90% of Python in 90 Minutes
PDF
The Swift Compiler and Standard Library
PPTX
Pythonppt28 11-18
PPTX
Introduction to the basics of Python programming (part 1)
Python idiomatico
Os Goodger
Programming with Python
FUNDAMENTALS OF PYTHON LANGUAGE
Learn 90% of Python in 90 Minutes
The Swift Compiler and Standard Library
Pythonppt28 11-18
Introduction to the basics of Python programming (part 1)

What's hot (20)

PDF
Python unit 2 M.sc cs
PDF
Python
PPSX
DITEC - Programming with Java
PDF
Python for text processing
ODP
An Intro to Python in 30 minutes
PDF
Ad hoc Polymorphism using Type Classes and Cats
PPSX
DISE - Windows Based Application Development in Java
PDF
AmI 2015 - Python basics
PDF
Python introduction
PPTX
ODP
Introduction to Python - Training for Kids
PDF
Protocols with Associated Types, and How They Got That Way
PPTX
Learn python in 20 minutes
PPTX
Introduction to the basics of Python programming (part 3)
PDF
Python Puzzlers - 2016 Edition
PPTX
Python language data types
PDF
Functional concepts in C#
PPTX
Python 101++: Let's Get Down to Business!
PDF
Python Tutorial
Python unit 2 M.sc cs
Python
DITEC - Programming with Java
Python for text processing
An Intro to Python in 30 minutes
Ad hoc Polymorphism using Type Classes and Cats
DISE - Windows Based Application Development in Java
AmI 2015 - Python basics
Python introduction
Introduction to Python - Training for Kids
Protocols with Associated Types, and How They Got That Way
Learn python in 20 minutes
Introduction to the basics of Python programming (part 3)
Python Puzzlers - 2016 Edition
Python language data types
Functional concepts in C#
Python 101++: Let's Get Down to Business!
Python Tutorial
Ad

Viewers also liked (20)

PPT
The fall of the empire
PDF
Fil 3 q readings
PDF
Letter science fair
PDF
Physics newton's laws
PDF
Chem lin reg
PDF
Outreach room assignments for lakbay-aral (v2).
XLSX
Upcat sched
PPT
1 july 2011 batch congress
PPT
Ss italian renaissance
PDF
Nat sci minerals part1
PPTX
Exploration
XLSX
Upcat sched
XLSX
Dost application
XLSX
Yearbook grad pic orders
PDF
Cat revised guidelines on tickler formatting (with signatures).
PDF
High Operating Costs
PPT
Tenegen ea prez_0325
PPT
Tenegen tanarszerep 2010_1001
PPT
Multimedia2009 Prez Fodorne
PPT
Változó tanárszerep - XI. E-learning fórum
The fall of the empire
Fil 3 q readings
Letter science fair
Physics newton's laws
Chem lin reg
Outreach room assignments for lakbay-aral (v2).
Upcat sched
1 july 2011 batch congress
Ss italian renaissance
Nat sci minerals part1
Exploration
Upcat sched
Dost application
Yearbook grad pic orders
Cat revised guidelines on tickler formatting (with signatures).
High Operating Costs
Tenegen ea prez_0325
Tenegen tanarszerep 2010_1001
Multimedia2009 Prez Fodorne
Változó tanárszerep - XI. E-learning fórum
Ad

Similar to Cs hangman (20)

PDF
Real World Haskell: Lecture 7
PDF
Main Form Number To Word
PPTX
String.pptxihugyftgrfxdf bnjklihugyfthfgxvhbjihugyfthcgxcgvjhbkipoihougyfctgf...
PPS
String and string buffer
PPTX
String.pptx
PDF
Test string and array
PDF
Hangman with Inheritance
PDF
DOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdf
PPTX
Programing with java for begniers .pptx
PDF
LectureNotes-04-DSA
PPTX
13. Java text processing
PDF
Python assignment 4
PPTX
Java Foundations: Strings and Text Processing
DOCX
Assignment SpecificationsYou must implement a simplified version .docx
PDF
Frequency .java Word frequency counter package frequ.pdf
PDF
Acm aleppo cpc training third session
PPT
PPT
strings.ppt
PDF
変数の型 - Java 演習
Real World Haskell: Lecture 7
Main Form Number To Word
String.pptxihugyftgrfxdf bnjklihugyfthfgxvhbjihugyfthcgxcgvjhbkipoihougyfctgf...
String and string buffer
String.pptx
Test string and array
Hangman with Inheritance
DOES NOT NEED TO BE ANSWERED UNTIL NOV 13thWords AssignmentRober.pdf
Programing with java for begniers .pptx
LectureNotes-04-DSA
13. Java text processing
Python assignment 4
Java Foundations: Strings and Text Processing
Assignment SpecificationsYou must implement a simplified version .docx
Frequency .java Word frequency counter package frequ.pdf
Acm aleppo cpc training third session
strings.ppt
変数の型 - Java 演習

More from iamkim (20)

PDF
Nat Sci - Minerals
DOCX
Batch 2012 schedule of exit interview
DOCX
College test results b2012
PDF
Chem cations
PDF
Chem anions
PDF
Grad ball collections per section(01 28-12)
DOCX
Congratulations to batch 2012 star scholar candidates
DOC
Retreat consent form
DOC
Retreat agreements
PDF
Fil la loba negra
PDF
Fil fray botod
DOC
Dasalan at tocsohan
PDF
Chem ps electrolysis
PDF
Physics waves
PDF
Math 3 hw ps2
DOCX
Memo circular # 4 dtd nov 4, 2011
DOC
Final creative shots hair & makeup evaluation (110211)
DOC
Creative shots hair & makeup evaluation (110211)
PDF
Cat creative marching guidelines
DOCX
Reminders
Nat Sci - Minerals
Batch 2012 schedule of exit interview
College test results b2012
Chem cations
Chem anions
Grad ball collections per section(01 28-12)
Congratulations to batch 2012 star scholar candidates
Retreat consent form
Retreat agreements
Fil la loba negra
Fil fray botod
Dasalan at tocsohan
Chem ps electrolysis
Physics waves
Math 3 hw ps2
Memo circular # 4 dtd nov 4, 2011
Final creative shots hair & makeup evaluation (110211)
Creative shots hair & makeup evaluation (110211)
Cat creative marching guidelines
Reminders

Cs hangman

  • 1. CS3 Project - HANGMAN Objective: r Create a Hangman console game o Create a console application that allows the user to add/delete words to be used in the game Deadline: r Second week of January 2011 (first meeting of the week) Other details: o Lab pairings will be in effect. o I will give you the entire 1" week of January to do this but you might want to start during the brea k o There will be 2 modules so you can work independently at the start then combine the modules at the end or work on both modules together. o The emphasis will be handling inputs through console and external file a-s well as proper error handling. o For any questions, email me at: paolo.santos@pshs.edu.ph or paolo.niccolo.santos@gmail.com lnstructions: 1. Create a menu that displays: 1. Manage Word Library 2. Play Hdngman J. tlx] f, >l 2. When L is selected, the user is directed to module 1 (See next page). 3. When 2 is selected, the user is directed to module 2 (See page 3). 4. Selecting 3 ends the program.
  • 2. Module 1: Creating the Word Library (File Reading/Writing Module) L. Start by manually creating a text file containing the default list of words (each word separated by a new line). Name it wordlist.txt. The file should look like this: Merry Christmas Rudolph the red nosed reindeer 2. At the start of the module, load all the words into an array of Strings 3. Then, display the following menu: 1. Display word library 2. Add a word 3. Delete a word 4. Save current list 5. Exit 4. When f. is selected, print the entire array of words. 5. When 2 is selected, prompt the user for a word then add it to the array. 6. When 3 is selected, print the entire array of words in this manner: I. Merry 2. Christmas 3. Rudolph the red nosed reindeer Then prompt the user for a NIJMBER. Delete the word that corresponds to that number (example if the user enters 1, delete Merry from the array). 7. When 4 is selected, save the words contained in the array to wordlist.txt 8. When 5 is selected, return the user to the previous menu.
  • 3. Module 2: Creating the game (Console Inputs Module) 1. You will need the file HangmanWord.java (located at the end of this document) for this module. 2. Start with an arrav of words and use the random class to generate a random number to randomly pick a word from the list. 3. Once a word is selected, you now need to transform it into a HangmanWord a. To create a HangmanWord, simply input the String into the constructor: new HangmanWord(<String value>); b. How to use a HangmanWord Object: i. When the object is created, it automatically geneterates a String that contains the blanks of the word. Meaning if you entered new HangmanWord("hello"), it generates " ". ---- ii. To output the String of blanks, use the outputBlanksfl function. iii. You can use the use the guess(char letter)or guess(String letter)function to guess a letter that is contained in the word. lt outputs true if the letter is contained in the word, false otherwise. lt is CASE SENSITIVE. lf the letter is . contained in the word, the blank is replaced by the letter. iv. Calling the isGuessed0 function returns true if the word is successfully guessed, and false otherwise. 4. OnCe yOu've made your hangman wOrd, set hOw many "lives" your user has tO guess the word. 5. Output the blanks (example the word is snowman) 6. Prompt the user for an input (either String or char) >s 7. Use the guessfl function of the HangmanWord o.bject a. lf it returns true, output the blanks b. lf it returns false, subtract a "life" from the user then output the blanks c. lf the word is fully guessed (no more blanks)go back to 1. d. lf the user is out of lives, output the word then go back to the main menu. ' e, lf the user is not out of lives and the word still contains blanks, go back to 5.
  • 4. public cfass Hanqmanword { private String inword; nriv,atc Strino outword; nri vafe i nt I etters I eft; nrrl.rlin llanam:nfaTnrd/af Vvgl4rrY rina r^rnrrl t inword : word; outword : ""; Ietters feft : 0; for(int i:0; i < word.IengthO; i++;1 1f((word.charAt(i):: ' ') I | (word.charAt(i):= '. ', I I (word.charAt(i):: ', ') | I (word.charAt(i):: 'e'1 | t (word.charAt(i)::'l') | I (word.charAt(i):: "") | l (word.charAt (i)::'" )){ outword : outv/ord + word.charAt(i) ; ) else { outword : outword ; Ietters_left++; ) ] ) public boofean giress (char letLer) { boofean hasletter : false; for(int i = 0; i < inword.lengtho; i++11 if ( (lnword. charAt (i) := letter) && (outword. charAt (i) :: '_') )i outhrord: outword.substring(0,i) + fetter + outword. substri-ng ( i+1, outword. lenqth ( ) ) ; L--T * +vr,^. IIOJ!V ^tt^, LgI L letters_left--; ] . return has{.etter; t t pub-Iic boo}ean guess (St ring letter ) { if(letter.lengthO != 1) t SysLem.out.println ("lnvalid guess. ") ; return false; ] boolean hasLetter : false; for(int i:0; i < inword.lengthO; i++11 if ( (Ietter.equals (inword.substring(i, i+1) ) ) && ("_".equals (outword. substring (i,i+t1 ; I 1 1 outword : outword. substring (0, i) + fetter + outword. substring (i+1, outword. length ( ) ) ; hasLetter : true; fetters_left--;
  • 5. / - return hasLetter; ) public void seLWorl (String word) { inword : word; outword : ""; letters_left : O; for(int i = 0; i < word.lengthO; i++11 if((word.charAt(i):= ' ') ll (word.charAt-(i)::'.') ll (word.charAt(i):= ', ', I I (word.charAt(i):: '?') i i (word.charAt(i):= ttt; ll (word.charAt(i):: "'t, 1l (word'charAt (i)::' " ) ) { outword: outword + word.charAt(i) ; l else 1 outword : outword + "_" ; f ette rs_le ft ++; l I ) n'ht in qts,,n^ ^rll-^ufBlanks() { String out : tr tt - for(int i:0; i < outworcl.lengthO; i++;1 our : our + outword. charAt (i) + rr II' ) return out. trin ( ) ; ) public boolean isGuessedO { return (letters left- :: 0); l 5