please complete in C++ and do whats in the diagram (box) only.
thank you, i will rate!
CS 162 - Programming Assignment 5 - Game Class Part 1 The purpose of this assignment is to give you additional practice creating more complex classes and using pointers in C++. Overview This program is the final step in your implementation of the game of Snake. I recommend you play the game to get a feel for what we are going to create this term. In this assignment you'll leverage SFML to complete the graphical elements of the Game class, resulting in a playable game. Game mySnake : Snake myApple : Apple snakeFit(): bool appleFit(): bool snakeFoundApple(): bool snakeEatApple(): void playGame(): void Details Write all the code necessary to implement the Game class as shown in the UML Class Diagram to the right. Your class definition and implementation should be in separate files, which you'll add to your previous snake project. When complete, the project should contain the following 8 source files: location.h and .cpp (from previous assignment) .apple.h and .cpp (from previous assignment) snake.h and .cpp (from previous assignment) game.h - the header file for your new Game class game.cpp - class implementation for your new Game class Data details are as follows: mySnake A pointer to a Snake object myApple A pointer to an Apple object Function details are as follows: Game() Initialize both pointers to nullptr. (constructor) -Game() (destructor) Check to see if your pointers are null. If not, delete the allocated memory and set them to nullptr. Function details are as follows: Game() Initialize both pointers to nullptr. (constructor) -Game) Check to see if your pointers are null. If not, delete the allocated memory and set them (destructor) to nullptr. snakeFit() The purpose of this method is to make sure mySnake is still alive and well on the board. You can return false if any of the following checks fail: The snake's head has gone off the board in any direction The snake's tail has gone off the board in any direction The snake's head has run into any part of its body If all 3 of those checks pass, return true. appleFit() The purpose of this method is to make sure a new apple isn't going to spawn on any part of my Snake. Get the location of myApple. Get the snake array. Then check to make sure the location of myApple doesn't conflict with any valid indexes in the snake array (remember, if a Location in the snake array is (-1,-1) you need not worry about it since there isn't actually anything there). If you find a conflict (apple location is the same as some valid part of the snake's body), return false. Otherwise, return true. snake FoundApple() The purpose of this method is to determine whether the snake has found an apple snake FoundApple() The purpose of this method is to determine whether the snake has found an apple during game play. This will be true if the location of mySnake's head is the same as the location of myApple. snake EatApple() The purpose of this method is to make the snake grow in length by one square. We will only call this method in the game if the snake actually found an apple. To make the snake grow, you need to create a new "tail" right behind the existing tail by populating a new Location in mySnake's array. Keep in mind that the row/col Location of the new tail will depend on how the snake is oriented on the board right now. I determined the orientation by comparing the Location of the current tail to the Location of the body part right before it. playGame() Place the following test code in your playGame method. Next week we will modify this method to create the game logic. Il create a new snake mySnake = new Snake; Il since the snake hasn't moved yet and you should be starting it on the board, it Il should definitely fit! if (IsnakeFit() std::cout getSnakeHead().getRow() getSnakeHead().getCol() getAppleLocation().getRow() getApple Location().getCol() getAppleLocation(); Il arbitrarily try orienting the snake's tail so that the snake is facing up... If this Il doesn't work because // the apple is on the bottom row, I'll flip the snake around newSnake[1].setLocation(newSnake[0].getRow() + 1, newSnake[0].getCol(); if(IsnakeFit() newSnake[1].setLocation(newSnake[0].getRow() - 1. newSnake[0).getCol(): mySnake->setSnakeArray(newSnake); Il now mySnake should be on the apple and not hanging off the board if (snakeFoundApple()) { Location snake Copy[MAX_SNAKE_SIZE); std::cout getSnakeArray(snakeCopy); std::cout getSnakeArray(snakeCopy); std::cout getSnake Array(snakeCopy): std::cout getSnakeHead().getRow() getSnakeHead().getCol() getAppleLocation().getRow() getApple Location().getCol() getAppleLocation(); Il arbitrarily try orienting the snake's tail so that the snake is facing up... If this Il doesn't work because // the apple is on the bottom row, I'll flip the snake around newSnake[1].setLocation(newSnake[0].getRow() + 1, newSnake[0].getCol(); if(IsnakeFit() newSnake[1].setLocation(newSnake[0].getRow() - 1. newSnake[0).getCol(): mySnake->setSnakeArray(newSnake); Il now mySnake should be on the apple and not hanging off the board if (snakeFoundApple()) { Location snake Copy[MAX_SNAKE_SIZE); std::cout getSnakeArray(snakeCopy); std::cout getSnakeArray(snakeCopy); std::cout getSnake Array(snakeCopy): std::cout