# bash hangman lolol



## whoadamn (May 3, 2009)

```
#! /bin/bash
# Finally givin' this hangman thang a shot :D
# Usage: hangman -r OR -n

# Reminder: Change _ _ _ _ to _ e _ t, if you know wat im sayin, foo'
# Reminder completed... allll right

##Modifyable vars
PS3='HMAN>'

##Initialize according to arguments
ng=0
case $1 in
    "-r")
        word=`head -1 hangman.clist`
        if [ -z $word ]; then
        rm -f hangman.clist
        cp hangman.list hangman.clist
        fi    
        ;;
    "-n") 
        word=`head -1 hangman.list`
        rm -f hangman.clist
        cp hangman.list hangman.clist    
    ;;
    *)
        echo "Invalid argument specified. Usage: `basename $0` -r OR -n" 1>&2
        exit 1
    ;;
esac
unset $tbuff

function drawguy {
    case $1 in
        6)
            echo "-____-----"
            echo "|----|----"
            echo "|---------"
            echo "|---------"
            echo "|---------"
            echo "|---------"
            ;;
        5)
            echo "-____-----"
            echo "|----|----"
            echo "|----O----"
            echo "|---------"
            echo "|---------"
            echo "|---------"
            ;;    
        4)
            echo "-____-----"
            echo "|----|----"
            echo "|----O----"
            echo "|----|----"
            echo "|---------"
            echo "|---------"
            ;;    
        3)
            echo "-____-----"
            echo "|----|----"
            echo "|----O----"
            echo "|----|\---"
            echo "|---------"
            echo "|---------"
            ;;
        2)
            echo "-____-----"
            echo "|----|----"
            echo "|----O----"
            echo "|---/|\---"
            echo "|---------"
            echo "|---------"
            ;;
        1)
            echo "-____-----"
            echo "|----|----"
            echo "|----O----"
            echo "|---/|\---"
            echo "|-----\---"
            echo "|---------"
            ;;
        0)
            echo "-____-----"
            echo "|----|----"
            echo "|----O----"
            echo "|---/|\---"
            echo "|---/-\---"
            echo "|---------"
            ;;
    esac
return
}

function editor {
    if [ -n $1 ]; then
        case $1 in
            ## Adds WORD to top of hangman.list
            "addtop") 
            tbuff=`cat hangman.list`
            tbuff=`echo -e "$2\n$tbuff"`
            echo "$tbuff" > hangman.list
            ;;
            "addbottom") 
            tbuff=`cat hangman.list`
            tbuff=`echo -e "$tbuff\n$2"`    
            echo "$tbuff" > hangman.list
            ;;            
            "removetop")
            lc=`wc -l < hangman.list`
            let lc=$lc-1
            tbuff=`tail -$lc hangman.list`
            echo "$tbuff" > hangman.list
            ;;
            "removebottom")
            lc=`wc -l < hangman.list`
            let lc=$lc-1
            tbuff=`tail -$lc hangman.list`
            echo "$tbuff" > hangman.list
            ;;
            "removespecified")
            if [ $2 -ne 1 ]; then
                if [ $2 -ne `wc -l < hangman.list` ]; then
            tlc=$2
            let tlc=$tlc-1
            blc=`wc -l < hangman.list`                        
            let blc=$blc-$2            
            ttbuff=`head -$tlc hangman.list`            
            btbuff=`tail -$blc hangman.list`            
            rm -f hangman.list
            echo -e "$ttbuff\n$btbuff" > hangman.list        
            unset $ttbuff
            unset $btbuff
                else editor "removebottom"
                fi
            else editor "removetop"
            fi            
            ;;            
            ## Shifts hangman.clist            
            "shift")
            lc=`wc -l < hangman.clist`
            let lc=$lc-1
            tbuff=`tail -$lc hangman.clist`
            rm -f hangman.clist        
            echo "$tbuff" > hangman.clist
            ;;
            "restart")
            rm -f hangman.clist
            cp hangman.list hangman.clist
            ;;
            "list")
            cat -n hangman.list
            if [ ! -z $2 ]; then
            if [ $2 = "noget" ]; then
            sleep 0
            fi
            else read
            fi
            ;;
            "clist")
            cat hangman.clist
            read            
            ;;
            *) echo "Function Editor: Invalid argument specified." 1>&2; exit 1            
            ;;    
        esac
        unset $tbuff
else echo "Function Editor: No mode specified." 1>&2; exit 1
fi
}
        

function game {
    lives=6
    #Word(character)Count
    wcount=${#word}
    let wcount=$wcount-1    
    guess=
    #CorrectGuess
    cguess=$word
    ditch=0
    while [ $ditch -ne 1 ]; do
        clear
        if [ $lives -ge 0 ]; then
            drawguy $lives
            echo ${word//[! _$guess]/' _'}     
            echo "You have guessed:$guess"
            echo -n $PS3; read

            if [ ${#REPLY} -gt 1 ]; then
                echo "1 character limit." 1>&2
            else
                if [ "$REPLY" = "_" ]; then
                    echo "Invalid character." 1>&2
                else        
                    guess="$guess $REPLY"
                    #MatchCount
                    mcount=`echo $cguess | grep -o "$REPLY" | wc -l`
                    #UnderscoreCount                    
                    ucount=`echo $cguess | grep -o _ | wc -l`
                    if [ $mcount -eq 0 ]; then
                        let lives=$lives-1
                    else
                        if [ $ucount -eq $wcount ]; then
                            break
                        else
                            cguess=${cguess//$REPLY/_}
                        fi
                    fi            
                fi
            fi    
        else
            echo "Sorry, you lose..."
            rm -f hangman.clist; cp hangman.list hangman.clist
            exit        
        fi
    done
    editor "shift"
    word=`head -1 hangman.clist`
    if [ -z $word ]; then
        word=`head -1 hangman.list`
        rm -f hangman.clist; cp hangman.list hangman.clist
    fi    
    echo "Congratulations! You win!"
}
ditch=0
tmp=$1
while [ $ditch -ne 1 ]; do
clear
echo "Welcome to Hangman v1.0!"
echo -e "------------------------\n"
echo -n "Current mode: "
case $tmp in
    "-r") echo "Continuing game"
    echo -e `wc -l < hangman.clist` "words remaining\n"
    ;;
    "-n") echo "New game"
    ;;
esac

select option in "Play game" "Editor" "Exit"; do
    case $option in
    "Play game") if [ $tmp = "-r" ]; then
    game "-r"
    else game
    tmp="-r"
    fi;;
    "Editor")
    editch=0
    while [ $editch -eq 0 ]; do
    clear
    echo "Hangman list Editor"
    echo -e "-------------------\n"
    select eoption in "Modify list" "Shift current list" "Restart current list" "Display lists" "Return to Main Menu"; do
        case $eoption in
        "Modify list")
        clear
        editor "list" "noget"
        echo ""
        select aoption in "Add top" "Add bottom" "Remove top" "Remove bottom" "Remove specified"; do
            case $aoption in
            "Add top")
            echo -n "Word>"; read
            editor "addtop" $REPLY
            ;;
            "Add bottom")
            echo -n "Word>"; read
            editor "addbottom" $REPLY
            ;;
            "Remove top")
            editor "removetop"
            ;;
            "Remove bottom")
            editor "removebottom"
            ;;
            "Remove specified")
            echo -n "Line>"; read
            editor "removespecified" $REPLY
            ;;
            esac
        break        
        done
        ;;
        "Shift current list") editor "shift"
        ;;
        "Restart current list") editor "restart"
        ;;
        "Display lists")
        clear
        select doption in "Display main list" "Display current list"; do
            case $doption in
                "Display main list")
                echo "Main list"
                echo -e "---------\n"
                editor "list"
                ;;
                "Display current list")
                echo "Current list"
                echo -e "------------\n"        
                editor "clist"
                ;;
            esac
        break
        done
        ;;            
        "Return to Main Menu")
        editch=1        
        ;;        
        esac
    break    
    done
    done    
    ;;
    "Exit")
    exit 0
    ;;
    esac
    break    
done
done
exit 0
```
it may be highly dysfunctional, choppy and unorganized but it fkn works >:C


----------



## Irreverent (May 3, 2009)

Whoadamn....outside.....NOW!

See that big glowy thing?  Its called the Sun.  Now go get some fresh air. :razz:


----------



## whoadamn (May 3, 2009)

SWEET JESUS
http://www.nrl.navy.mil/NewsRoom/images/sun.jpg


----------



## LizardKing (May 3, 2009)

I saw 'bash hangman' and thought it was hangman based on bash.org >_>


----------



## whoadamn (May 3, 2009)

mwaha.


----------



## Irreverent (May 3, 2009)

whoadamn, can you resize that pic to 400x400...its huge and frigging up the layout.


----------



## whoadamn (May 3, 2009)

That was the point 
However, the link acts as the perfect intermediary between the "SWEET JESUS" and the resolution


----------



## Liam (May 3, 2009)

Another reason to use linux.
How long have you been working on this?


----------



## whoadamn (May 3, 2009)

like 2 days lol, i just went back to fedora like a week ago and i made it my goal to get a hang of the shell.

after learning c, c++ and the winapi, i found learning other languages is generally just a matter of syntax 

and seriously, linux is the shit.


----------



## pheonix (May 3, 2009)

I lol'd. Why? 2 whole days! Why!?!? XD


----------



## Eevee (May 3, 2009)

whoadamn said:


> after learning c, c++ and the winapi, i found learning other languages is generally just a matter of syntax


Then you're looking at uneducational languages.

Look at an imperative language not based so directly on C, like Python.

Look at a functional language, like Haskell or Standard ML or LISP.

Look at an esoteric language, like Brainfuck.

Look at an assembly language.

Look at a language with a lot of built-in features, like Perl.

Look at a logic language, like Prolog.

Look at a pure OO language, like Smalltalk.


----------



## whoadamn (May 3, 2009)

Eevee said:


> Then you're looking at uneducational languages.
> 
> Look at an imperative language not based so directly on C, like Python.
> 
> ...


workin on it



pheonix said:


> I lol'd. Why? 2 whole days! Why!?!? XD


because im just beginning to get familiar with linux..


----------



## pheonix (May 3, 2009)

whoadamn said:


> because im just beginning to get familiar with linux..



Okay that's understandable. what's linux like? 

<---uses vista >.>


----------



## LizardKing (May 4, 2009)

Eevee said:


> Look at an esoteric language, like Brainfuck



Oh god...


----------



## ToeClaws (May 4, 2009)

Nice, though I agree with Irre - get ye outdoors!


----------



## Eevee (May 4, 2009)

pheonix said:


> Okay that's understandable. what's linux like?
> 
> <---uses vista >.>


it is great



LizardKing said:


> Oh god...


http://git.veekun.com/?p=project-euler.git;a=blob;f=heteroglot/005.bf;hb=HEAD


----------



## Rayne (May 4, 2009)

Eevee said:


> http://git.veekun.com/?p=project-euler.git;a=blob;f=heteroglot/005.bf;hb=HEAD



Oh god...


----------



## pheonix (May 4, 2009)

Eevee said:


> it is great



Next laptop I get I'm trashing vista for linux. I'm sick of windows at this point. >.< It should be a fun experience being I've never used linux. Are there computers in stores that have it as it's default OS?


----------



## Eevee (May 5, 2009)

uh, occasionally.  I think Dell still sells a few machines with Ubuntu pre-installed, but I have no idea beyond that.


----------



## pheonix (May 5, 2009)

Eevee said:


> uh, occasionally.  I think Dell still sells a few machines with Ubuntu pre-installed, but I have no idea beyond that.



Thanks, I'll keep my eyes open next time I'm out shopping around.


----------



## CaptainCool (May 5, 2009)

the netbooks with smal flash drives use linux most of the time as well i guess


----------



## whoadamn (May 8, 2009)

Eevee said:


> http://git.veekun.com/?p=project-euler.git;a=blob;f=heteroglot/005.bf;hb=HEAD



the thought crossed my mind "i should look into algorithms" quickly followed by "i should get my gr.12"


----------



## shruthv (Jul 14, 2015)

Hi,

I am trying to use your code. Just wanted to know what are hangman.clist and hangman.list files.
It's an immediate requirement from my end.. any help will be appreciated.
Thank You.


----------

