[Solved]Javascript Prelab Write Code Control Player Movement 2d Grid Simple Puzzle Game Inspired 1 Q37170574
In Javascript
In this PreLab you will write the code to control playermovement through a 2d grid of a simple puzzle game inspired by the1991 hit game Chip’s Challenge. This is a 2d grid-based puzzle gamewhere the player collects chips to unlock the exit while avoidinghazards and using keys to unlock doors. Save your code from thisPreLab as you’ll combine it with code you’ll write in other partsof the course to develop the game one piece at a time.
As is common in grid-based games the map for each level will berepresented by an array of arrays with integer values where eachinteger represents a different type of tile. For this game we willhave the following tile types with corresponding integers
0floorwhere the player can walk freely1wallthe player cannot walk through walls2crystalincreases the player’s crystal count by 1 and turns this into afloor tile3locked dooracts as a wall. If the player walks into this while they have akey the door will change to a floor tile and the player willlose/use one key4keyincreases the player’s key count by 1 and turns this tile intoa floor5lavakills the player unless the player collected the protectiveboots6bootscollects the protective boots and turns this tile into a floortile7exitacts as a wall. If the player collected every crystal on themap the player advances to the next level
The tiles are stored in row major order starting with the upperleft corner (Note: This means the y-axis is inverted. Decreasingthe y-coordinate move up on the map). For example if the grid is[[1,1,1],[0,2,7],[1,1,1]] then the level will be played on a 3x3grid where the top and bottom rows of the level are all wall tilesand the center row, from left to right, contains a floor tile, acrystal, and the exit. If the player starts on the left-most tileof the second row they would be able to move to the right twice tocomplete the level. To access a tile we will use [x, y] coordinateswhere x is the column number and y is the row number starting fromthe upper left corner and counting from 0. This allows for the tilepoints to correspond with the array indices. For example, the exitwould be at the point [2, 1] and would be accessed withgrid[1][2]
Finally, a level will be represented as an object with the keys”grid” which stored the 2d array of tiles and “start” which is anarray with 2 integers in the format [x, y] which is where theplayer starts the level
Part 1: Now that the format of this game isestablished let’s start writing some functionality one small pieceat a time. For this part, write a function named “movePlayer” thattakes as parameters a JSON string representing a level in theformat above and a string representing the first movement of theplayer. The movement string will be either “w”, “a”, “s”, or “d”based on the direction the player intends to move with “w” for up,”a” for left, “s” for down, and “d” for right. Return the newplayer location as an array in the format [x, y]. Remember to checkfor walls, locked doors, and the exit as the player cannot movethrough these (you can assume the player has no keys and does nothave all the crystals). You may assume that the player did not walkinto a lava tile. If the player walked into the edge of the map itshould be treated as a wall (Ex. walking to the right while alreadyon the right edge of the map shouldn’t move the player)
Expert Answer
Answer to In Javascript In this PreLab you will write the code to control player movement through a 2d grid of a simple puzzle gam… . . .
OR

