Computer Science Canada [source] Hangman Game, new version 1.1v... (button updates) |
Author: | we64 [ Wed Feb 04, 2004 5:01 pm ] |
Post subject: | [source] Hangman Game, new version 1.1v... (button updates) |
%Hangman Game 1.1 v. %By Tony Zhang setscreen ("graphics:1000;650") var x, y, letter : int := 0 var colo : int var fx, sx, tx : array 1 .. 11 of int := init (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) var words : array 1 .. 15 of string := init ("computer", "baseball", "program", "video", "cat", "dog", "tiger", "driver", "soccer", "radio", "music", "science", "king", "basketball", "chess") var random, counter, right : int := 0 var word, choice, let : string := "" process won loop Draw.Text ("YaY, You won!", maxx div 2 - 100, maxy div 2, Font.New ("serif:24:bold"), Rand.Int (1, 100)) delay (500) exit when choice = "y" or choice = "n" end loop end won process lost loop 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 (500) exit when choice = "y" or choice = "n" end loop end lost proc playagain 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" drawfillbox (maxx div 2 - 95, maxy - 245, maxx div 2 - 5, maxy - 205, black) drawfillbox (maxx div 2 - 94, maxy - 245, maxx div 2 - 5, maxy - 206, 29) Draw.Text ("Yes", maxx div 2 - 75, maxy - 235, Font.New ("serif:24:bold"), black) delay (300) elsif x >= maxx div 2 + 5 and x <= maxx div 2 + 95 and y >= maxy - 245 and y <= maxy - 205 then choice := "n" drawfillbox (maxx div 2 + 95, maxy - 245, maxx div 2 + 5, maxy - 205, black) drawfillbox (maxx div 2 + 96, maxy - 245, maxx div 2 + 5, maxy - 206, 29) Draw.Text ("No", maxx div 2 + 30, maxy - 235, Font.New ("serif:24:bold"), black) delay (300) end if end if exit when choice = "y" or choice = "n" end loop end playagain loop %Background randint (colo, 75, 79) colourback (colo) cls %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 %Alphabets var used : array 1 .. 26 of string var letters : array 1 .. 26 of string for a : 1 .. 26 used (a) := chr (96 + a) letters (a) := chr (96 + a) end for %Out put loop %Draw Dash locate (8, 15) for a : 1 .. length (words (random)) put dash (a) : 3, " " .. end for %Keyboard for a : 1 .. 10 %First Row drawfillbox (90 + fx (a), 250, 140 + fx (a), 300, 29) drawfillbox (95 + fx (a), 255, 135 + fx (a), 295, 26) drawbox (90 + fx (a), 250, 140 + fx (a), 300, white) Draw.Text (letters (a), 110 + fx (a), 270, Font.New ("serif:22:bold"), 35) fx (a + 1) := a * 50 %Second Row drawfillbox (90 + sx (a), 200, 140 + sx (a), 250, 29) drawfillbox (95 + sx (a), 205, 135 + sx (a), 245, 26) drawbox (90 + sx (a), 200, 140 + sx (a), 250, white) Draw.Text (letters (a + 10), 110 + sx (a), 220, Font.New ("serif:22:bold"), 35) sx (a + 1) := a * 50 %Third Row tx (a + 1) := a * 50 if tx (a) >= 100 and tx (a) <= 350 then drawfillbox (90 + tx (a), 150, 140 + tx (a), 200, 29) drawfillbox (95 + tx (a), 155, 135 + tx (a), 195, 26) drawbox (90 + tx (a), 150, 140 + tx (a), 200, white) Draw.Text (letters (a + 18), 110 + tx (a), 170, Font.New ("serif:22:bold"), 35) end if 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" else let := " " end if %Select if ord (let) >= 97 and ord (let) <= 106 then drawfillbox (95 + fx (ord (let) - 96), 255, 135 + fx (ord (let) - 96), 295, black) drawfillbox (96 + fx (ord (let) - 96), 253, 135 + fx (ord (let) - 96), 294, 29) Draw.Text (let, 110 + fx (ord (let) - 96), 270, Font.New ("serif:22:bold"), 35) elsif ord (let) >= 107 and ord (let) <= 116 then drawfillbox (95 + sx (ord (let) - 106), 205, 135 + sx (ord (let) - 106), 245, black) drawfillbox (96 + sx (ord (let) - 106), 203, 135 + sx (ord (let) - 106), 244, 29) Draw.Text (let, 110 + sx (ord (let) - 106), 220, Font.New ("serif:22:bold"), 35) elsif ord (let) >= 117 and ord (let) <= 122 then drawfillbox (95 + tx (ord (let) - 116 + 2), 155, 135 + tx (ord (let) - 116 + 2), 195, black) drawfillbox (96 + tx (ord (let) - 116 + 2), 153, 135 + tx (ord (let) - 116 + 2), 194, 29) Draw.Text (let, 110 + tx (ord (let) - 116 + 2), 170, Font.New ("serif:22:bold"), 35) end if delay (300) exit when ord (let) > 96 end if end loop %Release if ord (let) >= 97 and ord (let) <= 106 then drawfillbox (90 + fx (ord (let) - 96), 250, 140 + fx (ord (let) - 96), 300, 29) drawfillbox (95 + fx (ord (let) - 96), 255, 135 + fx (ord (let) - 96), 295, 26) drawbox (90 + fx (ord (let) - 96), 250, 140 + fx (ord (let) - 96), 300, white) Draw.Text (let, 110 + fx (ord (let) - 96), 270, Font.New ("serif:22:bold"), 35) elsif ord (let) >= 107 and ord (let) <= 116 then drawfillbox (90 + sx (ord (let) - 106), 200, 140 + sx (ord (let) - 106), 250, 29) drawfillbox (95 + sx (ord (let) - 106), 205, 135 + sx (ord (let) - 106), 245, 26) drawbox (90 + sx (ord (let) - 106), 200, 140 + sx (ord (let) - 106), 250, white) Draw.Text (let, 110 + sx (ord (let) - 106), 220, Font.New ("serif:22:bold"), 35) elsif ord (let) >= 117 and ord (let) <= 122 then drawfillbox (90 + tx (ord (let) - 116 + 2), 150, 140 + tx (ord (let) - 116 + 2), 200, 29) drawfillbox (95 + tx (ord (let) - 116 + 2), 155, 135 + tx (ord (let) - 116 + 2), 195, 26) drawbox (90 + tx (ord (let) - 116 + 2), 150, 140 + tx (ord (let) - 116 + 2), 200, white) Draw.Text (let, 110 + tx (ord (let) - 116 + 2), 170, Font.New ("serif:22:bold"), 35) end if %Used Letter for a : 1 .. 26 if let = used (a) and letters (a) not= chr (42) then locate (5, 1) put "" letters (a) := chr (42) %Wrong Letter if index (words (random), let) = 0 then counter += 1 end if elsif let = used (a) and letters (a) = chr (42) then locate (5, 1) put "You have already used this letter, please choose another one!!" end if end for %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"), colo) 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"), colo) 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 %Draw Dashes locate (8, 15) for a : 1 .. length (words (random)) put dash (a) : 3, " " .. end for %Right word checking for a : 1 .. length (words (random)) right += index (dash (a), "_") end for %Exits letter := 0 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) %Yes drawfillbox (maxx div 2 - 100, maxy - 250, maxx div 2, maxy - 200, 29) drawfillbox (maxx div 2 - 95, maxy - 245, maxx div 2 - 5, maxy - 205, 26) drawbox (maxx div 2 - 100, maxy - 250, maxx div 2, maxy - 200, white) Draw.Text ("Yes", maxx div 2 - 75, maxy - 235, Font.New ("serif:24:bold"), black) %No drawfillbox (maxx div 2 + 100, maxy - 250, maxx div 2, maxy - 200, 29) drawfillbox (maxx div 2 + 95, maxy - 245, maxx div 2 + 5, maxy - 205, 26) drawbox (maxx div 2 + 100, maxy - 250, maxx div 2, maxy - 200, white) Draw.Text ("No", maxx div 2 + 30, maxy - 235, Font.New ("serif:24:bold"), black) %Choice to Play Again choice := "" if counter = 9 then fork lost playagain elsif word = words (random) or right = 0 then fork won playagain end if exit when choice = "n" counter := 0 cls end loop |