Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [source] Hangman Game without using keyboard
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
we64




PostPosted: Sat Jan 24, 2004 9:28 pm   Post subject: [source] Hangman Game without using keyboard

code:

%Text Select
%By Tony Zhang
setscreen ("graphics:1000;650")
var x, y, nx, button, letter : int := 0
var colo : int := 9
var letters1 : array 1 .. 10 of string := init ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")
var letters2 : array 1 .. 10 of string := init ("K", "L", "M", "N", "O", "P", "Q", "R", "S", "T")
var letters3 : array 1 .. 6 of string := init ("U", "V", "W", "X", "Y", "Z")
var words : array 1 .. 15 of string := init ("computer", "speaker", "program", "video", "cat", "dog", "tiger", "driver", "soccer", "radio", "music", "science", "math", "basketball", "chess")
var random, counter, right : int := 0
var word, choice, let : string := ""
colourback (71)
cls

process won
    choice := "n"
    for w : 1 .. 100
        Draw.Text ("YaY, You won!", maxx div 2 - 100, maxy div 2, Font.New ("serif:24:bold"), Rand.Int (1, 100))
        delay (100)
        exit when choice not= "n"
    end for
end won

process lost
    choice := "n"
    for l : 1 .. 100
        Draw.Text ("You Lost!", maxx div 2 - 50, maxy div 2 - 50, Font.New ("serif:24:bold"), Rand.Int (155, 200))
        Draw.Text ("The word was:", maxx div 2 - 150, maxy div 2, Font.New ("serif:24:bold"), Rand.Int (155, 200))
        Draw.Text (words (random), maxx div 2 + 60, maxy div 2, Font.New ("serif:24:bold"), Rand.Int (155, 200))
        delay (100)
        exit when choice not= "n"
    end for
end lost

loop
    %Title
    Draw.Text ("Welcome to Tony's Hangman Game", maxx div 2 - 150, maxy - 20, Font.New ("serif:16:bold"), 40)

    %Question
    locate (3, 1)
    put "Please choose letters from the alphabets"

    %Hang
    drawfillbox (640, 170, 660, 410, 112)     %post
    drawfillbox (660, 390, 760, 410, 112)
    drawfillbox (600, 160, 800, 180, 115)     %ground
    drawfillbox (730, 390, 740, 358, 114)     %wire
    drawarc (735, 345, 13, 13, 0, 360, 114)

    %Random Words and Dashes
    randint (random, 1, 15)
    var dash : array 1 .. length (words (random)) of string
    for a : 1 .. length (words (random))
        dash (a) := "_"
    end for

    %Keyboard
    for a : 1 .. 10
        %First Row
        drawbox (90 + nx, 250, 140 + nx, 300, black)
        drawfillbox (95 + nx, 255, 135 + nx, 295, grey)
        Draw.Text (letters1 (a), 105 + nx, 260, Font.New ("serif:22:bold"), 56)

        %Second Row
        drawbox (90 + nx, 200, 140 + nx, 250, black)
        drawfillbox (95 + nx, 205, 135 + nx, 245, grey)
        Draw.Text (letters2 (a), 105 + nx, 210, Font.New ("serif:22:bold"), 56)

        %Third Row
        if nx >= 100 and nx <= 350 then
            letter += 1
            drawbox (90 + nx, 150, 140 + nx, 200, black)
            drawfillbox (95 + nx, 155, 135 + nx, 195, grey)
            Draw.Text (letters3 (letter), 105 + nx, 160, Font.New ("serif:22:bold"), 56)
        end if
        nx += 50
    end for


    %Out put
    loop
        %Draw Dash
        locate (8, 15)
        for a : 1 .. length (words (random))
            put dash (a) : 3, " " ..
        end for

        %Click
        loop
            if Mouse.ButtonMoved ("down") then
                var buttonnumber, buttonupdown : int
                Mouse.ButtonWait ("down", x, y, buttonnumber, buttonupdown)
                if x >= 95 and x <= 135 and y >= 255 and y <= 295 then
                    let := "a"
                elsif x >= 145 and x <= 185 and y >= 255 and y <= 295 then
                    let := "b"
                elsif x >= 195 and x <= 235 and y >= 255 and y <= 295 then
                    let := "c"
                elsif x >= 245 and x <= 285 and y >= 255 and y <= 295 then
                    let := "d"
                elsif x >= 295 and x <= 335 and y >= 255 and y <= 295 then
                    let := "e"
                elsif x >= 345 and x <= 385 and y >= 255 and y <= 295 then
                    let := "f"
                elsif x >= 395 and x <= 435 and y >= 255 and y <= 295 then
                    let := "g"
                elsif x >= 445 and x <= 485 and y >= 255 and y <= 295 then
                    let := "h"
                elsif x >= 495 and x <= 535 and y >= 255 and y <= 295 then
                    let := "i"
                elsif x >= 545 and x <= 585 and y >= 255 and y <= 295 then
                    let := "j"
                elsif x >= 95 and x <= 135 and y >= 205 and y <= 245 then
                    let := "k"
                elsif x >= 145 and x <= 185 and y >= 205 and y <= 245 then
                    let := "l"
                elsif x >= 195 and x <= 235 and y >= 205 and y <= 245 then
                    let := "m"
                elsif x >= 245 and x <= 285 and y >= 205 and y <= 245 then
                    let := "n"
                elsif x >= 295 and x <= 335 and y >= 205 and y <= 245 then
                    let := "o"
                elsif x >= 345 and x <= 385 and y >= 205 and y <= 245 then
                    let := "p"
                elsif x >= 395 and x <= 435 and y >= 205 and y <= 245 then
                    let := "q"
                elsif x >= 445 and x <= 485 and y >= 205 and y <= 245 then
                    let := "r"
                elsif x >= 495 and x <= 535 and y >= 205 and y <= 245 then
                    let := "s"
                elsif x >= 545 and x <= 585 and y >= 205 and y <= 245 then
                    let := "t"
                elsif x >= 195 and x <= 235 and y >= 155 and y <= 195 then
                    let := "u"
                elsif x >= 245 and x <= 285 and y >= 155 and y <= 195 then
                    let := "v"
                elsif x >= 295 and x <= 335 and y >= 155 and y <= 195 then
                    let := "w"
                elsif x >= 345 and x <= 385 and y >= 155 and y <= 195 then
                    let := "x"
                elsif x >= 395 and x <= 435 and y >= 155 and y <= 195 then
                    let := "y"
                elsif x >= 445 and x <= 485 and y >= 155 and y <= 195 then
                    let := "z"
                end if
                exit when ord (let) > 95
            end if
        end loop

        %Wrong Letter
        if index (words (random), let) = 0 then
            counter += 1
        end if

        %Hangman face
        if counter = 1 then
            drawfilloval (735, 355, 15, 15, 89)
        elsif counter = 2 then
            drawfilloval (728, 357, 3, 3, black)     % left eye
        elsif counter = 3 then
            drawfilloval (742, 357, 3, 3, black)     %right eye
        elsif counter = 4 then
            drawarc (735, 345, 5, 5, 20, 160, black)     %mouth

            %Hangman body
        elsif counter = 5 then
            drawline (735, 340, 735, 280, black)
            Draw.Text ("Help me please!", 795, 330, Font.New ("serif:16:bold"), 40)
        elsif counter = 6 then
            drawline (735, 310, 765, 340, black)     %right arm
            Draw.Text ("Help me please!", 795, 330, Font.New ("serif:16:bold"), 71)
            Draw.Text ("Help me!", 795, 330, Font.New ("serif:16:bold"), 40)
        elsif counter = 7 then
            drawline (735, 310, 705, 340, black)     %left arm

        elsif counter = 8 then
            drawline (735, 280, 765, 250, black)     %right leg
            Draw.Text ("Help me!", 795, 330, Font.New ("serif:16:bold"), 71)
            Draw.Text ("Help! Help!", 795, 330, Font.New ("serif:16:bold"), 40)
        elsif counter = 9 then
            drawline (735, 280, 705, 250, black)     %left leg
        end if

        %Right letter
        for a : 1 .. length (words (random))
            if let = words (random) (a) then
                dash (a) := let
            end if
        end for

        locate (8, 15)
        for a : 1 .. length (words (random))
            put dash (a) : 3, " " ..
        end for

        for a : 1 .. length (words (random))
            right := right + index (dash (a), "_")
        end for

        %Exits
        exit when right = 0
        right := 0
        exit when counter = 9
    end loop

    %Play again
    delay (1000)
    cls
    Draw.Text ("Would you like to play again?", maxx div 2 - 130, maxy - 100, Font.New ("serif:16:bold"), 56)
    drawbox (maxx div 2 - 100, maxy - 250, maxx div 2, maxy - 200, black)
    drawfillbox (maxx div 2 - 95, maxy - 245, maxx div 2 - 5, maxy - 205, grey)
    Draw.Text ("Yes", maxx div 2 - 75, maxy - 235, Font.New ("serif:24:bold"), black)
    drawbox (maxx div 2 + 100, maxy - 250, maxx div 2, maxy - 200, black)
    drawfillbox (maxx div 2 + 95, maxy - 245, maxx div 2 + 5, maxy - 205, grey)
    Draw.Text ("No", maxx div 2 + 30, maxy - 235, Font.New ("serif:24:bold"), black)

    %Choice
    if counter = 9 then
        fork lost
        loop
            if Mouse.ButtonMoved ("down") then
                var buttonnumber, buttonupdown : int
                Mouse.ButtonWait ("down", x, y, buttonnumber, buttonupdown)
                if x >= maxx div 2 - 95 and x <= maxx div 2 - 5 and y >= maxy - 245 and y <= maxy - 205 then
                    choice := "y"
                    exit
                end if
            end if
        end loop
    elsif word = words (random) or right = 0 then
        fork won
        loop
            if Mouse.ButtonMoved ("down") then
                var buttonnumber, buttonupdown : int
                Mouse.ButtonWait ("down", x, y, buttonnumber, buttonupdown)
                if x >= maxx div 2 - 95 and x <= maxx div 2 - 5 and y >= maxy - 245 and y <= maxy - 205 then
                    choice := "y"
                    exit
                end if
            end if
        end loop
    end if

    nx := 0
    letter := 0
    counter := 0
    exit when choice = "n"
    cls
end loop
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: