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

Username:   Password: 
 RegisterRegister   
 Snake program
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
white_dragon




PostPosted: Sat Feb 07, 2004 5:13 pm   Post subject: Snake program

tis is my snake program but i dunno how to make it so than 2 ppl can press a key at the same time and the snake moves. also, i dunno how i make it so when a person collides with the other person, it stops. can someone help me? Confused . i am hopelessly confused. i only spent about 3 months in turing............


Snake game.t
 Description:

Download
 Filename:  Snake game.t
 Filesize:  619 Bytes
 Downloaded:  586 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Sat Feb 07, 2004 5:14 pm   Post subject: (No subject)

read up on Input.Keydown
white_dragon




PostPosted: Sat Feb 07, 2004 5:18 pm   Post subject: (No subject)

tks. but i still dunno how 2 put it back into da program
santabruzer




PostPosted: Sat Feb 07, 2004 5:37 pm   Post subject: (No subject)

... enjoy:

code:
setscreen ("graphics:400;400,nocursor")
var chars : array char of boolean
var cellsize := 20
var ch : string (1)
var x, y := 3
var leftright, updown : int := 0 % 1 for first word, 2 for second, 0 for nothing
var lsnake := 3
var count := 1

proc drawboard
    drawbox (0, 0, maxx, maxy, 7)
    for i : 1 .. 20
        drawline (i * 20, 0, i * 20, maxy, 7)
        drawline (0, i * 20, maxx, i * 20, 7)
    end for
end drawboard

proc drawcell (row, col, clr : int)
    var temprow := row - 1
    var tempcol := col - 1
    drawfillbox (temprow * cellsize, tempcol * cellsize, row * cellsize, col * cellsize, clr)
end drawcell

loop

    Input.KeyDown (chars)
    delay (50)
    if chars (KEY_UP_ARROW) then
        y += 1
    elsif chars (KEY_DOWN_ARROW) then
        y -= 1
    elsif chars (KEY_LEFT_ARROW) then
        x -= 1
    elsif chars (KEY_RIGHT_ARROW) then
        x += 1
    end if
        drawcell (x, y, 7)
    drawboard
    if count = lsnake then
        count := 1
    end if
end loop
Paul




PostPosted: Sat Feb 07, 2004 5:39 pm   Post subject: (No subject)

This is the basic movement with Input.KeyDown
code:

%Snake game
setscreen ("nocursor")
setscreen ("noecho")
var chars : array char of boolean
var x, y : int := 100
var d, e : int := 150
var a : string (1)
var b : string (1)
loop
    Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        x := x + 2
elsif chars (KEY_LEFT_ARROW) then
        x := x - 2
elsif chars (KEY_UP_ARROW) then
        y := y + 2
elsif chars (KEY_DOWN_ARROW) then
        y := y - 2
end if
    delay (30)
    drawfilloval (x, y, 2, 2, 50)

end loop

Edit: Darn it, santabruzer is faster again... I was experimenting with erasing its tail after its gone a bit.
white_dragon




PostPosted: Sat Feb 07, 2004 5:39 pm   Post subject: (No subject)

lol tks. i got some lines from ur program and got da idea. but i still don't how 2 make some borders so it doesn't go past it.
santabruzer




PostPosted: Sat Feb 07, 2004 5:43 pm   Post subject: (No subject)

the hardest thing in this program.. was the fact that you have to keep the snake size.. i was thinking of using a flexible array, when i attacked the challenge.. and then i got bored.. was i on the right path?
Paul




PostPosted: Sat Feb 07, 2004 5:45 pm   Post subject: (No subject)

Hehe, I have no idea, I thought about storing the co-ordinates in an array or something, then when the snake went a certain distance, you'd draw white dots at those previous coordinates, but my idea is probably stupid.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Feb 07, 2004 5:52 pm   Post subject: (No subject)

do it the whatdotcolour way Smile

in the Input.KeyDown part, whenever an arrow key is hit, a counter goes up. you'd need an array to hold the x and y values of the snake's body circles thingys. then when the counter = 10 or whatever, make the counter go down by 1 (so it = 9) and draw a white dot over the last x and the last y in the array.

for collisions, use whatdotcolour Smile
white_dragon




PostPosted: Sat Feb 07, 2004 6:02 pm   Post subject: (No subject)

thank u all sincerely for your help! i come here very often 2 look for help n i always get it!!!!!!!!!!1 Very Happy Very Happy Very Happy Very Happy u guys are all so nice. i'm only 11 years old n my class mates n teacher hate me. i guess tat's how life is.......... *sigh* tks for all the help
recneps




PostPosted: Sun Feb 08, 2004 4:08 pm   Post subject: (No subject)

you can take turing at 11 yrs old?! and for the keydow with more than one person, you gotta put each if statement separately (if blah
end if
if blah
end if)
the_short1




PostPosted: Sun Feb 08, 2004 6:07 pm   Post subject: (No subject)

nice... Post as a .exe when its done... it willl be a hit with my sis.. shes addicted to that Game.....
white_dragon




PostPosted: Mon Feb 09, 2004 4:37 pm   Post subject: (No subject)

yeah. i did skip tat many grades. lol
the_short1




PostPosted: Mon Feb 09, 2004 5:03 pm   Post subject: (No subject)

crazy.... i think it would kind of suck to be that young in high school.... everyone would think u a weak little sh!t cuz ur younger and start beating you up....... but then u got braging rights to be smarter then people that are like 4 years older then you.. hahhahah....

Anyway.... it would be kinda cool if you made you steps in incriments

Maybe integrate into this....
I think it is a Wicked Grid program and the movement rocks....
Also a idea....<<ask the user to input player 1 Color,name, and player 2 name and color... then when you crash you can say who lost... and to colorfy it too....Have FUn.,.,.,.
Paul




PostPosted: Mon Feb 09, 2004 5:04 pm   Post subject: (No subject)

Ah, my eyes, you can't look at that program for too long, the lines are too close together. And it says battleship Razz.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: