Newsgroups: comp.databases.informix
Subject: Just For Fun
From: jtibb@rankin.com (Jim Tibbets x143)
Date: 7 Nov 1995 18:48:04 -0500

Hello All,
You know the old "all work and no play" etc etc saying, so here
Ive decided to let you have my Informix-4gl version of the
classic Hangman game.  Cut the .per and .4gl out and save them
as instructed, compile and have a moment of fun.
Add more words later at your leisure if you desire or scoring or
whatever.  You may modify it as you wish as much as you wish.  If
you add something really cool, send me a copy!  This program is completely
free and may be given away and copied as much as you wish.  No warrenties
are expressed or implied of any kind! Use completely at your own risk,
I am not liable for anything at anytime period.
James Tibbets
jtibb@rankin.com
-- 
                       )        \   /        (
                      /|\       )\_/(       /|\
*                    / | \     (/\|/\)     / | \                    *
|\                  /  |  \     \`|'/     /  |  \                  /|
| .________________/___|___o__ __\|/__ __o___|___\________________. |
|  James Tibbets           |^`    V     ^|`  Suite 1286             |
|  Application Engineer                      Phoenix, Arizona 85029 |
|  Rankin Technology Group                   Phone:(602) 997-6996   |
|  2432 West Peoria Avenue                   Fax:  (602) 997-4256   |
| ._______________________________________________________________. |
|/             |    /\ /      \\            \ /\    |             \ |
*              |  /   V        ))            V   \  |              *
               |/             //                   \|
                              V

---------------- Cut and save as hangman.per -----------------------------
{#####################################################################
# Copyright (C) 1994 Rankin Technology Group Inc. Phoenix, AZ
# All rights reserved.
# Use, modification, duplication, and/or distribution of this
# software is limited by the software license agreement.
# Sccsid:  %Z%  %M%  %I%  Delta: %G%
######################################################################
# Screen Generator version: 4.10.UC1 }

DATABASE formonly

SCREEN
{
---------------------------------------------

                      -------
                     |      |
                            |
                            |
                            |
                            |
                            |
                    ----------------

  Letter:[A]
---------------------------------------------
}

ATTRIBUTES
A = formonly.guess, upshift,
     comments = "Enter a letter to guess.";

INSTRUCTIONS
screen record s_screen (formonly.guess)

delimiters "  "
--------------- Cut ------------------------------------------------------

---------------- Cut and save as hangman.4gl -----------------------------
######################################################################
# Copyright (C) 1994 Rankin Technology Group Inc. Phoenix, AZ
# All rights reserved.
# Use, modification, duplication, and/or distribution of this
# software is limited by the software license agreement.
# Sccsid:  %Z%  %M%  %I%  Delta: %G%
######################################################################
# hangman.4gl 1.0 Written 11/02/95 by James Tibbets Rankin Technology Group.
# This is an Informix-4gl version of Hangman.
# Maybe in the future add scoring, more words...clean up, etc etc...
#

globals
    define
      x smallint,
      y smallint,
      open_scr char(1),
      num_let_guess smallint,
      letter_guess char(1),
      got_letter smallint,
      a_word char(15),
      word_lngth smallint,
      num_wrong smallint,
      g_word array[26] of record
          old_word char(1)
      end record,
      init_prep char(1),
      word_selected array[15] of record
          sel_flag smallint
      end record
end globals

main
    call start_hangman()
end main

######################################################################
function start_hangman()
######################################################################
#
#
    #_init
    initialize init_prep to null
    let x = 1
    let y = 1
    for x = 1 to 26
        initialize g_word[x].* to null
    end for
    let num_wrong = 0
    let word_lngth = 0
    let got_letter = false
    call set_word()
    call guess()

end function
# start_hangman()

######################################################################
function set_word()
# sets the word to be guessed
######################################################################
#  In the future add more words.
#
    #_define_var - Define local variables
    define
        cur_time datetime hour to second,
        tmp_time char(8)

    let cur_time = time
    let tmp_time = cur_time

    case
      when tmp_time[8] = 1
        let a_word = "WIN"
        let word_lngth = length(a_word)
      when tmp_time[8] = 2
        let a_word = "ELEPHANT"
        let word_lngth = length(a_word)
      when tmp_time[8] = 3
        let a_word = "RANDOM"
        let word_lngth = length(a_word)
      when tmp_time[8] = 4
        let a_word = "COMPUTER"
        let word_lngth = length(a_word)
      when tmp_time[8] = 5
        let a_word = "FISH"
        let word_lngth = length(a_word)
      when tmp_time[8] = 6
        let a_word = "POPCORN"
        let word_lngth = length(a_word)
      when tmp_time[8] = 7
        let a_word = "ORANGE"
        let word_lngth = length(a_word)
      when tmp_time[8] = 8
        let a_word = "MONKEY"
        let word_lngth = length(a_word)
      when tmp_time[8] = 9
        let a_word = "HOUSE"
        let word_lngth = length(a_word)
      when tmp_time[8] = 0
        let a_word = "BUILDING"
        let word_lngth = length(a_word)
      otherwise
        let a_word = "OTHERWISE"
        let word_lngth = length(a_word)
    end case

end function
# set_word()
######################################################################
function disp_clue()
######################################################################
#
    #_define_var - Define local variables
    define
        x smallint,
        y smallint

    #_init
    let x = 0
    let y = 2

    for x = 1 to word_lngth
        display "=" at  11, y
        let y = y + 1
    end for

end function
# disp_clue()

######################################################################
function guess()
# returns guess
######################################################################
#
    #_define_var - Define local variables
    define
        letter_guess char(1)

    #_open_window
    if open_scr is null
    then
        open window selwin1 at 5, 16 with 16 rows, 45 columns
                attribute (border, blue)

        #_display_parameters
        display "Hangman" at 2, 20

        #_open_form
        open form sel_screen1 from "hangman"
        display form sel_screen1

        let open_scr = "Y"
    end if

    #_disp_clue
    call disp_clue()

    #_input
    input letter_guess without defaults from s_screen.guess

    #_before_input
    before input

    #_after_field
    after field guess
        call check_guess(letter_guess) returning got_letter
        if not got_letter
        then
            call wrong_guess(letter_guess)
            let letter_guess = " "
            display letter_guess to s_screen.guess
            next field s_screen.guess
            continue input
        else
            if not word_complete()
            then
                let letter_guess = " "
                display letter_guess to s_screen.guess
                next field s_screen.guess
                continue input
            end if
        end if

    #_after_input
    after input
      #_interrupt
      # if they hit del, break all the way out
      if int_flag = 1
      then
          exit program(1)
      end if

    #_end_input
    end input

    #_close_window
    close form sel_screen1
    close window selwin1

end function
# guess()

######################################################################
function check_guess(letter)
# checks for the guess in a_word
######################################################################
#

    #_define_var - Define local variables
    define
        letter char(1),
        stat smallint,
        the_word array[15] of record
            word_char char(1)
        end record,
        x smallint,
        y smallint

    #_init
    let x = 0
    let y = 0
    let stat = false
    for x = 1 to word_lngth
        initialize the_word[x].* to null
    end for
    let x = 0
    for x = 1 to word_lngth
        let the_word[x].word_char = a_word[x]
    end for

    if init_prep is null
    then
        let x = 0
        for x = 1 to word_lngth
            let word_selected[x].sel_flag = false
        end for
        let init_prep = "Y"
    end if

    #_set_stat
    let x = 0
    for x = 1 to word_lngth
        if letter not matches a_word[x] and word_selected[x].sel_flag = false
        then
            let word_selected[x].sel_flag = false
            let stat = false
        else
            if letter matches a_word[x] and word_selected[x].sel_flag = false
            then
                let stat = true
                exit for
            end if
        end if
    end for

    #_disp_letters_correct
    if stat = true
    then
        let x = 0
        for x = 1 to word_lngth
            if letter = the_word[x].word_char
            then
                let y = x + 1
                display letter at 10,y
                let word_selected[x].sel_flag = true
            end if
        end for
    end if

    #_return
    return stat

end function
# check_guess()

######################################################################
function word_complete()
######################################################################
#
    #_define_var - Define local variables
    define
        x smallint

    #_init
    let x = 0
    let num_let_guess = 0

    for x = 1 to word_lngth
        if word_selected[x].sel_flag = true
        then
            let num_let_guess = num_let_guess + 1
        end if
    end for

    if num_let_guess = word_lngth
    then
        call you_win()
    else
        return false
    end if

end function
# word_complete()

######################################################################
function you_win()
######################################################################
#
    display "**You Win!!**" at 13, 26 attribute (reverse)
    sleep 3
    #_clear_screen
    display "             " at 13,26
    display "                    " at 14,26
    display "                    " at 5,1
    display "                    " at 10,1
    display " " at 7, 22
    display " " at 8, 22
    display " " at 9, 22
    display "  " at 8, 21
    display " " at 8, 23
    display " " at 10, 21
    display "  " at 10, 23
    display "              " at 11,1
    call start_hangman()

end function
# you_win()

######################################################################
function wrong_guess(letter_guess)
######################################################################
#

    #_define_var - Define local variables
    define
        n smallint,
        letter_guess char(1)

    #_init
    let n = 0
    let num_wrong = num_wrong + 1

    case
      when num_wrong = 1
        display "O" at 7, 22
      when num_wrong = 2
        display "|" at 8, 22
      when num_wrong = 3
        display "|" at 9, 22
      when num_wrong = 4
        display "\\" at 8, 21
      when num_wrong = 5
        display "/" at 8, 23
      when num_wrong = 6
        display "/" at 10, 21
      when num_wrong = 7
        display "\\" at 10, 23
    end case

    let g_word[y].old_word = letter_guess
    let y = y + 1
    for n = 1 to y
        display g_word[n].old_word at 5,n
    end for

    if num_wrong = 7
    then
        display "You Lose!!" at 13, 26
        display "Word Was: " ,a_word at 14,26 attribute (reverse)
        sleep 3
        #_clear_screen
        display "          " at 13,26
        display "                    " at 14,26
        display "                    " at 5,1
        display "                    " at 10,1
        display " " at 7, 22
        display " " at 8, 22
        display " " at 9, 22
        display "  " at 8, 21
        display " " at 8, 23
        display " " at 10, 21
        display "  " at 10, 23
        display "              " at 11,1
        call start_hangman()
    end if

end function
# wrong_guess()
--------------- Cut ------------------------------------------------------
