
Final Commit
Dependencies: mbed
Snake/Snake-test.h@27:bd0f69a75d8b, 2018-05-08 (annotated)
- Committer:
- JRM1986
- Date:
- Tue May 08 12:32:46 2018 +0000
- Revision:
- 27:bd0f69a75d8b
- Parent:
- 25:f03439ee32c6
Final Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JRM1986 | 25:f03439ee32c6 | 1 | #ifndef SNAKE_TEST_H |
JRM1986 | 25:f03439ee32c6 | 2 | #define SNAKE_TEST_H |
JRM1986 | 25:f03439ee32c6 | 3 | |
JRM1986 | 25:f03439ee32c6 | 4 | |
JRM1986 | 25:f03439ee32c6 | 5 | /** |
JRM1986 | 25:f03439ee32c6 | 6 | * \brief Check that food changes position within game area |
JRM1986 | 25:f03439ee32c6 | 7 | * |
JRM1986 | 25:f03439ee32c6 | 8 | * \returns true if all the tests passed |
JRM1986 | 25:f03439ee32c6 | 9 | */ |
JRM1986 | 25:f03439ee32c6 | 10 | |
JRM1986 | 25:f03439ee32c6 | 11 | bool snake_test_movement() |
JRM1986 | 25:f03439ee32c6 | 12 | { |
JRM1986 | 25:f03439ee32c6 | 13 | bool success_flag = true; |
JRM1986 | 25:f03439ee32c6 | 14 | |
JRM1986 | 25:f03439ee32c6 | 15 | Snake snake; |
JRM1986 | 25:f03439ee32c6 | 16 | |
JRM1986 | 25:f03439ee32c6 | 17 | // next diretion test |
JRM1986 | 25:f03439ee32c6 | 18 | |
JRM1986 | 25:f03439ee32c6 | 19 | snake.set_current_direction(S); |
JRM1986 | 25:f03439ee32c6 | 20 | snake.set_snake_direction(N,S); |
JRM1986 | 25:f03439ee32c6 | 21 | Direction next = snake.get_snake_direction(); |
JRM1986 | 25:f03439ee32c6 | 22 | snake.set_snake_position(next); |
JRM1986 | 25:f03439ee32c6 | 23 | Vector2D pos = snake.get_snake_position(); |
JRM1986 | 25:f03439ee32c6 | 24 | |
JRM1986 | 25:f03439ee32c6 | 25 | |
JRM1986 | 25:f03439ee32c6 | 26 | printf("%c", next); |
JRM1986 | 25:f03439ee32c6 | 27 | |
JRM1986 | 25:f03439ee32c6 | 28 | printf("Position %f, %f", pos.x, pos.y); |
JRM1986 | 25:f03439ee32c6 | 29 | |
JRM1986 | 25:f03439ee32c6 | 30 | if(next == !S) { |
JRM1986 | 25:f03439ee32c6 | 31 | |
JRM1986 | 25:f03439ee32c6 | 32 | success_flag = false; |
JRM1986 | 25:f03439ee32c6 | 33 | |
JRM1986 | 25:f03439ee32c6 | 34 | } |
JRM1986 | 25:f03439ee32c6 | 35 | |
JRM1986 | 25:f03439ee32c6 | 36 | if((pos.x != 0) && (pos.y != 1)) { |
JRM1986 | 25:f03439ee32c6 | 37 | |
JRM1986 | 25:f03439ee32c6 | 38 | success_flag = false; |
JRM1986 | 25:f03439ee32c6 | 39 | |
JRM1986 | 25:f03439ee32c6 | 40 | } |
JRM1986 | 25:f03439ee32c6 | 41 | |
JRM1986 | 25:f03439ee32c6 | 42 | return success_flag; |
JRM1986 | 25:f03439ee32c6 | 43 | |
JRM1986 | 25:f03439ee32c6 | 44 | |
JRM1986 | 25:f03439ee32c6 | 45 | } |
JRM1986 | 25:f03439ee32c6 | 46 | #endif |