Joshua O'hara 201291390

Dependencies:   mbed

Committer:
josh_ohara
Date:
Tue May 26 15:15:46 2020 +0000
Revision:
44:3b904d25ee12
Parent:
39:5d4277548303
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
josh_ohara 15:dde4ce4bf7fe 1 #include "Cover.h"
josh_ohara 15:dde4ce4bf7fe 2
josh_ohara 15:dde4ce4bf7fe 3 Cover::Cover()
josh_ohara 15:dde4ce4bf7fe 4 {
josh_ohara 15:dde4ce4bf7fe 5 }
josh_ohara 15:dde4ce4bf7fe 6
josh_ohara 15:dde4ce4bf7fe 7 Cover::~Cover()
josh_ohara 15:dde4ce4bf7fe 8 {
josh_ohara 15:dde4ce4bf7fe 9 }
josh_ohara 15:dde4ce4bf7fe 10
josh_ohara 31:27c938ec2a11 11 void Cover::init(int x, int y, int no_rocks)
josh_ohara 31:27c938ec2a11 12 {
josh_ohara 31:27c938ec2a11 13 _x = x; //set x and y position
josh_ohara 31:27c938ec2a11 14 _y = y;
josh_ohara 31:27c938ec2a11 15 _rock_number = no_rocks; //set number of rocks in the cover
josh_ohara 31:27c938ec2a11 16 _spacing = 3; //set the spacing between rocks
josh_ohara 31:27c938ec2a11 17 _row_size = 5; //set the number of rocks in each row of the cover
josh_ohara 31:27c938ec2a11 18 create_cover(); //create the vector of rocks
josh_ohara 15:dde4ce4bf7fe 19 }
josh_ohara 15:dde4ce4bf7fe 20
josh_ohara 31:27c938ec2a11 21 void Cover::create_cover()
josh_ohara 31:27c938ec2a11 22 {
josh_ohara 31:27c938ec2a11 23 for (int i = 0; i < _rock_number; i++) { //add _rock_number of rocks to vector
josh_ohara 31:27c938ec2a11 24 int remainder_x_ = i%_row_size; //find the row index of the rock (e.g. the 3rd rock in the row), like x position in vector
josh_ohara 31:27c938ec2a11 25 int remainder_y_ = i/_row_size; //find the column index of the rock (e.g. the 2nd rock in the column), like y position in vector
josh_ohara 31:27c938ec2a11 26 int init_x_ = remainder_x_*_spacing + _x; //set the x position of new rock based on spacing between rocks and the new rocks position in the cover
josh_ohara 31:27c938ec2a11 27 int init_y_ = remainder_y_*_spacing + _y; //set the y position of new rock based on spacing between rocks and the new rocks position in the cover
josh_ohara 31:27c938ec2a11 28 Rock new_rock; //create new rock
josh_ohara 31:27c938ec2a11 29 new_rock.init(init_x_, init_y_, _spacing); //initialise new rock, spacing is equal to size as the rocks are all touching
josh_ohara 31:27c938ec2a11 30 _alien_cover.push_back(new_rock); //add new rock to vector
josh_ohara 15:dde4ce4bf7fe 31
josh_ohara 15:dde4ce4bf7fe 32 }
josh_ohara 15:dde4ce4bf7fe 33 }
josh_ohara 15:dde4ce4bf7fe 34
josh_ohara 31:27c938ec2a11 35 void Cover::render(N5110 &lcd)
josh_ohara 31:27c938ec2a11 36 {
josh_ohara 31:27c938ec2a11 37 for (int i = 0; i < _alien_cover.size(); i++) {
josh_ohara 31:27c938ec2a11 38 _alien_cover[i].render(lcd); //draw all rocks in the cover vector
josh_ohara 15:dde4ce4bf7fe 39 }
josh_ohara 15:dde4ce4bf7fe 40 }
josh_ohara 15:dde4ce4bf7fe 41
josh_ohara 31:27c938ec2a11 42 vector<Rock> Cover::get_vector()
josh_ohara 31:27c938ec2a11 43 {
josh_ohara 31:27c938ec2a11 44 vector<Rock> v = _alien_cover;
josh_ohara 31:27c938ec2a11 45 return v; //return a copy of the vector of rocks
josh_ohara 15:dde4ce4bf7fe 46 }
josh_ohara 15:dde4ce4bf7fe 47
josh_ohara 31:27c938ec2a11 48 void Cover::set_life(int i, bool x)
josh_ohara 31:27c938ec2a11 49 {
josh_ohara 39:5d4277548303 50 _alien_cover[i].set_life(x); //set the life variable of rock i in the cover
josh_ohara 31:27c938ec2a11 51 }
josh_ohara 31:27c938ec2a11 52
josh_ohara 31:27c938ec2a11 53 bool Cover::get_life(int i)
josh_ohara 31:27c938ec2a11 54 {
josh_ohara 39:5d4277548303 55 return _alien_cover[i].get_life(); //return the life value of rock i in the cover
josh_ohara 31:27c938ec2a11 56 }