Skip to content

10 moved ship definitions into source file #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions shm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ set(THIS_PROJECT_SRC_DIRECTORIES
source/Map.cpp
source/Game.cpp
source/Cargo.cpp
source/Player.cpp
source/Ship.cpp
)
set(THIS_PROJECT_TESTS_DIRECTORIES
)
Expand Down
83 changes: 83 additions & 0 deletions shm/source/Ship.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "Ship.hpp"
#include "Cargo.hpp"
//#include "Delegate.hpp"
//#include "Tieme.hpp"

#include <algorithm>

Ship::Ship()
: Ship(0, 0, 0, "", -1)
{}

Ship::Ship(int maxCrew, int speed, size_t id)
: Ship(0, maxCrew, speed, "", id)
{}

// Ship::Ship(int capacity, int crew, int speed, std::string name, size_t id, Time* time);

Ship::Ship(int capacity, int maxCrew, int speed, const std::string& name, size_t id)
: name_(name)
, capacity_(capacity)
, maxCrew_(maxCrew)
, id_(id)
, crew_(0)
, speed_(speed)
, cargo_()
{}

// ~ Ship::Ship() override;

void Ship::setName(const std::string& name) { name_ = name; }

Ship& Ship::operator-=(size_t num) {
crew_ = (crew_ > num)? crew_ - num : 0;
return *this;
}

Ship& Ship::operator+=(size_t num) {
crew_ = (crew_ + num < maxCrew_)? crew_ + num : maxCrew_;
return *this;
}

size_t Ship::getCapacity() const {
return capacity_;
}

size_t Ship::getMaxCrew() const {
return maxCrew_;
}

size_t Ship::getSpeed() const {
return speed_;
}

std::string Ship::getName() const {
return name_;
}

size_t Ship::getId() const {
return id_;
}

std::vector<std::unique_ptr<Cargo>>& Ship::getCargo() {
return cargo_;
}

// void Ship::printCargo() const;

// void Ship::load(std::unique_ptr<Cargo> cargo);

// void Ship::unload(Cargo* cargo);

Cargo* Ship::getCargo(const size_t index) const {
if (index < cargo_.size()) {
return cargo_[index].get();
}
return nullptr;
}

// Cargo* Ship::FindMatchCargo(Cargo* cargo);

// void Ship::RemoveFromStorage(Cargo* cargo);

// void Ship::NextDay() override;
111 changes: 56 additions & 55 deletions shm/source/Ship.hpp
Original file line number Diff line number Diff line change
@@ -1,64 +1,65 @@
#pragma once

#include <memory>
#include <string>
#include <vector>

//#include "Delegate.hpp"
//#include "Tieme.hpp"

#include "Cargo.hpp"
class Cargo;

class Ship {
std::string name_;
const size_t capacity_;
const size_t maxCrew_;
const size_t id_;
size_t crew_;
size_t speed_;
//Time* time_;
//Delegate* delegate_;
std::vector<std::unique_ptr<Cargo>> cargo_;

public:
Ship()
: capacity_()
, maxCrew_()
, crew_()
, speed_()
, name_()
, cargo_()
, id_(-1)
{}

Ship(int capacity, int maxCrew, int speed, const std::string& name, size_t id)
: capacity_(capacity)
, maxCrew_(maxCrew)
, crew_(0)
, speed_(speed)
, name_(name)
, cargo_()
, id_(id)
{}
Ship();

Ship(int maxCrew, int speed, size_t id);

// Ship(int capacity, int crew, int speed, std::string name, size_t id, Time* time);

Ship(int maxCrew, int speed, size_t id)
: Ship(0, maxCrew, speed, "", id)
{}

void setName(const std::string& name) { name_ = name; }

Ship& operator-=(size_t num) {
crew_ -= num;
return *this;
}
Ship& operator+=(size_t num) {
crew_ += num;
return *this;
}

size_t getCapacity() const { return capacity_; }
size_t getMaxCrew() const { return maxCrew_; }
size_t getSpeed() const { return speed_; }
std::string getName() const { return name_; }
size_t getId() const { return id_; }
Ship(int capacity, int maxCrew, int speed, const std::string& name, size_t id);

// ~Ship() override;

Cargo* getCargo(const size_t index) {
if (index < cargo_.size()) {
return &cargo_.at(index);
}
return nullptr;
}

private:
size_t capacity_;
size_t maxCrew_;
size_t crew_;
size_t speed_;
std::string name_;
std::vector<Cargo> cargo_;
const size_t id_;
void setName(const std::string& name);

Ship& operator-=(size_t num);

Ship& operator+=(size_t num);

size_t getCapacity() const;

size_t getMaxCrew() const;

size_t getSpeed() const;

std::string getName() const;

size_t getId() const;

std::vector<std::unique_ptr<Cargo>>& getCargo();

// void printCargo() const;

// void load(std::unique_ptr<Cargo> cargo);

// void unload(Cargo* cargo);

Cargo* getCargo(const size_t index) const;

// Cargo* FindMatchCargo(Cargo* cargo);

// void RemoveFromStorage(Cargo* cargo);

// void NextDay() override;
};