Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki Blog Search Turing Chat Room Members
Hangman Game without using keyboard Author Message
we64 Posted: Sun Jan 25, 2004 9:38 am   Post subject: 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
{"ft_lang_label":"__label__en","ft_lang_prob":0.5432133,"math_prob":0.99704087,"size":7336,"snap":"2021-21-2021-25","text_gpt3_token_len":2793,"char_repetition_ratio":0.20662847,"word_repetition_ratio":0.41323906,"special_character_ratio":0.50354415,"punctuation_ratio":0.2362514,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9992478,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-05-06T07:24:13Z\",\"WARC-Record-ID\":\"<urn:uuid:376552c1-7131-473f-bafd-fd3b41d7dbf8>\",\"Content-Length\":\"66477\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:eb490df8-e951-443d-81a0-001156473b98>\",\"WARC-Concurrent-To\":\"<urn:uuid:c3d488c5-607d-4b79-ae62-6cee6490b4a3>\",\"WARC-IP-Address\":\"198.27.91.240\",\"WARC-Target-URI\":\"http://compsci.ca/v3/viewtopic.php?t=3277\",\"WARC-Payload-Digest\":\"sha1:FRO2MSZO52CXJ7DFUJDLJZME6VL2EB5I\",\"WARC-Block-Digest\":\"sha1:ZZMLGQE3XIT3IJKACKYSXCYEKAELE6YN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-21/CC-MAIN-2021-21_segments_1620243988741.20_warc_CC-MAIN-20210506053729-20210506083729-00041.warc.gz\"}"}