Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
School project: Hangman
Author Message
we64

Posted: Mon Jan 12, 2004 10:03 pm   Post subject: School project: Hangman

Please set the screen to 40 rows by 120 columes

%Hangman Game
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, times, right : int := 0
var letter, word, choice : 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, Font.New ("serif:24:bold"), Rand.Int (155, 200))
Draw.Text ("The word is:", maxx div 2 - 150, maxy div 2 + 60, Font.New ("serif:24:bold"), Rand.Int (155, 200))
Draw.Text (words (random), maxx div 2 + 40, maxy div 2 + 60, 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 (4, 1)
put "Please enter a letter from the alphabets:"
locate (10, 5)
put "Alphabets:"

%Hang
drawfillbox (490, 200, 510, 410, 112) %post
drawfillbox (500, 400, 620, 410, 112)
drawfillbox (430, 180, 650, 200, 115) %ground
drawfillbox (595, 400, 605, 358, 114) %wire
drawarc (600, 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 star : array 1 .. 26 of string
for a : 1 .. 26
used (a) := chr (96 + a)
star (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

%Used letters 1
locate (11, 10)
for a : 1 .. 26
put star (a) : 3, " " ..
end for

%letter checking
loop
locate (6, 1)
put ""
locate (5, 1)
put ""
locate (5, 1)
get letter

if length (letter) > 1 then
locate (6, 1)
put "Error, please only put one letter at a time."
delay (2000)
end if
exit when length (letter) = 1
end loop

%Used letters 2
locate (12, 1)
put ""
for a : 1 .. 26
if letter = used (a) then
if star (a) = chr (42) then
locate (12, 1)
put "You have already used this letter!"
else
star (a) := chr (42)
end if
end if
end for

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

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

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

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

%Right letter
for a : 1 .. length (words (random))
if letter = words (random) (a) then
dash (a) := letter
end if
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
if counter = 9 then
fork lost
put "Would you like to play again? (y/n)"
get choice
elsif word = words (random) or right = 0 then
fork won
put "Would you like to play again? (y/n)"
get choice
end if

counter := 0
exit when choice = "n"
cls
end loop
 code:

poly

Posted: Mon Jan 12, 2004 10:47 pm   Post subject: (No subject)

hmm its pretty good, except for one wee problem.

we64

Posted: Tue Jan 13, 2004 5:31 pm   Post subject: (No subject)

you have to set the run window to 40 rows by 120 columes under 1024*768
shorthair

Posted: Tue Jan 13, 2004 5:41 pm   Post subject: (No subject)

Whats with the double post , , Oh well its agood game , but you should make the code more flexible for the screen size by using the maxx and maxy
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 4 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: