ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Test.cpp Source File

Test.cpp

00001 #include "Tests.h"
00002 
00003 Tests::Tests() {} 
00004 
00005 Tests::~Tests() {}
00006 
00007 void Tests::init(int platforms_y) {
00008   // Initialise objects.
00009   _platforms.init(platforms_y);  // Argument is vertical position of platforms.
00010   _coin.init();
00011   _fire.init();
00012   _moving_counter = 0;
00013 }
00014 
00015 void Tests::run_tests(float joy_x, 
00016                float joy_y,
00017                Sprite_value sprite,
00018                int coin_x,
00019                int coin_y,
00020                int fire_y,
00021                int line_1_start,
00022                int line_2_start,
00023                int line_3_start,
00024                int line_length,
00025                N5110 &lcd) {
00026   // Runs tests for each sprite with user input stimulus.
00027   test_skater(joy_x, joy_y, sprite, lcd);
00028   test_coin(coin_x, coin_y, lcd);
00029   test_fire(fire_y, lcd);
00030   test_platforms(line_1_start,
00031                  line_2_start,
00032                  line_3_start, 
00033                  line_length, 
00034                  lcd);
00035 }
00036 
00037 void Tests::test_skater(float joy_x,
00038                         float joy_y, 
00039                         Sprite_value sprite, 
00040                         N5110 &lcd) {
00041   // Prints the skater sprite at coords with given direction and sprite.
00042   lcd.clear(); 
00043   _skater.set_x_position_and_sprite(joy_x, 
00044       _moving_counter, 
00045       Left,
00046       joy_y);  // Sets object with input stimulus. Skate driection is set to 
00047   // left as default, this will not matter and be overwritten when sprite is
00048   // specified by user.    
00049   lcd.drawSprite(_skater.get_x_position(),_skater.get_y_position(),17,10,
00050                 (int *)_skater.get_sprite(sprite));  // Prints object.
00051   lcd.refresh();
00052   wait(1);
00053 }
00054 
00055 void Tests::test_coin(int coin_x, int coin_y, N5110 &lcd) {
00056   // Prints the coin at coords from input.
00057   lcd.clear();
00058   _coin.generate_coin();  // Updates coin sprite.
00059   _coin.set_coin(coin_x,coin_y);  // Sets object with input stimulus.
00060   lcd.drawSprite(_coin.get_coin_x(),_coin.get_coin_y(),5,5,
00061                  (int*)_coin.get_coin_sprite());
00062   lcd.refresh();
00063   wait(0.5);  // Repeat so different sprites of coin are seen more often.
00064   lcd.clear();
00065   _coin.generate_coin();
00066   _coin.set_coin(coin_x,coin_y);
00067   lcd.drawSprite(_coin.get_coin_x(),_coin.get_coin_y(),5,5,
00068                  (int*)_coin.get_coin_sprite());
00069   lcd.refresh();
00070   wait(0.5);
00071 }
00072 
00073 void Tests::test_fire(int fire_y, N5110 &lcd) {
00074   // Prints the fire at given input y coord (x is not accessible to user as 
00075   // automatically moves across screen).
00076   lcd.clear();
00077   _fire.generate_fire();  // Set fire x coord and sprite.
00078   lcd.drawSprite(_fire.get_fire_x(),fire_y,5,8,(int*)_fire.get_fire_sprite());
00079   lcd.refresh();
00080   wait(0.5);  // Repeat so different sprites of fire are seen more often.
00081   lcd.clear();
00082   _fire.generate_fire();
00083   lcd.drawSprite(_fire.get_fire_x(),fire_y,5,8,(int*)_fire.get_fire_sprite());
00084   lcd.refresh();
00085   wait(0.5);
00086   // Print coords of fire (as it is moving) to moniter changes.
00087   printf("Fire x coord = %d, y coord = %d \n",_fire.get_fire_x(), fire_y);  
00088 }
00089 
00090 void Tests::test_platforms(int line_1_start,
00091                  int line_2_start,
00092                  int line_3_start, 
00093                  int line_length, 
00094                  N5110 &lcd) {
00095   // Prints three lines from the single platform object, with lengths and 
00096   // starting positions determined by input stimulus.
00097   lcd.clear();
00098   // Set (with length) and get each line.
00099   _platforms.set_line_1(line_length);
00100   _line_1 = _platforms.get_line_1(); 
00101   _platforms.set_line_2(line_length);
00102   _line_2 = _platforms.get_line_2();
00103   _platforms.set_line_3(line_length);
00104   _line_3 = _platforms.get_line_3();
00105   // Print all three lines.
00106   lcd.drawLine(_line_2.x_start,_line_2.y,_line_2.x_end,
00107                _line_2.y,FILL_BLACK);
00108   lcd.drawLine(_line_1.x_start,_line_1.y,_line_1.x_end,
00109                _line_1.y,FILL_BLACK);
00110   lcd.drawLine(_line_3.x_start,_line_3.y,_line_3.x_end,
00111                _line_3.y,FILL_BLACK);
00112   lcd.refresh();
00113   // Print start coords of each line (as they are moving) to moniter changes.
00114   printf("Line 1 start = %d,\n Line 2 start = %d,\n Line 3 start = %d \n", 
00115          _line_1.x_start,
00116          _line_2.x_start,
00117          _line_3.x_start);
00118   wait(1);                
00119 }
00120                  
00121                  
00122