Variables and Functions

Variables and Functions used in the Code-

Variables   –

j – Integer used in checking if position of the snake matched the death condition. Used as a value in a for loop.

Food – A class containing a Vector class named pos and a function named Draw(). The functions’ descriptions’ can be found in the Functions section below. The function’s description can be found in the Functions section below.

Food f[5] – A vector containing instances of Food. This will be used to place the food on the screen. The function’s description’s can be found in the Functions section below.

Vector-  A class containing integers x and y, and four functions: Vector(), Vector (int, int) Add(Vector), Equals(Vector). Variables x and y are position locations. The functions’ descriptions’ can be found in the Functions section below.

SnakeDot –  A class containing an instance of Vector named pos, and a function named Draw(). The function’s description can be found in the Functions section below.

Snake – A class containing an instance of Vector named pos and the function Draw.  The function’s description can be found in the Functions section.

snake – An instance of class Snake that is used to represent the main snake that is passed among the various functions.

i – An integer variable used to determine the amount of food generated. It increases within a for loop to count the amount of food on screen.

k = A variable used to return the result of the check to see if the snake has met any death conditions.

x – A variable used in a numerous places that always represents the x coordinate of an object.

y -A variable used in a numerous places that always represents the y coordinate of an object.

Place – An integer used in the menufolder function that represents the location in the menu. This variable only works between 0 and 5 and resets itself to 0 if tit strays these bounds.

Functions –

Vector::Vector() – Constructor for the Vector class. Sets the default x and y equal to 0.

Vector::Vector(int x1, int y1) – A function inside class Vector used to update the position of an object on screen. x1 and y1 are the new locations for the snake.

Vector:: Add(Vector v) – A function inside class Vector that is used as temporary velocity change for the snake.  The Vector v is an instance of the class to which the velocity is being saved.

Vector:: Equals( Vector v) – A function inside class Vector used toreset the velocity of the snake. This function is called after every button click so the snake does not get faster, but rather takes a new velocity.

Food::Draw() – Contained inside class Food,  this function draws the white rectangles at the locations found using a random function in the regenfood function.

Snake::Snake() – A constructor for snake that sets the initial body length, numDots equal to three and generates this body in the middle of the screen.

Snake::Draw() – A function inside Snake that draws the number of body parts needed until the length of the snake equals the number of food eaten plus the starting length.

Snake::GetInput() – A function inside Snake that is responsible for the control of the snake. At every button press the snake receives a new velocity in the x or y direction that is added to the velocity variable in the class.

Snake::Update()- A function inside class Snake, this function updates the body length of the snake, numDots, inside a for loop by moving the front square and redrawing the rest of the snake one location ahead of where it was.

SnakeDot::Draw() – A function within SnakeDot, this draws the body of the snake in the current location, x and y.

regenfood(Food f[], int i) – The main function used to generate food. Using a instance of class Food input, the function looks at the location of the food and which one was eaten, the integer. The function then rewrites over that location and redraws another piece of food somewhere else on the board to make sure that the number of food locations remains the same.

checkdeath(SnakeDot dots[]) – The kill function for the snake. The function checks to see if any portion of the snake is in either in contact with itself or with a wall. If this is true, the game will end.

drawborder() – Draws the outline borders of the game. Four rectangles are drawn on the screen in yellow.

menufolder() – This function contains the top menu for the game. After every input by the user, the menu is reprinted to represent what is currently selected. Based on the selection made the function then either calls that function to be run, or it quits out of the function to go to the game.

rulesdisplay() – Prints the four lines of rules to the screen. These are then left there for a few seconds and then the user is returned to the menu.

Leaderboard(Leaderboard[])- Prints the last 50 scores recorded from highest to lowest. Score is determined by the amount of food eaten before dying.

Credits()- Prints the credits to the screen.