JavaScript - Help With Snakes And Ladders
Hi, I am stuck.
I have been given the task of writing snakes and ladders as a one player version. But am struggling with the rest of it. I know its nearly there but just cant figure out where i am going wrong for the rest of it. Please help, thanks in advance Code: <HTML> <HEAD> <TITLE> Snakes and Ladders </TITLE> <SCRIPT LANGUAGE = "JavaScript"> /* * M150 TMA03 2010J Q4. * Program to simulate a one-player version of 'Snakes and Ladders' */ //PROVIDED FUNCTIONS -- you do not need to change these /* *imitates a normal 6-sided die, by returning a random whole number between 1 and 6 inclusive. */ function rollDie() { return Math.floor(Math.random() * 6) + 1; } /* *searches for a number in a number array. * *function takes two arguments * the number to search for * the number array to search *function returns the array index at which the number was found, or -1 if not found. */ function findIndexOf(number, numberArray) { var indexWhereFound = -1; for (var position = 0; position < numberArray.length; position = position + 1) { if (numberArray[position] == number) { indexWhereFound = position; } } return indexWhereFound; } //ARRAYS that represent the board -- you do not need to change these //array of special squares var specialSquaresArray = [1,7,25,32,39,46,65,68,71,77]; //array of corresponding squares the player ascends or descends to var connectedSquaresArray = [20,9,29,13,51,41,79,73,35,58]; //VARIABLES used -- you do not need to change these //the square the player is currently on var playersPosition; //play is initially at START playersPosition = 0; //what they score when they roll the die var playersScore; //the index of the player's position in the special squares array or -1 //var indexOfNumber; //MAIN PROGRAM //TODO add code here for parts (iii), (iv)(b), (v), and (vi) //(iv) (b) var returned; var specA; var specB; while (playersPosition <= 80) //{ //(iii) playersScore = rollDie(); document.write ('Sco ' + playersScore); playersPosition = playersPosition + playersScore; document.write (' Squa ' + playersPosition); findIndexOf (playersPosition, specialSquaresArray); returned = indexWhereFound; if (returned != -1) { findIndexOf (returned, connectedSquaresArray); returned = indexWhereFound; playersPosition = returned; document.write (' Ladder to Squa '); } document.write ('<BR>'); //(v) /*Now add code to your program which will: ! declare and initialise a variable to keep count of how many goes the player takes to get out; ! add one to this count every time the loop is repeated; ! write out the count in a suitable message at the end. */ document.write('It Took goes to get out.'); document.write ('this is the final count'+ count); //(vi) if { indexwherefound > 10; document.write('The player is out'); </SCRIPT> </HEAD> <BODY> </BODY> </HTML> Similar TutorialsOk so I'm in college and I'm taking my first web development class online. Unfortunate my teacher is awful. We have already "covered" html and some css and done a bit of java such as creating a prompt and a super simple calculator. However, for the final I have to make a 2 player game with at least 30 spaces and dice (random number generator). More importantly our "learn javascript in 24 hours" book doesn't cover this at all and my teacher is MIA like always. So, I have come to you all for help. I found a sample script that is almost exactly what I need for this project but it needs a bit of tweaking http://javascript.internet.com/games...ders-game.html I need to add 5 additional spaces and I wanted to add a ladder from space 24-27 and change the chute from 16-6 to 25-6. Unfortunately I'm kind of clueless on how to do this and make sure everything works properly.... Here is an image I made real quick of what I want it to look like And this is the requirements for the project. * Minimum Requirements for a C: o 2 players o 20 steps on the board o Random number generator o Game displays the location of each player on the board * Minimum Requirements for a B: o Everything above plus o Attractive user interface. o 30 steps on the board o Graphical random number generator (Example: Display the number as a dice image) * Minimum Requirements for an A: o Everything above plus o Educational game that shows facts as the players move around the game. Any help at all would be amazing and greatly appreciated |