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

Username:   Password: 
 RegisterRegister   
 Picture guessing game help for turing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
anchor




PostPosted: Sun Jan 20, 2013 11:59 am   Post subject: Picture guessing game help for turing

What is it you are trying to achieve?
<Trying to create an efficient picture guessing game where a picture will be drawn to screen, and the user has to guess what it is.>


What is the problem you are having?
<There will be 8 rounds in my game, but at the moment i'm copying and pasting round 1 over and over and changing the number of the round and picture. Isn't there a better way to go about this? I don't know how to create a loop of some sort so that the picture corresponds to the right answer. >


Describe what you have tried to solve this problem
<tried creating a loop for the pictures but i'm a beginner at all this so...>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:


%---------------------ROUND 1------------------------
%tiger picture is drawn
var a, b : int
pic := Pic.FileNew ("round1tiger.jpg")
a := 400
b := 30
Pic.Draw (pic, a, b, picMerge)
Pic.Free (pic)

%start of round 1
put "ROUND 1: START"
put "What is this picture part of?"
put "You have 30 seconds starting..." %will add a timer
delay (500)
put "now!"
get guess
put ""
%if user puts captials/spaces for ans
guess := Str.Lower (guess)
guess := Str.Trim (guess)

%if it's wrong
if guess not= "tiger" then
    put guess, " is wrong. You get 0 points."
    Draw.Text ("you win 0 points. You have a total of ", 0, 400, font, red)
    sumpointstxt (1) := intstr (sumpoints)
    Draw.Text (sumpointstxt (1), 240, 400, font, red)
    Draw.Text ("points ", 275, 400, font, red)
    Draw.Text ("Enter any key to continue.", 0, 380, font, red)
    get enter
    cls
%if it's right
elsif guess = "tiger" then
    put guess, " is",
%drawing text so it doesn't overlap picture   
    Draw.Text ("correct! You may move on to the next round!", 0, 420, font, red)
    sumpoints := sumpoints + 10 %total points
    sumpointstxt (1) := intstr (sumpoints) %changing pts integer to string so it can be drawn to screen
%summary
    Draw.Text ("you win 10 points. You have a total of ", 0, 400, font, red)
    Draw.Text (sumpointstxt (1), 240, 400, font, red)
    Draw.Text ("points ", 275, 400, font, red)
%contd
    Draw.Text ("Enter any key to continue.", 0, 380, font, red)
    get enter
    cls
end if
%--------------------END OF ROUND 1------------------------

%------------------------ROUND 2---------------------------
%fire truck picture is drawn
var c, d : int
pic := Pic.FileNew ("round2firetruck.jpg")
c := 400
d := 30
Pic.Draw (pic, c, d, picMerge)
Pic.Free (pic)

%start of round 2
put "ROUND 2: START"
put "What is this picture part of?"
put "You have 30 seconds starting..." %will add a timer
delay (500)
put "now!"
get guess
put ""
%if user puts captials/spaces for ans
guess := Str.Lower (guess)
guess := Str.Trim (guess)

%if it's wrong
if guess not= "fire_truck" then
    put guess, " is wrong. You get 0 points."
    sumpointstxt (2) := intstr (sumpoints)
    Draw.Text ("you win 0 points. You have a total of ", 0, 400, font, red)
    Draw.Text (sumpointstxt (2), 240, 400, font, red)
    Draw.Text ("points ", 275, 400, font, red)
    Draw.Text ("Enter any key to continue.", 0, 380, font, red)
    get enter
    cls
%if it's right
elsif guess = "fire_truck" then
    put guess, " is",
%drawing text so it doesn't overlap picture
    Draw.Text ("correct! You may move on to the next round!", 0, 420, font, red)
    sumpoints := sumpoints + 10 %total points
    sumpointstxt (2) := intstr (sumpoints)  %changing pts integer to string so it can be drawn to screen
%summary
    Draw.Text ("you win 10 points. You have a total of ", 0, 400, font, red)
    Draw.Text (sumpointstxt (2), 240, 400, font, red)
    Draw.Text ("points ", 275, 400, font, red)
%contd
    Draw.Text ("Enter any key to continue.", 0, 380, font, red)
    get enter
    cls
end if
%--------------------END OF ROUND 2--------------------------




Please specify what version of Turing you are using
Turing 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Sun Jan 20, 2013 3:31 pm   Post subject: RE:Picture guessing game help for turing

There are only two different parameters for each round:
1) The path to the image.
2) The string representing the correct answer.

You could create two arrays of strings: one to hold image paths, the other to hold correct answers. They should have the same number of elements, and image_paths(1) should correspond to correct_answers(1), and so on. For example, image_paths(1) := "round1tiger.jpg" and correct_answers(1) := "tiger".

Then, you could use a for loop to count with a variable i from 1 to (however many questions you have). Inside your for loop, load the image from image_paths(i), draw it, get the user's guess, compare it to correct_answers(i), etc. You can even use the value of i itself to count the round number.
anchor




PostPosted: Sun Jan 20, 2013 5:59 pm   Post subject: RE:Picture guessing game help for turing

So does that mean i have to declare the strings to the answers all the way down like this:

var image_paths: array 1..8 of string
var correct_answers: array 1..8 of string


image_paths(1) := "round1tiger.jpg"
correct_answers(1) := "tiger"
image_paths(2):="round2firetruck.jpg"
correct_answers(2):="tiger"
and etc?


and how would compare the answers to the image using the strings?

thank you so much for helping!
DemonWasp




PostPosted: Sun Jan 20, 2013 7:34 pm   Post subject: RE:Picture guessing game help for turing

You can use the "init" syntax, or you can load them from a file. For the former, see: http://compsci.ca/holtsoft/doc/init.html ; for the latter, recall your lessons on file input and output (IO).

Compare the answers to the user's guess in the same way that you have previously, except that instead of "tiger" or "fire_truck", you have to use correct_answers(i).
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: