/    Sign up×
Community /Pin to ProfileBookmark

Small Problem in game Design

Hi I am Designing a Game(Snake – used on nokia Phones) in javascript.

I am using an array of td’s as my background and then with user inputs I can simulate the movements using css.I have attached my Code below. in a file called stage8.zip which has a file called stage8Tp.html this file is Executable in a sense as I have put the Css in a style tag.

The problem I am having is that I am unable to make the snake a fixed size.

Now i am using 2 methods draw() and erase() to draw the head of the Snake and Erase to erase its left overs. The way i have managed to do is the game can draw one Td and erase the one before.

Now according to what I have learnt (my logic) I should be able to use an array to give the snake a Fixed length.

This is the Code now

[code]
function drawSnake() {
tableobj = document.getElementById(‘Table1’);
tdarray = tableobj.getElementsByTagName(‘td’);
ea = ta;
ta = ta + dir;
detect();
tdarray[ta].className=’snakeF’;
rc =window.setTimeout(“drawSnake();”,800);
eraseSnake();

[/code]

this basicly Draws the front and calls the method again before it erases the current position of the snake.

Now to record the movement I though we can use an array and impliment the same code with something like this

[code]
function drawSnake() {
tableobj = document.getElementById(‘Table1’);
tdarray = tableobj.getElementsByTagName(‘td’);
ea = ta;
ta = ta + dir;
detect();
arr = [ta].concat(arr);
lst = arr[arr.length-1];
var ft =arr[0]; // one End of the Array
tdarray[ft].className=’ground’; // Should be 1 end of the Array
tdarray[lst].className=’snakeF’;
[/code]

Any Suggestion hear will be Valuable. I am also open to new Techniques I can use to do this thanks

[upl-file uuid=0dd61845-80e9-4671-8274-301e6b6f3020 size=2kB]stage8tp.zip[/upl-file]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Adi5402 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...