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();
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’;
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