Computer Science Canada engineering Homework :( |
Author: | zaczac [ Sat Sep 27, 2008 6:52 pm ] |
Post subject: | engineering Homework :( |
Well we just started learning about this program and we have to make a program. The program is a game of hangman and you must pick a number between 1-20 and if you get it wrong the program will draw another part of the body, Example if i guessed the number 5 and it was wrong then the program would draw a head, if i guessed wrong again it would draw the body, and so on. Heres what i got so far... var num, rnum : int loop rnum := Rand.Int (1, 20) put "Please Pick A Number between 1 and 20. 100 is to Exit." loop get num if rnum = num then put "You guessed it!" exit else put "Wring. Guess Again." end if end loop end loop Im completely lost on how to get the program to draw the body if anyone could help id appreciate it a lot thanks in advanced |
Author: | Tony [ Sat Sep 27, 2008 7:42 pm ] |
Post subject: | RE:engineering Homework :( |
You can use commands such as Draw.Oval() and Draw.Line() to draw graphics. Look up the documentation for their proper use. |
Author: | zaczac [ Tue Sep 30, 2008 7:18 pm ] |
Post subject: | RE:engineering Homework :( |
Heres what i got now var numb, guess, counter : int numb := Rand.Int (1, 20) counter := 7-1 drawoval (100, 250, 50 ,50, black) drawline (70, 40, 100, 100, black) drawline (100, 100, 130, 40, black) drawline (100, 100, 100, 200, black) drawline (70, 140, 100, 180, black) drawline (130, 140, 100, 180, black) loop put "Guess a number from 1 to 20." get guess if guess = numb then put "Guess is right" else put "Guess is wrong" end if end loop Still dont get how i could take parts away from my stick man if someone guesses somthing wrong >.< i tried using a counter but that didnt work =_- thanks for any suggestions. |
Author: | Insectoid [ Tue Sep 30, 2008 7:28 pm ] |
Post subject: | RE:engineering Homework :( |
Use a counter to count how many times they got it wrong, and draw a part corresponding to that counter. pseudo code: [code] if guess is wrong then if counter = 1 then draw head elsif counter = 2 then draw body elsif.... end if |
Author: | OneOffDriveByPoster [ Tue Sep 30, 2008 7:33 pm ] |
Post subject: | Re: RE:engineering Homework :( |
Erm... I think you want to add parts, not remove them... A counter is a good approach. If the user makes his Xth wrong guess, then draw the part Xth part. |
Author: | S_Grimm [ Wed Oct 01, 2008 7:50 am ] |
Post subject: | RE:engineering Homework :( |
put a variable in the program, called something like numberwrong, and put it so " if numberwrong = 1 then drawhead end if if numberwrong = 2 then drawbody end if |
Author: | Insectoid [ Wed Oct 01, 2008 11:18 am ] | ||||
Post subject: | RE:engineering Homework :( | ||||
Quote: counter := 7-1 This is a problem. It says that your counter will always equal 6. You need to decrease it, and you need a loop. Replace 7 with 'counter'.
A nice programming thingummy that allows you to shorten this common piece of code:
|
Author: | Clayton [ Wed Oct 01, 2008 8:38 pm ] | ||||
Post subject: | Re: RE:engineering Homework :( | ||||
insectoid @ Wed Oct 01, 2008 11:18 am wrote: Quote: counter := 7-1 This is a problem. It says that your counter will always equal 6. You need to decrease it, and you need a loop. Replace 7 with 'counter'.
A nice programming thingummy that allows you to shorten this common piece of code:
I believe the term you are looking for here is syntactic sugar. |
Author: | S_Grimm [ Thu Oct 02, 2008 7:56 am ] | ||
Post subject: | Re: engineering Homework :( | ||
This is NOT a complete program, because i know that it will be deleted if it was, but i belive that it is what you wanted, no?
|