Answered step by step
Verified Expert Solution
Link Copied!

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 -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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions

Question

1. Does your voice project confidence? Authority?

Answered: 1 week ago