Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
Diff: GameObjects/Snake/Snake-test.h
- Revision:
- 74:7b6568bc16d5
- Parent:
- 70:7caab8069b9b
- Child:
- 75:f00c79f79b6a
diff -r 80556a279962 -r 7b6568bc16d5 GameObjects/Snake/Snake-test.h --- a/GameObjects/Snake/Snake-test.h Sun May 05 10:58:33 2019 +0000 +++ b/GameObjects/Snake/Snake-test.h Sun May 05 11:46:08 2019 +0000 @@ -33,22 +33,86 @@ snake.update(d, b); // Read the position - Vector2D read_pos_2 = snake.get_pos(0); + Vector2D read_pos_2 = snake.get_pos(0); //getting the position of the first beed printf("%f, %f\n", read_pos_2.x, read_pos_2.y); - // Now check that both the positions are as expected + // Set the direction to E and set snake motion free by setting b as 1; + d = E; + + for(int i=0; i<=9; i++) { + b[i] = 1; + } + + // Update the snake position + snake.update(d, b); + + // Read the position + Vector2D read_pos_3 = snake.get_pos(0); //getting the position of the first beed + printf("%f, %f\n", read_pos_3.x, read_pos_3.y); + + + // Set the direction to W, length and speed both to 10 and set snake motion stopped by setting b as 0; + d = W; + snake.init(10, 10); + + for(int i=0; i<=9; i++) { + b[i] = 0; + } + + // Update the snake position + snake.update(d, b); + + // Read the position + Vector2D read_pos_4 = snake.get_pos(0); //getting the position of the first beed + printf("%f, %f\n", read_pos_4.x, read_pos_4.y); + + + // Set the direction to W, length to 20 and speed to 2 and set snake motion free by setting b as 1; + d = W; + snake.init(20, 2); + + for(int i=0; i<=9; i++) { + b[i] = 1; + } + + // Update the snake position 3 times because i want to read the position of the third bead that only mooves with a chain reaction. + snake.update(d, b); + snake.update(d, b); + snake.update(d, b); + + // Read the position + Vector2D read_pos_5 = snake.get_pos(2); //getting the position of the third beed + printf("%f, %f\n", read_pos_5.x, read_pos_5.y); + + + // Now check that all 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. + if (read_pos_1.x != WIDTH/2 || read_pos_1.y != 18) { //18 because I'm testing the position of the first snake beed, from the top. + success_flag = false; + } + + // Fail the test if the final position after moving West is wrong + if (read_pos_2.x != ((WIDTH/2)-2) || read_pos_2.y != 18) { //18 because I'm testing the position of the first snake beed, from the top and ((WIDTH/2)-2) because speed is set to 2. 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. + // Fail the test if the final position after moving East is wrong + if (read_pos_3.x != ((WIDTH/2)) || read_pos_3.y != 18) { //18 because I'm testing the position of the first snake beed, from the top and ((WIDTH/2)) because speed is set to 2 + //and it moves back from its previous position. success_flag = false; } + // Fail the test if the final position after moving West but stopping motion using b[i] = 0; is wrong. + if (read_pos_4.x != ((WIDTH/2)) || read_pos_4.y != 18) { //18 because I'm testing the position of the first snake beed, from the top and ((WIDTH/2)) because it is not meant to moove. + success_flag = false; + } + + // Fail the test if the final position of the third beed after moving West and after 3 itterations; is wrong. + if (read_pos_5.x != ((WIDTH/2)-2) || read_pos_5.y != 24) { //24 because I'm testing the position of the third snake beed, from the top and ((WIDTH/2)) because it is not meant to moove. + success_flag = false; + } return success_flag; } #endif \ No newline at end of file