

-----------------------------------

shruti

Thu May 22, 2008 4:20 pm


need helppppppp with my maze ..

-----------------------------------

hi 
i wrote a progrm for maze but my problem is that the keys dont work and i want to make my maze confusing.  when i try for the keys it says variable has no valu so plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz help me thanks ......and i made my program faster just for now ..and plzz crrect the mistake i did 


my program is 

% to set screen
setscreen ("graphics:600,500, position:center;center,nobuttonbar,offscreenonly")
%constants
const rows := 42
const columns := 42
const size := 15
% declare the variables
var bold, italic, underline : boolean
var maze, x, y, c : int
var font1, font2, font3, font4 : int
var text1, text2, text3 : string
var keys : array char of boolean
var counter : int := 0
var startime : int
var timeremaining : int
var timeLowRange : int := 5
var timeHighRange : int := 10
var travelled : array 0 .. columns + 1, 0 .. rows + 1 of boolean
var routes : int := 0
var direction : array 1 .. 4, 1 .. 2 of int    % there are 4 possibilities and 2 different directions
var way : array 1 .. rows* columns, 1 .. columns* rows of boolean 
var lines : int
var x1, y1, x2, y2 : int
 % to initilize the random values
 randint (x, 0, maxx)
 randint (y, 0, maxy)
 randint (c, 0, 255)
 
 % sets the background colour as black
 drawfillbox (0, 0, maxx, maxy, 7)
 
 %assign the font type and the size, for "The Maze"
 font1 := Font.New ("monotype corsiva:80")
 assert font1 > 0
 text1 := "The Maze"
 Draw.Text (text1, 100, 250, font1, c)
 % for text 2, " Please press enter to continue"
 font2 := Font.New ("times new roman:15:Italic")
 assert font2 > 0
 text2 := "please press enter to continue "
 Draw.Text (text2, 160, 190, font2, 40)
 
 %  animation for " The Maze"
 for i : 1 .. 65
 randint (c, 35, 51)
 Draw.Text (text1, 100, 250, font1, c)
 View.Update
 delay (15)
 end for
 
 % for text 3, " Instructions"
 font3 := Font.New ("monotype corsiva:55:Italic")
 assert font3 > 0
 text3 := " Instructions "
 % lets the user use the keys
 loop
 counter := counter + 1
 Input.KeyDown (keys)
 if keys (KEY_ENTER) then
 cls
 drawfillbox (0, 0, maxx, maxy, 7)
 Draw.Text (text3, 150, 330, font3, 64)
 end if
 exit when (counter = 2)
 View.Update
 Input.Pause
 end loop
 
 % font and size for the instructions
 font4 := Font.New ("times new roman:19")
 assert font4 > 0
 
 % draw text for the instructions
 Draw.Text (" * This is a one player game ", 65, 250, font4, 40)
 Draw.Text (" * You have to use the arrow keys to move", 65, 210, font4, 40)
 Draw.Text (" * start where you see red circle and end at the blue ", 65, 180, font4, 40)
 Draw.Text (" * You have to complete this game in 2 minutes ", 65, 140, font4, 40)
 Draw.Text (" * Enjoy ", 65, 100, font4, 40)
 
 % lets the user use the enter key
 loop
 Input.KeyDown (keys)
 View.Update
 if keys (KEY_ENTER) then
 cls
 for k:  1..3
 put " loading.. "..
 delay(100)
 end for
 end if
 cls
 %draws outer walls
Draw.Box (15, 15, 45 * 13, 34 * 13, 7)
 % draws the oval at the start
Draw.FillOval (575, 23, 5, 5, red)
 % for the other end
Draw.FillOval (44 * 13, 33 * 13, 5, 5, blue)
startime := Time.Elapsed      % for time
loop
    %time at the top of the game
     timeremaining := Time.Elapsed - startime
     if timeremaining = 60 then
     put " you have 1 minutes remaining "
     end if
     if timeremaining = 120 then
     put " your time is up !!!  "
     end if
     exit when timeremaining = 120
     View.Update
     locate (1, 1)
     put "Time: ", startime / 1000 : 1 : 1, " seconds "
     View.Set ("offscreenonly")
     %exit when Time.Elapsed =300
     % for the lines in the maze
    Draw.Line (550, 420, 585, 420, black)
    Draw.Line (550, 420, 585, 420, black)
    Draw.Line (550, 420, 550, 300, black)
    Draw.Line (440, 300, 550, 300, black)
    Draw.Line (550, 220, 500, 220, black)
    Draw.Line (100, 110, 374, 110, black)
    Draw.Line (550, 100, 550, 300, black)
    Draw.Line (450, 350, 450, 440, black)
    Draw.Line (560, 320, 440, 320, black)
    Draw.Line (440, 320, 440, 220, black)
    Draw.Line (400, 360, 400, 260, black)
    Draw.Line (500, 340, 500, 440, black)
    Draw.Line (400, 260, 360, 260, black)
    Draw.Line (350, 160, 440, 220, black)
    Draw.Line (300, 360, 360, 260, black)
    Draw.Line (300, 220, 360, 220, black)
    Draw.Line (250, 160, 350, 160, black)
    Draw.Line (250, 160, 250, 270, black)
    Draw.Line (250, 270, 300, 270, black)
    Draw.Line (450, 360, 360, 360, black)
    Draw.Line (250, 350, 300, 270, black)
    Draw.Line (300, 320, 340, 320, black)
    Draw.Line (360, 360, 300, 360, black)
    Draw.Line (40, 310, 210, 310, black)
    Draw.Line (210, 310, 210, 270, black)
    Draw.Line (210, 130, 210, 270, black)
    Draw.Line (210, 130, 370, 130, black)
    Draw.Line (480, 200, 370, 130, black)
    Draw.Line (480, 280, 480, 200, black)
    Draw.Line (480, 280, 510, 280, black)
    Draw.Line (510, 210, 510, 280, black)
    Draw.Line (510, 210, 640, 210, black)
    Draw.Line (40, 310, 40, 230, black)
    Draw.Line (15, 180, 80, 180, black)
    Draw.Line (80, 180, 170, 180, black)
    Draw.Line (80, 180, 80, 260, black)
    Draw.Line (210, 260, 170, 260, black)
    Draw.Line (170, 210, 170, 260, black)
    Draw.Line (34, 130, 300, 130, black)
    Draw.Line (300, 200, 300, 150, black)
    Draw.Line (215, 359, 215, 440, black)
    Draw.Line (120, 100, 120, 130, black)
    Draw.Line (160, 15, 160, 90, black)
    Draw.Line (200, 40, 200, 130, black)
    Draw.Line (240, 15, 240, 90, black)
    Draw.Line (280, 40, 280, 130, black)
    Draw.Line (320, 15, 320, 90, black)
    Draw.Line (360, 40, 360, 130, black)
    Draw.Line (360, 40, 580, 40, black)
    Draw.Line (580, 40, 580, 160, black)
    Draw.Line (500, 160, 580, 160, black)
    Draw.Line (500, 160, 420, 60, black)
    Draw.Line (420, 100, 530, 80, black)
    Draw.Line (510, 120, 540, 120, black)
    Draw.Line (45, 345, 255, 345, black)
    Draw.Line (100, 15, 100, 100, black)
    Draw.Line (50, 35, 100, 35, black)
    Draw.Line (150, 35, 100, 35, black)
    Draw.Line (50, 100, 50, 15, black)
x:=57
y:=23
x2:=5
y2:=5    
    % to move the circle 
   Input.KeyDown (keys) 
    if keys (KEY_UP_ARROW) then 
                y1 := y1 + 1 
                y2 := y2 + 1 
                drawfilloval (x1, y1, x2, y2, 1) 
            elsif keys (KEY_DOWN_ARROW) then 
                y1 := y1 - 1 
                y2 := y2 - 1 
                drawfilloval (x1, y1, x2, y2, 1) 
            elsif keys (KEY_LEFT_ARROW) then 
                x1 := x1 - 1 
                x2 := x2 - 1 
                drawfilloval (x1, y1, x2, y2, 1) 
            elsif keys (KEY_RIGHT_ARROW) then 
                x1 := x1 + 1 
                x2 := x2 + 1 
                drawfilloval (x1, y1, x2, y2, 1) 
            end if 
            View.Update 
            Input.Pause
            cls 

    
end loop
end loop


Mod EDIT: Remember the syntax tags!!


-----------------------------------

Sean

Thu May 22, 2008 4:35 pm


Re: need helppppppp with my maze ..

-----------------------------------

Fix it into one entire loop, and cut out all the small loops where ever you used the Input.KeyDown.

And only declare it once.


loop
     Input.KeyDown (keys)

%Code
end loop



-----------------------------------

shruti

Thu May 22, 2008 4:55 pm


RE:need helppppppp with my maze ..

-----------------------------------

i did try it but then everything comes into one and input.keydown is declared only once ..the other is enter


-----------------------------------

Sean

Thu May 22, 2008 5:04 pm


Re: need helppppppp with my maze ..

-----------------------------------

When i have the chance to use the other machine, I'll send you a PM with an example of Input.KeyDown with character movement.


-----------------------------------

shruti

Thu May 22, 2008 5:05 pm


RE:need helppppppp with my maze ..

-----------------------------------

i know how it works and stuff but when I try this      .............it does something but does not move the oval
Input.KeyDown (keys) 
   put " before if "
        if keys (KEY_UP_ARROW)  then 
        y += 1
         Draw.FillOval (x1,y1, x2, y2, red)
        put " jhgerjkfhsd"
       end if 
        if keys (KEY_LEFT_ARROW)  then 
         x -= 1 
          Draw.FillOval (x1, y1, x2, y2, red)
        end if  
        if keys (KEY_RIGHT_ARROW)  then  
           Draw.FillOval (x1, y1, x2, y2, red)
            y += 1
        end if 
        if keys (KEY_DOWN_ARROW) then 
        y -= 1 
           Draw.FillOval (x1, y1, x2, y2, red)
        end if
 View.Update
 Input.Pause


-----------------------------------

Sean

Thu May 22, 2008 5:13 pm


Re: need helppppppp with my maze ..

-----------------------------------

You are not attempting to redraw the oval after you press the key. Once it is in a loop, and you use View.Update, and no Input.Pause you should be fine.


-----------------------------------

shruti

Thu May 22, 2008 5:14 pm


RE:need helppppppp with my maze ..

-----------------------------------

ok i will try that



i tried that ..but it just puts what i tell and does not move the oval


-----------------------------------

Sean

Thu May 22, 2008 5:21 pm


Re: need helppppppp with my maze ..

-----------------------------------

Here is an example:


View.Set ("offscreenonly")

var keys : array char of boolean
var x, y : int := 100

loop
    Draw.FillOval (x, y, 15, 15, blue)

    Input.KeyDown (keys)
    View.Update

    if keys (KEY_RIGHT_ARROW) then
        x += 1
    elsif keys (KEY_LEFT_ARROW) then
        x -= 1
    end if
    cls
end loop



-----------------------------------

Insectoid

Fri May 23, 2008 9:17 am


RE:need helppppppp with my maze ..

-----------------------------------

You didn't initialize x1 and y1 (unless I missed it) You randomize x and y, then declared them again with x2 and y2 later on.


-----------------------------------

Sean

Fri May 23, 2008 10:44 am


Re: need helppppppp with my maze ..

-----------------------------------

This thread has been answered. We continued it into PMs. Thread should be locked.

