Error somewhere..
Author |
Message |
Jim
|
Posted: Tue Jan 15, 2008 8:41 am Post subject: Error somewhere.. |
|
|
Ok so here is a project that me and a partner are writing at the moment. When you run it its suppose to be hooked to a bread box. The program will first execute our load screen and then begin the same (similar to simon says) the program will randomly choose 3 parallel puts at first and light the cooresponding lights up. The user then clicks the circles on the screen that lit up in the same order. If they do it right its suppose to be going onto 4 lights etc. But there is an error in here and my partner and I have spent 2 days trying to find it with little sucess. When you click the correct circle its saying we lose and also bringing up the load screen lol. Neways anyone willing to hack away and see whats up, would be appreciated Thanks.
Turing: |
import GUI
var x, y, buttonnumber, buttonupdown, num : int
var light : int
var x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16 : int
setscreen ("graphics")
procedure mainScreen
var mypic : int := Pic.FileNew ("LZRD.bmp")
var font1 : int
font1 := Font.New ("comicsans:14")
Font.Draw ("A Caves and Lizards Production", 175, 175, font1, red)
Pic.Draw (mypic, maxx div 2. 5, maxy div 2, 0)
Pic.Free (mypic )
end mainScreen
mainScreen
procedure Quit
locate (1, 1)
put "Bye!"
GUI.Quit
delay (500)
cls
end Quit
procedure Light2
if y < 230 and y > 170 then
if light = 1 and x < x1 and x > x2 then
locatexy (20, 100)
put "correct"
else
if
light = 2 and x < x3 and x > x4 then
locatexy (20, 100)
put "correct"
else
if light = 3 and x < x5 and x > x6 then
locatexy (20, 100)
put "correct"
else
if light = 4 and x < x7 and x > x8 then
locatexy (20, 100)
put "correct"
else
if light = 5 and x < x9 and x > x10 then
locatexy (20, 100)
put "correct"
else
if light = 6 and x < x11 and x > x12 then
locatexy (20, 100)
put "correct"
else
if light = 7 and x < x13 and x > x14 then
locatexy (20, 100)
put "correct"
else
if light = 8 and x < x15 and x > x16 then
locatexy (20, 100)
put "correct"
else
locatexy (20, 100)
put "you lose"
delay (2000)
cls
mainScreen
end if
end if
end if
end if
end if
end if
end if
end if
end if
end Light2
procedure Light1
if y < 230 and y > 170 then
if light = 1 and x < x1 and x > x2 then
locatexy (20, 100)
put "correct"
Light2
else
if light = 2 and x < x3 and x > x4 then
locatexy (20, 100)
put "correct"
Light2
else
if light = 3 and x < x5 and x > x6 then
locatexy (20, 100)
put "correct"
Light2
else
if light = 4 and x < x7 and x > x8 then
locatexy (20, 100)
put "correct"
Light2
else
if light = 5 and x < x9 and x > x10 then
locatexy (20, 100)
put "correct"
Light2
else
if light = 6 and x < x11 and x > x12 then
locatexy (20, 100)
put "correct"
Light2
else
if light = 7 and x < x13 and x > x14 then
locatexy (20, 100)
put "correct"
Light2
else
if light = 8 and x < x15 and x > x16 then
locatexy (20, 100)
put "correct"
Light2
else
locatexy (20, 100)
put "you lose"
delay (2000)
cls
mainScreen
end if
end if
end if
end if
end if
end if
end if
end if
end if
end Light1
procedure Begin
cls
put "Pay attention to the order!"
%Draws the eight circles on the screen
%Each circle is labelled with an "x" value.
%x1,x2
drawfilloval (50, 200, 30, 30, 10)
locatexy (48, 150)
put "S"
%x3, x4
drawfilloval (125, 200, 30, 30, 10)
locatexy (123, 150)
put "T"
%x5, x6
drawfilloval (200, 200, 30, 30, 10)
locatexy (198, 150)
put "U"
%x7, x8
drawfilloval (275, 200, 30, 30, 10)
locatexy (273, 150)
put "V"
%x9, x10
drawfilloval (350, 200, 30, 30, 10)
locatexy (348, 150)
put "W"
%x11, x12
drawfilloval (425, 200, 30, 30, 10)
locatexy (423, 150)
put "X"
%x13, x14
drawfilloval (500, 200, 30, 30, 10)
locatexy (498, 150)
put "Y"
%x15, 16
drawfilloval (575, 200, 30, 30, 10)
locatexy (573, 150)
put "Z"
delay (2000)
%Randomly chooses and number and opens the corresponding parallel port.
%Which ever parallel port is on, the green lights in the window flash
%black the same as the bread box.
for i : 1 .. 3
parallelput (0)
randint (num, 1, 8)
if num = 1
then
drawfilloval (575, 200, 30, 30, 7)
parallelput (1)
delay (1000)
drawfilloval (575, 200, 30, 30, 10)
light := 1
else
if num = 2
then
drawfilloval (500, 200, 30, 30, 7)
parallelput (2)
delay (1000)
drawfilloval (500, 200, 30, 30, 10)
light := 2
else
if num = 3
then
drawfilloval (425, 200, 30, 30, 7)
parallelput (4)
delay (1000)
drawfilloval (425, 200, 30, 30, 10)
light := 3
else
if num = 4
then
drawfilloval (350, 200, 30, 30, 7)
parallelput (8)
delay (1000)
drawfilloval (350, 200, 30, 30, 10)
light := 4
else
if num = 5
then
drawfilloval (275, 200, 30, 30, 7)
parallelput (16)
delay (1000)
drawfilloval (275, 200, 30, 30, 10)
light := 5
else
if num = 6 then
drawfilloval (200, 200, 30, 30, 7)
parallelput (32)
delay (1000)
drawfilloval (200, 200, 30, 30, 10)
light := 6
else
if num = 7 then
drawfilloval (125, 200, 30, 30, 7)
parallelput (64)
delay (1000)
drawfilloval (125, 200, 30, 30, 10)
light := 7
else
if num = 8 then
drawfilloval (50, 200, 30, 30, 7)
parallelput (128)
delay (1000)
drawfilloval (50, 200, 30, 30, 10)
light := 8
end if
end if
end if
end if
end if
end if
end if
end if
parallelput (0)
delay (2000)
end for
%Assign each circle x-coords
x1 := 80
x2 := 20
x3 := 155
x4 := 95
x5 := 230
x6 := 170
x7 := 305
x8 := 255
x9 := 380
x10 := 320
x11 := 455
x12 := 395
x13 := 530
x14 := 470
x15 := 605
x16 := 555
%Cycles through which coordinates the mouse was clicked and lights up
%the corresponding circle.
put "Click the circles in the correct order to advance to the next round!"
loop
buttonwait ("down", x, y, buttonnumber, buttonupdown )
if x < x1 and x > x2 or x < x3 and x > x4 or x < x5 and x > x6 or x < x7 and x > x8 or x < x9 and x > x10 or x < x11 and x > x12 or x < x13 and x > x14 or x < x15 or x > x16 then
if y < 230 and y > 170 then
delay (100)
%S
if x < x1 and x > x2 then
drawfilloval (50, 200, 30, 30, 7)
delay (250)
drawfilloval (50, 200, 30, 30, 10)
else
%T
if x < x3 and x > x4 then
drawfilloval (125, 200, 30, 30, 7)
delay (250)
drawfilloval (125, 200, 30, 30, 10)
else
%U
if x < x5 and x > x6 then
drawfilloval (200, 200, 30, 30, 7)
delay (250)
drawfilloval (200, 200, 30, 30, 10)
else
%V
if x < x7 and x > x8 then
drawfilloval (275, 200, 30, 30, 7)
delay (250)
drawfilloval (275, 200, 30, 30, 10)
else
%W
if x < x9 and x > x10 then
drawfilloval (350, 200, 30, 30, 7)
delay (250)
drawfilloval (350, 200, 30, 30, 10)
else
%X
if x < x11 and x > x12 then
drawfilloval (425, 200, 30, 30, 7)
delay (250)
drawfilloval (425, 200, 30, 30, 10)
else
%Y
if x < x13 and x > x14 then
drawfilloval (500, 200, 30, 30, 7)
delay (250)
drawfilloval (500, 200, 30, 30, 10)
else
%Z
if x < x15 and x > x16 then
drawfilloval (575, 200, 30, 30, 7)
delay (250)
drawfilloval (575, 200, 30, 30, 10)
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
Light1
end loop
end Begin
var button2 : int := GUI.CreateButton (25, 50, 0, "Play", Begin )
var button1 : int := GUI.CreateButton (25, 25, 0, "Exit", Quit )
loop
exit when GUI.ProcessEvent
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Randolf Nitler
|
Posted: Tue Jan 15, 2008 8:00 pm Post subject: Re: Error somewhere.. |
|
|
makes my eyes hurt just to look at this. Fix all those if statements, thats most likely where your problem lies |
|
|
|
|
|
Nick
|
Posted: Tue Jan 15, 2008 8:12 pm Post subject: RE:Error somewhere.. |
|
|
use elsif instead of else if |
|
|
|
|
|
ericfourfour
|
Posted: Tue Jan 15, 2008 9:25 pm Post subject: RE:Error somewhere.. |
|
|
Also, do you see a pattern with your drawing and the parallelputs inside the if statements?
The first two if sections could be be reduced with the use of "or".
In the third if section, the only thing that changes are the x coordinates (decrease by 75) and the parallelput (2^n). To solve for the x coordinates, this expression can be used: 650 - num * 75. To solve for the parallelput, this expression can be used: 2**(n-1). That would completely remove the need for if statements.
The fourth if section can be reduced if you look into arrays. Then do something similar to the last section, to further reduce the amount of code. |
|
|
|
|
|
|
|