Creating guessing games
Author |
Message |
iNsteReo
|
Posted: Thu Apr 30, 2009 12:04 pm Post subject: Creating guessing games |
|
|
What is it you are trying to achieve?
I am trying to create a program that would randomly select the order of 4 colors. After this, the user sees 4 boxes( of the same 4 colors, but not in the same order). The user then clicks on the the boxes in order which he thinks the program set the colors in. Then there are 4 LEDS on the outside of the computer, connected to the computer through parallel circuit. The LEDS light up according to how many correct colors the user guessed ( if he got the first and the last color right, the 1st and last LED light up)
What is the problem you are having?
My problem is making the program random the colors and then getting the user input and matching the user input to the randomed colors.
Describe what you have tried to solve this problem
I tried to put the 4 colors in an array and randomize it. But i honestly do not even know how to start solving this.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
i started out with a little different program, because i know how to this and not what is needed.
Turing: |
% Dmytro TK
% April, 2009
% The mastermind game
setscreen ("graphics")
var finished : boolean := false
var rangeX, rangeY, button : int
% Program Title
procedure title
cls
locate (1, 28)
put "The mastermind game"
end title
%Program introduction
procedure introduction
title
locate (3, 1)
put "Click on the boxes to guess in which order the colors were set."
end introduction
% Displaying Boxes
procedure userInput
%draw a blue box on the screen
drawfillbox (20, 150, 120, 300, blue)
drawfillbox (150, 150, 250, 300, green)
drawfillbox (280, 150, 380, 300, black)
drawfillbox (410, 150, 510, 300, red)
drawbox (240, 50, 360, 90, black)
locate (21, 32)
put "EXIT PROGRAM" ..
mousewhere (rangeX, rangeY, button )
for i : 1 .. 4
if button = 1 then
if rangeX >= 20 and rangeX <= 120 and rangeY >= 150 and rangeY <= 300 then
locate (20, 1)
put "You picked the blue box."
elsif rangeX >= 150 and rangeX <= 250 and rangeY >= 150 and rangeY <= 300 then
locate (20, 1)
put "You picked the green box."
elsif rangeX >= 280 and rangeX <= 380 and rangeY >= 150 and rangeY <= 300 then
locate (20, 1)
put "You picked the black box."
elsif rangeX >= 410 and rangeX <= 510 and rangeY >= 150 and rangeY <= 300 then
locate (20, 1)
put "You picked the red box."
else
locate (20, 1)
put "Please click inside a box!!!"
exit when button = 1 and rangeX >= 240 and rangeX <= 360 and rangeY >= 50 and rangeY <= 90
end if
end if
end for
end userInput
% GoodBye
proc goodBye
title
locate (10, 6)
put "Thank you for playing the Mastermind Game!!I hope you enjoyed it!!!"
locate (20, 33)
put "By: Dmytro Tk."
end goodBye
%Main Program
introduction
loop
userInput
exit when button = 1 and rangeX >= 240 and rangeX <= 360 and rangeY >= 50 and rangeY <= 90
end loop
goodBye
% End of program
|
Please specify what version of Turing you are using
4.0.5. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
tjmoore1993
|
Posted: Thu Apr 30, 2009 3:14 pm Post subject: RE:Creating guessing games |
|
|
Try using a procedure to randomize by using
Use the Rand.Int code to randomize an order and use an IF statement.
If you still have problems ask (RANDOMIZER IS YOUR FRIEND!) |
|
|
|
|
|
DtY
|
Posted: Thu Apr 30, 2009 4:29 pm Post subject: RE:Creating guessing games |
|
|
Something like this would work, and it might be what tjmoore1993 is suggesting.
Note, this code has not been tested
Turing: | var order: array 0..3 of int %This will store the order of the numbers
var used: int:= 0 %This will store which numbers have been used
var temp: int %This will store the number randomly chosen
for i: 0..3
loop
temp := Rand.Int(0, 3)
if ((used >> temp) & 1) = 0 then
order(i) := temp
used := used | (1 << temp)
exit
end if
end loop
end for |
used could also be an array of booleans. |
|
|
|
|
|
|
|