Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
GameObjects/Snake/Snake-test.h
- Committer:
- AhmedPlaymaker
- Date:
- 2019-05-04
- Revision:
- 70:7caab8069b9b
- Parent:
- 69:55e309da7efd
- Child:
- 74:7b6568bc16d5
File content as of revision 70:7caab8069b9b:
#ifndef SNAKE_TEST_H #define SNAKE_TEST_H /** * \brief Check that Snake object goes to correct position when moved * * \returns true if all the tests passed */ bool Snake_test_movement() { // Create Snake object with a length of 15, and x axis speed of 2. Snake snake; snake.init(15, 2); // Set the position to WIDTH/2, HEIGHT - 3 Vector2D initial_pos = {WIDTH/2, HEIGHT - 3}; //Spawns player sprite near the middle of the screen. snake.set_pos(initial_pos); // Read the position Vector2D read_pos_1 = snake.get_pos(0); printf("%f, %f\n", read_pos_1.x, read_pos_1.y); // Set the direction to W and set snake motion free by setting b as 1; Direction d = W; int b[10]; //each element in this array represents the beed number in the snake. for(int i=0; i<=9; i++) { b[i] = 1; } // Update the snake position snake.update(d, b); // Read the position Vector2D read_pos_2 = snake.get_pos(0); printf("%f, %f\n", read_pos_2.x, read_pos_2.y); // Now check that both the positions are as expected bool success_flag = true; // Fail the test if the initial position is wrong if (read_pos_1.x != WIDTH/2 || read_pos_1.y != 18) { //18 because I'm testing the position of the last snake beed. success_flag = false; } // Fail the test if the final position is wrong if (read_pos_2.x != ((WIDTH/2)-2) || read_pos_2.y != 18) { //18 because I'm testing the position of the last snake beed and ((WIDTH/2)-2) because speed is set to 2. success_flag = false; } return success_flag; } #endif