Computer Science Canada

O i wish it were turing!

Author:  tlivingston [ Tue May 04, 2004 5:58 pm ]
Post subject:  O i wish it were turing!

I know java is a more "powerful" language, lol, but i loved turing! Dont hurt me. lol. But anywas, im building a snake game. I'm going to use an array for each "bit" of the snake and then add array members as the snake gets bigger. To "move" the snake, ill for example make array cords 4= cords 3, cords 3= 2, cords 2=1, and finally give cords 1 the new coordinates based on the users input. This is all fine but im having trouble with the collision. I know i coooullllddd just check the current x and y cords of the "head" of the snake against all the array all the array member cordinates, but what i loved in turing is whatDotColorNext(). Basically it tells you the color of the dot at a pecific x,y cordinate, is there anything like that in java? Also, is there anything liek getch, where i can see if the user is pressing a key, if he is take input, if he isnt move snake. Thanks, ull be hearing from me over the next three weks as that is how long we have to do a whole isp...grrrrr....lol. Thanks,

Ted

Author:  Paul [ Tue May 04, 2004 6:36 pm ]
Post subject: 

I don't think there's a whatdotcolor command in java.
Are u gonna be doing an applet?

Author:  tlivingston [ Tue May 04, 2004 6:44 pm ]
Post subject: 

No def application, unless u have reasons otherwise, but basically i hate applets. lol

Author:  Dan [ Tue May 04, 2004 9:12 pm ]
Post subject: 

pff u do not need whatDotColor, but i do belvie there is somting like that in java.

any how if u have the cordents of the sanke parts why not just check to see if the head of the snake = any of the cordents other the the head of the snake. if it dose the snake has hit it's self. for the walls just do basik line colsione dection, like if x >= what ever it has hit a wall.


just whondering what kind of java are u using? the real stuff or ready to progame by holth?

Author:  tlivingston [ Wed May 05, 2004 3:38 pm ]
Post subject: 

real java....k ya ive got that sorted out....gonna store the snake body parts in an array and then check the head against that, like u said. The last thing which im not totally sure how to use is get keyboard input IF the user is giving input. ill put it in psuedo code to help explain....basically:

do (while gamm="running")
{
if (userInput = "true")
{
key=input;
System.out.println("User pressed: " + key);
}
else
then continue on with next iteration; //nothing on keyboard is being pushed

pause 1 second //=> which is like Thread.sleep(1000)?
}


Any ideas how to do this because we didnt cover input really other then like swing GUI. I think something about a keyboard listener, which im going to look up. Any help on this would be appreaciated and if you could give some sample code/ program or direct me to a site thatd be great.


: