Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello I need help with this,I have done what I think is the correct code but I want to compare with yours please,thank you :
Hello I need help with this,I have done what I think is the correct code but I want to compare with yours please,thank you :
Define the Snake class in Snake.ts
In your class definition, include private attributes of currentPosition and currentDirection. They can both be numbers for example, currentDirection could be if the Snake is facing backward or if the Snake is facing forward Initialize the these properties in the constructor so that every new Snake starts at a position of and faces forward.
Include a move method with a parameter variable that will hold the number of squares to move. If the Snake is facing forward, increase its position by the given number. If the Snake is facing backward, decrease its position by the given number. Use an ifelse statement to do this.
Include a turn method to change the Snake's direction. Again, use ifelse statements. If it's facing forward, turn it backward and vice versa.
Finally, include a getter to get its current position. Use position.
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