JAVA! This time something half good...

Anything and Everything about Uplink

Moderators: bert_the_turtle, jelco, Chris, Icepick, Rkiver

elDiablo
level5
level5
Posts: 3111
Joined: Thu Mar 14, 2002 12:23 pm
Location: London, UK

JAVA! This time something half good...

Postby elDiablo » Wed Apr 28, 2004 4:08 pm

YEP! It's that time of the week again kiddies. This week... I bring to your viewing pleasure... SNAKE! Yes, a snake clone. In java. Using JFrame.

This is a nice little program. It even has scoring etc. And if you hit yourself, yes, you die :) Comments are something to be desired though. There are some, near the top... about things that are very obvious... OH WELL! :D use wasd to move around, I couldnt be bothered to look up the values for left, right, etc ;)

And as always, this code is free for you all to use, but give credit where credit is due! As, of course, thanks go to Hektik Sniper for hosting it nicely for me here. And if you want some help with it, or even an extended explanation of the code, just ask.

What games would you guys and gurls like to see next btw? Im working on HL2 for java, so dont suggest it, k? :D

CHEERS FOR READING PEOPLE!
elDiablo


Edit

For those (lazy) people who cant get it to compile, the bytecode can be found here, here, here, and finally here. Just download them all, put them all in a directory, and run "java Snake" from that directory. Thats it :) Thanks go to coolsi for hosting those files.

Edit 2

There is a bug! coolsi and Dave2 both found this. DONT PRESS TWO KEYS AT ONCE! If anyone wants, ill make a bug fix, but at the mo, its just the damn engine ppl! stop complaining! :P
We dont stop playing cos we get old... We get old cos we stop playing.
User avatar
LLamaBoy
level5
level5
Posts: 1627
Joined: Sun Aug 18, 2002 12:18 pm
Location: Nicosia, Cyprus
Contact:

Postby LLamaBoy » Wed Apr 28, 2004 4:47 pm

Yay for elDy and his Javaey goodness!

I just wish I had the time/motivation/ideas to do something productive in Java too, but alas, I'm lazy.

Ah well, I'll just have to link you to an old proggy I made: I call it Jangman

[Edit]Sorry about the downtime of the file, Apache's playing up :/ You'll be notified as soon as it's sorted[/Edit]
BlueScreen
level2
level2
Posts: 168
Joined: Mon Mar 11, 2002 11:53 am
Contact:

some modifications...

Postby BlueScreen » Wed Apr 28, 2004 6:47 pm

do you really want the food to keep jumping around every so often? if not remove or coment out (/* ... */) the method

Code: Select all

public void makeNewFoodThread() {

on lines 149 - 165 and replace line 129

Code: Select all

makeNewFoodThread();

with

Code: Select all

drawFood();


The two button press kill is caused by having the method

Code: Select all

 changeDirection(char)

check against the last snakeDirecton value, which, in the case of this bug is being changed before the snake has moved, allowing the snake to do a fatal u-turn.

to remove, insert another variable, (ie snakeOldDirection) which gets updated only after the snake has moved, in the

Code: Select all

public void moveSnake() {

method, after the switch statement, before the close of the else statement, on about line 360
the the switch statement in the

Code: Select all

 changeDirection(char)

method needs the case if statments changed to:

Code: Select all

if (snakeOldDirection != #) {
(except replace the # with the numbers which are in the statements already), lines 305, 312, 319, 326
Since we cannot know all that there is to be known about anything, we ought to know a little about everything.  Blaise Pascal (1623 - 1662)
<damn 255 char sig limit>
User avatar
LLamaBoy
level5
level5
Posts: 1627
Joined: Sun Aug 18, 2002 12:18 pm
Location: Nicosia, Cyprus
Contact:

Postby LLamaBoy » Wed Apr 28, 2004 8:53 pm

I'm currently editing it to be BETTAR than elD's pitiful effort :P
I've already put a restart option when you die... Once i get hosting (coolsi?) I'll put the edited version up.
elDiablo
level5
level5
Posts: 3111
Joined: Thu Mar 14, 2002 12:23 pm
Location: London, UK

Postby elDiablo » Wed Apr 28, 2004 9:12 pm

BlueScreen, takes for those comments. I didnt even think about the 2 key fatal u-turn when i was making it. I made it stop doing this by only letting you change dir once per snake movement update :) thanks for you (very) indepth idea though! Its nice to see someone else take an interest in my code! :D LlamaBoy dont count ;) he's rubbish at coding :D

Also, I do want the food to kept moving around, to make it a bit more of a challenge. The problem was with the food, that it jumps too quickly sometime. This is due to the foodMovingThread is sleeping, and i call the drawFood method when it is still sleeping. Thus, it calls the drawFood method when it is finished waiting, which COULD (theortically) be a split second after the food has just moved :)


And finally, although i do like peoples comments and "constructive" put downs, I did make this in 2 hours after finishing my coursework today ;) so dont be too hard? :D

And LlamaBoy, you know i pwn you at coding ;)
We dont stop playing cos we get old... We get old cos we stop playing.
Sonnybobiche
level3
level3
Posts: 432
Joined: Mon Dec 24, 2001 1:12 pm
Contact:

Postby Sonnybobiche » Fri Apr 30, 2004 3:20 pm

I like the creative names you gave to your methods. checkSnakeIsntEatingFood() is a good one... lol.
gj on the coding.
If at first you don't succeed, skydiving is not for you...
elDiablo
level5
level5
Posts: 3111
Joined: Thu Mar 14, 2002 12:23 pm
Location: London, UK

Postby elDiablo » Fri Apr 30, 2004 8:02 pm

THANK YOU! :D I like people to know what I'm talking about when I code ;) makes it easier!

And thaks for the good job bit!
We dont stop playing cos we get old... We get old cos we stop playing.
exosyphen
level2
level2
Posts: 240
Joined: Wed Jul 02, 2003 8:14 am
Location: Romania
Contact:

Postby exosyphen » Fri Apr 30, 2004 9:50 pm

How do i get rid of the tracer in this game !?

Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests