Question: 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 -1 if the Snake is facing backward or 1 if the Snake is facing forward). Initialize the these properties in the constructor so that every new Snake starts at a position of 0 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 if/else statement to do this.
.Include a turn method to change the Snake's direction. Again, use if/else 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!