Computer Science Canada Please Help!!!!!!!!!!! How To Make A Snake Game With Out Using Flexible Array??? |
Author: | hongyousan [ Wed Jan 15, 2014 4:31 pm ] | ||
Post subject: | Please Help!!!!!!!!!!! How To Make A Snake Game With Out Using Flexible Array??? | ||
What is it you are trying to achieve? <Replace all the <> with your answers/code and remove the <>> What is the problem you are having? I am having trouble making a snake game without using flexible array... Describe what you have tried to solve this problem I have tried many ways, but the snake wont grow longer when it hits an apple... Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) This is what I did so far.. PLEASE HELP ME EDIT IT!! THANK YOU!!! View.Set ("graphics:600,600") View.Set ("offscreenonly") colour (white) colorback (black) var tempx, tempy : int := -100 var x, y : int := 0 var x2, y2 : int := 0 var playagain : string (1) var font1 : int var scoreint : int := 00 var scorestring : string font1 := Font.New ("Dauphin:17") var z : string (1) var foodx, foody : int randint (foodx, 24, 576) randint (foody, 24, 576) loop if foodx mod 12 not= 0 then randint (foodx, 20, 568) end if if foody mod 12 not= 0 then randint (foody, 20, 568) end if exit when foodx mod 12 = 0 and foody mod 12 = 0 end loop drawfill (0, 0, black, black) drawfillbox (12, 12, 588, 576, white) View.Update loop put "Your score: ", scoreint % Font.Draw ("Your score: ", 100, 580, font1, black) % % scorestring := intstr (scoreint) % Font.Draw (scorestring, 210, 580, font1, black) drawfillbox (foodx, foody, foodx + 10, foody + 10, black) drawfillbox (foodx + 2, foody + 2, foodx + 8, foody + 8, yellow) View.Update if hasch then getch (z) locate (1, 1) if ord (z) = 200 and y not= -12 then % put "Up Arrow Key" y := 12 x := 0 end if if ord (z) = 203 and x not= 12 then % put "Left Arrow Key" x := -12 y := 0 end if if ord (z) = 205 and x not= -12 then % put "Right Arrow Key" x := 12 y := 0 end if if ord (z) = 208 and y not= 12 then % put "Down Arrow Key" y := -12 x := 0 end if end if drawfillbox (60 + tempx, 60 + tempy, 70 + tempx, 70 + tempy, white) drawfillbox (60 + x2, 60 + y2, 70 + x2, 70 + y2, black) drawfillbox (62 + x2, 62 + y2, 68 + x2, 68 + y2, green) tempx := x2 tempy := y2 View.Update x2 := x2 + x y2 := y2 + y if 60 + x2 = foodx and 60 + y2 = foody then scoreint := scoreint + 1 randint (foodx, 24, 568) randint (foody, 24, 568) loop if foodx mod 12 not= 0 then randint (foodx, 20, 568) end if if foody mod 12 not= 0 then randint (foody, 20, 568) end if exit when foodx mod 12 = 0 and foody mod 12 = 0 end loop end if if 60 + x2 > 576 or 60 + x2 < 12 or 60 + y2 >= 576 or 60 + y2 < 12 then locate (1, 23) put "GAME OVER" locate (1, 37) put "Press ANY key to play again" View.Update getch (playagain) cls scoreint := 0 x := 0 y := 0 x2 := 0 y2 := 0 drawfillbox (12, 12, 588, 576, white) View.Update end if locate (1, 1) delay (60) end loop
Please specify what version of Turing you are using <Answer Here> |
Author: | Raknarg [ Wed Jan 15, 2014 6:29 pm ] |
Post subject: | RE:Please Help!!!!!!!!!!! How To Make A Snake Game With Out Using Flexible Array??? |
var snake : array 1 .. 100 of int var snakeUpper : int := 0 snakerUpper := 10 this is the same as var snake : flexible array 1 .. 0 new snake, 10 Why are you not allowed to use flexible arrays? |
Author: | hongyousan [ Sat Jan 18, 2014 10:18 pm ] |
Post subject: | Re: Please Help!!!!!!!!!!! How To Make A Snake Game With Out Using Flexible Array??? |
var snakex : array 1 .. 100000 of int var snakey : array 1 .. 100000 of int var chars : array char of boolean var uppervarx : int := 50 var counter : int := 2 var uppervary : int := 50 var last_upper : int := 0 var direction : string := "right" var x, y : int := 200 var dirx : int := 3 var diry : int := 0 var ball : string := "not drawn" var ballx, bally : int var ball_count : int := 0 var speed : int := 20 drawfillbox (0, 0, maxx, maxy, 7) for i : 1 .. uppervarx %initializes array snakex (i) := 0 snakey (i) := 0 end for loop if x < 0 or x > maxx or y < 0 or y > maxy then %checks if snake hits edge exit end if if ball = "not drawn" then %draw balls loop randint (ballx, 5, maxx - 5) randint (bally, 5, maxy - 5) if whatdotcolour (ballx, bally) not= 10 then drawfilloval (ballx, bally, 3, 3, 14) ball := "drawn" end if exit when ball = "drawn" end loop end if if sqrt ((ballx - x) ** 2 + (bally - y) ** 2) < 9 then %checks if it eats ball drawfilloval (ballx, bally, 5, 5, 7) ball_count += 1 counter += 1 ball := "not drawn" % makes ball not drawn so it know to draw a new one last_upper := uppervarx %keeps record of last and new upper bounds of the arrays to initialize new elements % adds elements to array snakex (counter) := uppervarx snakey (counter) := uppervary uppervarx += 15 for i : last_upper + 1 .. uppervarx %initializes new array values to 0 snakex (i) := 0 snakey (i) := 0 end for end if % draws enemies for decreasing i : uppervarx .. 2 % changes places of array snakex (i) := snakex (i - 1) snakey (i) := snakey (i - 1) end for snakex (1) := x %sets x,y to the array snakey (1) := y drawfilloval (x, y, 5, 5, 10) %draws snake drawfilloval (snakex (uppervarx), snakey (uppervary), 5, 5, black) %erases snake Input.KeyDown (chars) if chars (KEY_UP_ARROW) and direction not= "down" then %checks which way to move snake diry := 3 %sets direction snake moves in dirx := 0 direction := "up" %to make sure you can't double back on yourself elsif chars (KEY_RIGHT_ARROW) and direction not= "left" then diry := 0 dirx := 3 direction := "right" elsif chars (KEY_LEFT_ARROW) and direction not= "right" then diry := 0 dirx := -3 direction := "left" elsif chars (KEY_DOWN_ARROW) and direction not= "up" then diry := -3 dirx := 0 direction := "down" end if if direction = "up" and whatdotcolour (x, y + 6) = 10 or whatdotcolour (x, y + 6) = red then %checks if snake hit itself or enemy exit elsif direction = "right" and whatdotcolour (x + 6, y) = 10 or whatdotcolour (x + 6, y) = red then exit elsif direction = "left" and whatdotcolour (x - 6, y) = 10 or whatdotcolour (x - 6, y) = red then exit elsif direction = "down" and whatdotcolour (x, y - 6) = 10 or whatdotcolour (x, y - 6) = red then exit end if x += dirx %adds the direction to make snake move y += diry delay (speed) %changes speed end loop I changed a bit... However, i dont think the array is working... Can someone please help me fix it?!! |