Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello I need help with this assignment, the instructions are bellow and I will also leave the Snake code bellow, thank you in advance .
Hello I need help with this assignment, the instructions are bellow and I will also leave the Snake code bellow, thank you in advanceImplement an immutable D Point class. In the constructor, you should be initializing xcoord and ycoord properties and provide getters but no setters for these two propertiesIn the Snake class, set its initial location to a new Point with x and y coordinates of In the Snake class, introduce turnLeft and turnRight methods. These methods will now need else if statements to appropriately adjust the direction from the four possibilities left right, up and down Leave your turn method in the code but mark it as deprecated in TypeDoc meaning it should no longer be usedModify the move method to also include ifelse ifelse ifelse statements for each of the four directions. Because points are immutable no setters the move method will need to construct new points from the existing ones each time and need to adjust the x or y coordinates by positive or negative depending on the Snake's direction. To do this, you would use this.position new Point filling in the blanks with this.position.x and this.position.y including a for the coordinate that's changing Note: The Snake class is accessing the Point class's getters x and y; it should not access its private data variables xcoord and ycoord directlyNext, implement a WorldModel class which will for now contain one Snake. The class should be an aggregation of a Snake, not a composition so you should create the Snake outside of the class and pass it to the constructorAdd a method updatesteps to the WorldModel class, which will call its one Snake's move method, passing an argument of steps and a getter to retrieve the SnakeUpdate the tests in Snake.test.js to use your new methods correctly. Also, create a new file and add tests in WorldModel.test.ts in which you call the WorldModel's update method. Tell the Snake to turn. Call the update method again. See if the Snake's positions are what you expect them to be Check the tests terminal to make sure all the tests passAfter creating a new Snake, create a new WorldModel, passing this Snake to the constructor. DOCUMENT ALL METHODSCLASSES and run the command to generate the documentation.import display from display; import display from display; place your code on line above the export statement belowclass Snake private currentPosition: number; private currentDirection: number; constructor this.currentPosition ; this.currentDirection ; movedistance: number if thiscurrentPosition this.currentPosition distance; else this.currentPosition distance; turn this.currentDirection ; get position: number return this.currentPosition; export default Snake;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started