diff --git a/CST136SRS02.sln b/CST136SRS02.sln new file mode 100644 index 0000000..138ddb2 --- /dev/null +++ b/CST136SRS02.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2036 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Waka", "Waka\Waka.vcxproj", "{5FEF05EA-51EF-44E8-98F5-A9FC2195A738}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5FEF05EA-51EF-44E8-98F5-A9FC2195A738}.Debug|x64.ActiveCfg = Debug|x64 + {5FEF05EA-51EF-44E8-98F5-A9FC2195A738}.Debug|x64.Build.0 = Debug|x64 + {5FEF05EA-51EF-44E8-98F5-A9FC2195A738}.Debug|x86.ActiveCfg = Debug|Win32 + {5FEF05EA-51EF-44E8-98F5-A9FC2195A738}.Debug|x86.Build.0 = Debug|Win32 + {5FEF05EA-51EF-44E8-98F5-A9FC2195A738}.Release|x64.ActiveCfg = Release|x64 + {5FEF05EA-51EF-44E8-98F5-A9FC2195A738}.Release|x64.Build.0 = Release|x64 + {5FEF05EA-51EF-44E8-98F5-A9FC2195A738}.Release|x86.ActiveCfg = Release|Win32 + {5FEF05EA-51EF-44E8-98F5-A9FC2195A738}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {331E2184-AB62-4393-A372-09F1F802D21B} + EndGlobalSection +EndGlobal diff --git a/CST136SRS02/CST136SRS02.cpp b/CST136SRS02/CST136SRS02.cpp new file mode 100644 index 0000000..05cb636 Binary files /dev/null and b/CST136SRS02/CST136SRS02.cpp differ diff --git a/CST136SRS02/CST136SRS02.vcxproj b/CST136SRS02/CST136SRS02.vcxproj new file mode 100644 index 0000000..512707b --- /dev/null +++ b/CST136SRS02/CST136SRS02.vcxproj @@ -0,0 +1,165 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {B5E4D46D-6227-4FB7-9B44-4F713D8A4A81} + Win32Proj + CST136SRS02 + 10.0.16299.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + Create + Create + Create + Create + + + + + + \ No newline at end of file diff --git a/CST136SRS02/CST136SRS02.vcxproj.filters b/CST136SRS02/CST136SRS02.vcxproj.filters new file mode 100644 index 0000000..7552d79 --- /dev/null +++ b/CST136SRS02/CST136SRS02.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/CST136SRS02/stdafx.cpp b/CST136SRS02/stdafx.cpp new file mode 100644 index 0000000..9653ee7 Binary files /dev/null and b/CST136SRS02/stdafx.cpp differ diff --git a/CST136SRS02/stdafx.h b/CST136SRS02/stdafx.h new file mode 100644 index 0000000..94d4ed8 Binary files /dev/null and b/CST136SRS02/stdafx.h differ diff --git a/CST136SRS02/targetver.h b/CST136SRS02/targetver.h new file mode 100644 index 0000000..567cd34 Binary files /dev/null and b/CST136SRS02/targetver.h differ diff --git a/README.md b/README.md index 0d70446..324cd80 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,81 @@ # CST136SRS02 Polynesian Polymorphism -Name: +Name: Forrest Warner + +Notes: + +-no cin && no cout +-Classes that contain at least one pure virtual function are known as abstract base classes. + +--- + +Failures/Errors: + +-unable to link Water/Wind to Boat. +-no demo, not even for raft... :( +-Hull base class and sub classes dont function properly +-Sail has no interaction with Wind +-Paddle has little interaction with Water +-Some of my dtors aren't working correctly +-Propulsion Sail is not limited to Sailboat(unimplemented) + +Successes: + +-Navigation/Chart work properly +-Raft successfully constructs +-Most of the classes are almost setup completely (even if not all properly) +-I learned a lot about virtual/abstract/augment/override and more. --- Purpose: -- Learn C++ Polymorphism -- Practice creating classes -- Understand abstraction and abstract classes +[*] Learn C++ Polymorphism +[*] Practice creating classes +[*] Understand abstraction and abstract classes + +[*] Project Name: Waka In this assignment you will create different boats to take you on your voyage around the Pacific Ocean. You already have all the safety gear and the knowledge to use it should you run across rough seas. Many wonders await you, but before you do that, you must make sure you can handle your boat, so we will be sticking close to the coast of New Zealand. -You will create 3 different types of boats. A raft, a canoe, and a sailboat. Only a sailboat may have a sail. +[*] You will create 3 different types of boats. A raft, a canoe, and a sailboat. + +[] Only a sailboat may have a sail. + +[*] You must name each of your boats for them to have [mana](https://en.wikipedia.org/wiki/Mana#M%C4%81ori_use). -You must name each of your boats for them to have [mana](https://en.wikipedia.org/wiki/Mana#M%C4%81ori_use). +[*] You will find the UML blueprints to assemble your boats in a file called Waka.png. [See: Waka](https://en.wikipedia.org/wiki/Waka_(canoe)) -You will find the UML blueprints to assemble your boats in a file called Waka.png. [See: Waka](https://en.wikipedia.org/wiki/Waka_(canoe)) +[] After you have assembled your boats to specification, take them on a test voyage. -After you have assembled your boats to specification, take them on a test voyage. +[*] Create a Wind and Current object as well as a Chart to keep track of your navigation. -Create a Wind and Current object as well as a Chart to keep track of your navigation. +[*] Your boats should turn more easily if MonoHull but be more stable if MultiHull. A MultiHull boat isn't as easy to capsize and your code should reflect this. -Your boats should turn more easily if MonoHull but be more stable if MultiHull. +[] A sail is greatly impacted by the wind and can never move you within +-45 degrees of direction of the wind. Doing so will capsize your boat. However, your speed will be greatly increased by a sail. -A sail is greatly impacted by the wind and can never move you within +-45 degrees of direction of the wind. Doing so will capsize your boat. However, your speed will be greatly increased by a sail. A MultiHull boat isn't as easy to capsize and your code should reflect this. +[*] A raft has no control and is only able to drift with the current. -A raft has no control and is only able to drift with the current. +[] Simulate the conditions of a voyage and chart your course around the entire coast of New Zealand. [See: feature_(NZLand).jpg](https://github.com/labermt/CST136SRS02/blob/master/nz.png) -Simulate the conditions of a voyage and chart your course around the entire coast of New Zealand. (See included map) +[] After you have tested your boats, be able to explain which one would be your choice for a trip across the Pacific Ocean. -After you have tested your boats, be able to explain which one would be your choice for a trip across the Pacific Ocean. +[] Feel free to add provisions and gear (compass, ropes, food, drinking water, ...) as you see fit. Also feel free to add any additional boat items such as an anchor, rudder, ... -Feel free to add provisions and gear (compass, ropes, food, drinking water, ...) as you see fit. Also feel free to add any additional boat items such as an anchor, rudder, ... +[] There are no points given for being fast or even successful navigation, your only goal is to create your boats to the UML specification, describe how you assembled them, and demo testing them. -There are no points given for being fast or even successful navigation, your only goal is to create your boats to the UML specification, describe how you assembled them, and demo testing them. +[] Be sure you account for rough seas in your simulation and have your safety gear ... urrr... code (assertions, exceptions, ...) ready and be able to demonstrate it functioning. -Be sure you account for rough seas in your simulation and have your safety gear ... urrr... code (assertions, exceptions, ...) ready and be able to demonstrate it functioning. +[*] If you have a destructor in any class, follow the guideline [C.35: A base class destructor should be either public and virtual, or protected and nonvirtual](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-dtor-virtual) -If you have a destructor in any class, follow the guideline [C.35: A base class destructor should be either public and virtual, or protected and nonvirtual](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-dtor-virtual) +[] If you want to refer to a concrete class in your code beyond construction, you must obtain permission from the master boat builder (aka your instructor). + +[*] Be creative and have fun on your test voyage. + +--- -If you want to refer to a concrete class in your code beyond construction, you must obtain permission from the master boat builder (aka your instructor). +Citations: -Be creative and have fun on your test voyage. +- Referenced Old Loxadonta Project. Modified some methods initially coded by Professor Mitch Besser (specifically, methods from gps.cpp). [See: GitHub] (https://github.com/labermt/CST126SRS03/blob/master/CST126SRS03/gps.cpp) +- Read up on virtual member functions. [See:C++ FAQ](http://www.cs.technion.ac.il/users/yechiel/c++-faq/overview-virtual-fns.html) \ No newline at end of file diff --git a/Waka/Boat.cpp b/Waka/Boat.cpp new file mode 100644 index 0000000..e14e891 --- /dev/null +++ b/Waka/Boat.cpp @@ -0,0 +1,125 @@ +#include "stdafx.h" + +#include "Boat.h" + +Boat::Boat(std::string name, Propulsion& prop, Hull& hull): +name_(name), prop_(prop), hull_(hull) +{} + +std::string Boat::getName() noexcept +{ + return doGetName(); +} + +Hull & Boat::getHull() const noexcept +{ + return hull_; //return turnRadius? or waveHeight? +} + +Propulsion & Boat::getProp() const noexcept +{ + return prop_; //return speed? +} + +std::string Boat::doGetName() noexcept +{ + return name_; +} + +void Boat::setNav(Navigation & nav) +{ + nav_ = &nav; +} + +Direction Boat::getDirection(const Turn turn) +{ + auto theta{ 0 }; + + switch (turn) + { + case Turn::k0: + case Turn::kForward: + theta = 0; + break; + + case Turn::kLeft: + theta = -90; + break; + + case Turn::kRight: + theta = +90; + break; + } + + const auto result{ Navigation::compRose(theta) }; + + return result; +} + +void Boat::beginVoyage() +{ +} + +Navigation * Boat::getNav() const +{ + return nav_; +} + +void Boat::incrementTime(const unsigned minutes) +{ + auto min = minutes; + + if (prop_.getSpeed() == kFast) + { + min *= 2; + } + + if (prop_.getSpeed() == kModerate) + { + min *= 3; + } + + if (prop_.getSpeed() == kSlow) + { + min *= 4; + } + + elapsedTime_ += min; +} + +unsigned Boat::getElapsedTime() const +{ + return elapsedTime_; +} + +Direction Boat::getHeading(const Turn turn) const +{ + const auto result{ Navigation::compRose(heading_ + getDirection(turn)) }; + + return result; +} + +Direction Boat::getHeading() const +{ + const auto result{ getHeading(Turn::kForward) }; + + return result; +} + +void Boat::move() +{ + incrementTime(20); + if (nav_ != nullptr) + { + const Chart::Feature feature{ look(Turn::kForward) }; + if (!Chart::isKnown(feature)) + { + nav_->move(heading_, 1); + } + } +} + +void Boat::turn(const Turn turn) +{ + heading_ = getHeading(turn); +} diff --git a/Waka/Boat.h b/Waka/Boat.h new file mode 100644 index 0000000..eb6b96b --- /dev/null +++ b/Waka/Boat.h @@ -0,0 +1,65 @@ +#ifndef BOAT_H +#define BOAT_H + +#include + +#include "MonoHull.h" +#include "MultiHull.h" +#include "Propulsion.h" +#include "Chart.h" +#include "Water.h" + +class Boat +{ +public: + enum class Turn { k0, kForward, kLeft, kRight}; + +private: + std::string name_; + + Hull& hull_; //has-a: Composition + Propulsion& prop_; + Direction heading_{ kNorth }; + Navigation* nav_{}; + + unsigned elapsedTime_{}; + +protected: + Boat(std::string name, Propulsion& prop, Hull& hull); + +public: + std::string getName() noexcept; + Hull& getHull() const noexcept; + Propulsion& getProp() const noexcept; + +protected: //prefer virtual functions to be private or protected. + virtual std::string doGetName() noexcept = 0; //A pure virtual function + +protected: + void setNav(Navigation& nav); + +private: + static Direction getDirection(const Turn turn); + +public: + Navigation * getNav() const; + unsigned getElapsedTime() const; + + Direction getHeading(const Turn turn) const; + Direction getHeading() const; + +private: + void incrementTime(const unsigned minutes); + +public: + void beginVoyage(); + void move(); + void turn(const Turn turn); + +public: //a base clase destructor should be: public and virtual || protected and non-virtual + virtual ~Boat() = default; //A virtual destructor +}; +//Boat is abstract because it has one or more pure virtual functions. +#endif + +//TODO::Raft hits obstacle -> end voyage. Paddle/sail use -> algorithm for navigating around rocks/land? \ No newline at end of file diff --git a/Waka/Canoe.cpp b/Waka/Canoe.cpp new file mode 100644 index 0000000..460860f --- /dev/null +++ b/Waka/Canoe.cpp @@ -0,0 +1,17 @@ +#include "stdafx.h" + +#include "Canoe.h" + +Canoe::Canoe(std::string const name, Propulsion & prop, Hull & hull): +Boat(name, prop, hull) +{} + +void Canoe::nav(Navigation & nav) +{ + setNav(nav); +} + +std::string Canoe::doGetName() noexcept +{ + return Boat::getName(); +} diff --git a/Waka/Canoe.h b/Waka/Canoe.h new file mode 100644 index 0000000..c382bbb --- /dev/null +++ b/Waka/Canoe.h @@ -0,0 +1,18 @@ +#ifndef CANOE_H +#define CANOE_H + +#include "Boat.h" + +class Canoe final: public Boat +{ +public: + Canoe(std::string const name, Propulsion & prop, Hull & hull); + +protected: + std::string doGetName() noexcept override; + +public: + void nav(Navigation& nav); + +}; +#endif diff --git a/Waka/Chart.cpp b/Waka/Chart.cpp new file mode 100644 index 0000000..b412bc6 --- /dev/null +++ b/Waka/Chart.cpp @@ -0,0 +1,64 @@ +#include "stdafx.h" + +#include "Chart.h" +#include "Boat.h" + +Chart::Chart() : + feature_ +{ + { Feature:: kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kLand, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kLand, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kLand, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kLand, Feature::kLand, Feature::kLand, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kLand, Feature::kLand, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kLand, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kLand, Feature::kLand, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kLand, Feature::kLand, Feature::kLand, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kLand, Feature::kLand, Feature::kLand, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kLand, Feature::kLand, Feature::kLand, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kLand, Feature::kLand, Feature::kLand, Feature::kLand, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kLand, Feature::kLand, Feature::kLand, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kWater, Feature::kUnknown }, + { Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown, Feature::kUnknown } +}, +pushOff_(0, 7) //push of from NZland +{} + +Chart::Feature Chart::getFeature(int lat, int lng) const +{ + auto result = Feature::kUnknown; + + result = feature_[lat][lng]; + + return result; +} + +Chart::Feature Chart::getFeature(const Navigation nav) const +{ + const auto lat{ nav.getlat() }; + const auto lng{ nav.getlng() }; + const auto result = getFeature(lat, lng); + + return result; +} + +bool Chart::isKnown(const Feature feature) +{ + bool result{ true }; + + switch (feature) + { + case Feature::kUnknown: + result = false; + break; + + case Feature::kLand: + case Feature::kWater: + result = true; + break; + } + + return result; +} \ No newline at end of file diff --git a/Waka/Chart.h b/Waka/Chart.h new file mode 100644 index 0000000..2d7d366 --- /dev/null +++ b/Waka/Chart.h @@ -0,0 +1,35 @@ +#ifndef CHART_H +#define CHART_H + +#include "Navigation.h" + +class Chart +{ +public: + +enum class Feature +{ + kUnknown, //kUnknown defines that the boat is lost(hit boundary -> terminate voyage) + kWater, + kLand //pushOff_ of kLand +}; + +private: + Feature feature_[16][16]; //See: feature_(NZLand).jpg + Navigation pushOff_; + +protected: + Chart(); + +public: + static bool isKnown(const Feature feature); + +private: + Feature getFeature(int lat, int lng) const; + +public: + Feature getFeature(const Navigation nav) const; + +}; +#endif +//aggregate class \ No newline at end of file diff --git a/Waka/Current.cpp b/Waka/Current.cpp new file mode 100644 index 0000000..9b5e9a1 --- /dev/null +++ b/Waka/Current.cpp @@ -0,0 +1,129 @@ +#include "stdafx.h" + +#include + +#include "Current.h" + +#include "gsl.h" + +Current::Current(Strength strength, Direction direction) : + strength_(strength), direction_(direction) +{} + +void Current::simulateCurrent() noexcept //get random number, throw into switch that randomly picks from all the combinations of Strength/Direction +{ + const auto rand{ random(11) }; + + Expects(rand >= 0 && rand < 12); + + switch (rand) + { + case 0: + { + setStrength(kWeak); + setDirection(kNorth); + } + break; + case 1: + { + setStrength(kWeak); + setDirection(kEast); + } + break; + case 2: + { + setStrength(kWeak); + setDirection(kSouth); + } + break; + case 3: + { + setStrength(kWeak); + setDirection(kWest); + } + break; + case 4: + { + setStrength(kSteady); + setDirection(kNorth); + } + break; + case 5: + { + setStrength(kSteady); + setDirection(kEast); + } + break; + case 6: + { + setStrength(kSteady); + setDirection(kSouth); + } + break; + case 7: + { + setStrength(kSteady); + setDirection(kWest); + } + break; + case 8: + { + setStrength(kStrong); + setDirection(kNorth); + } + break; + case 9: + { + setStrength(kStrong); + setDirection(kEast); + } + break; + case 10: + { + setStrength(kStrong); + setDirection(kSouth); + } + break; + case 11: + { + setStrength(kStrong); + setDirection(kWest); + } + break; + default: + { + setStrength(kSteady); + setDirection(kNorth); + } + break; + } +} + +void Current::setStrength(Strength strength) +{ + strength_ = strength; +} + +void Current::setDirection(Direction direction) +{ + direction_ = direction; +} + +Strength Current::getStrength() const +{ + return strength_; +} + +Direction Current::getDirection() const +{ + return direction_; +} + +int Current::random(const int combos) const +{ + std::random_device rd; + std::mt19937 gen{ rd() }; + std::uniform_int_distribution const rand(0, combos); + + return rand(gen); +} \ No newline at end of file diff --git a/Waka/Current.h b/Waka/Current.h new file mode 100644 index 0000000..8737b17 --- /dev/null +++ b/Waka/Current.h @@ -0,0 +1,28 @@ +#ifndef CURRENT_H +#define CURRENT_H + +#include "Strength.h" +#include "Direction.h" + +class Current +{ +protected: + Current(Strength strength, Direction direction); + +private: + Strength strength_{ kSteady }; + Direction direction_ { kNorth }; + +private: + void setStrength(Strength strength); + void setDirection(Direction direction); + +private: + void simulateCurrent() noexcept; //randomizes direction_ and strength_ + int random(const int combos) const; + +public: + Strength getStrength() const; + Direction getDirection() const; +}; +#endif \ No newline at end of file diff --git a/Waka/Direction.h b/Waka/Direction.h new file mode 100644 index 0000000..28bd506 --- /dev/null +++ b/Waka/Direction.h @@ -0,0 +1,6 @@ +#ifndef DIRECTION_H +#define DIRECTION_H + +enum Direction { kEast = 0 , kNorth = 90, kWest = 180, kSouth = 270 }; + +#endif \ No newline at end of file diff --git a/Waka/Drift.cpp b/Waka/Drift.cpp new file mode 100644 index 0000000..4128188 --- /dev/null +++ b/Waka/Drift.cpp @@ -0,0 +1,8 @@ +#include "stdafx.h" + +#include "Drift.h" + +Speed Drift::doSpeed() noexcept +{ + return Speed::kSlow; +} \ No newline at end of file diff --git a/Waka/Drift.h b/Waka/Drift.h new file mode 100644 index 0000000..414b0d6 --- /dev/null +++ b/Waka/Drift.h @@ -0,0 +1,16 @@ +#ifndef DRIFT_H +#define DRIFT_H + +#include "Propulsion.h" + +class Drift final: public Propulsion +{ +public: + Drift() = default; + +protected: + Speed doSpeed() noexcept override; + +}; +#endif + diff --git a/Waka/Hull.cpp b/Waka/Hull.cpp new file mode 100644 index 0000000..046ba50 --- /dev/null +++ b/Waka/Hull.cpp @@ -0,0 +1,13 @@ +#include "stdafx.h" + +#include "Hull.h" + +Hull::TurnRadius Hull::getTurnRadius() +{ + return minTurnRadius(); +} + +Hull::WaveHeight Hull::getWaveHeight() +{ + return maxWaveHeight(); +} \ No newline at end of file diff --git a/Waka/Hull.h b/Waka/Hull.h new file mode 100644 index 0000000..bbf8e9b --- /dev/null +++ b/Waka/Hull.h @@ -0,0 +1,28 @@ +#ifndef HULL_H +#define HULL_H + +#include "Boat.h" + +class Hull +{ +protected: + Hull(); + +protected: + enum class TurnRadius { kNarrow = 90, kWide = 180 }; + + enum class WaveHeight { kLow = 2, kHigh = 5 }; + +protected: + virtual TurnRadius minTurnRadius() noexcept = 0; + virtual WaveHeight maxWaveHeight() noexcept = 0; + +public: + TurnRadius getTurnRadius(); + WaveHeight getWaveHeight(); + +public: + virtual ~Hull() = default; +}; +//turn more easily if MonoHull but be more stable if MultiHull. +#endif diff --git a/Waka/MonoHull.cpp b/Waka/MonoHull.cpp new file mode 100644 index 0000000..1698e58 --- /dev/null +++ b/Waka/MonoHull.cpp @@ -0,0 +1,13 @@ +#include "stdafx.h" + +#include "MonoHull.h" + +Hull::TurnRadius MonoHull::minTurnRadius() noexcept +{ + return TurnRadius::kWide; //can turn +-180 degrees +} + +Hull::WaveHeight MonoHull::maxWaveHeight() noexcept +{ + return WaveHeight::kLow; //2 foot waves +} \ No newline at end of file diff --git a/Waka/MonoHull.h b/Waka/MonoHull.h new file mode 100644 index 0000000..966d50d --- /dev/null +++ b/Waka/MonoHull.h @@ -0,0 +1,15 @@ +#ifndef MONOHULL_H +#define MONOHULL_H +#include "Hull.h" + +class MonoHull final: public Hull +{ +public: + MonoHull(); + +protected: + TurnRadius minTurnRadius() noexcept override; + WaveHeight maxWaveHeight() noexcept override; + +}; +#endif diff --git a/Waka/MultiHull.cpp b/Waka/MultiHull.cpp new file mode 100644 index 0000000..46395a7 --- /dev/null +++ b/Waka/MultiHull.cpp @@ -0,0 +1,13 @@ +#include "stdafx.h" + +#include "MultiHull.h" + +Hull::TurnRadius MultiHull::minTurnRadius() noexcept +{ + return TurnRadius::kNarrow; //can turn +-90 degrees +} + +Hull::WaveHeight MultiHull::maxWaveHeight() noexcept +{ + return WaveHeight::kHigh; //5 foot waves +} \ No newline at end of file diff --git a/Waka/MultiHull.h b/Waka/MultiHull.h new file mode 100644 index 0000000..25d22a0 --- /dev/null +++ b/Waka/MultiHull.h @@ -0,0 +1,15 @@ +#ifndef MULTIHULL_H +#define MULTIHULL_H + +#include "Hull.h" + +class MultiHull final: public Hull +{ +protected: + MultiHull() = default; + +protected: + TurnRadius minTurnRadius() noexcept override; + WaveHeight maxWaveHeight() noexcept override; +}; +#endif diff --git a/Waka/Navigation.cpp b/Waka/Navigation.cpp new file mode 100644 index 0000000..b29e62e --- /dev/null +++ b/Waka/Navigation.cpp @@ -0,0 +1,122 @@ +#include "stdafx.h" + +#include "gsl.h" + +#include "Navigation.h" + + +Navigation::Navigation(const int lat, const int lng) : + lat_(lat), lng_(lng) +{} + +void Navigation::set(const int lat, const int lng) +{ + lat_ = lat; + lng_ = lng; +} + +int Navigation::getlat() const +{ + return lat_; +} + +int Navigation::getlng() const +{ + return lng_; +} + +void Navigation::move(const int direction, const unsigned distance) +{ + switch (distance) + { + case 0: + break; + + case 1: + { + const auto cardinal = Navigation::compRose(direction); + + switch (cardinal) + { + case kNorth: + --lat_; + break; + + case kEast: + ++lng_; + break; + + case kSouth: + ++lat_; + break; + + case kWest: + --lng_; + break; + } + } + break; + } +} + +Direction Navigation::compRose(const int direction) +{ + auto result{ kNorth }; + + const auto theta = rangeTheta(direction); + + Expects(theta >= 0 && theta <= 360); + + if (theta <= 135 && theta > 45) + { + result = kNorth; + } + else if (theta <= 45 && theta > 315) + { + result = kEast; + } + else if (theta <= 315 && theta > 225) + { + result = kSouth; + } + else if (theta <= 225 && theta > 135) + { + result = kWest; + } + + return result; +} + +int Navigation::theta(const int x, const int y) +{ + int result = 0; + if (x == 0) + { + if (y < 0) + { + result = 90; + } + } + else + { + constexpr auto kPi{ 3.14159265358979323846 }; + + result = std::lround(atan(1.0 * y / x) * 180.0 / kPi); + if (x < 0) + { + result += 180; + } + else if (y < 0) + { + result += 360; + } + } + + return result; +} +int Navigation::rangeTheta(const int theta) +{ + const auto result{ (360 * (1 - theta / 360) + theta) % 360 }; + + return result; +} \ No newline at end of file diff --git a/Waka/Navigation.h b/Waka/Navigation.h new file mode 100644 index 0000000..c3788f4 --- /dev/null +++ b/Waka/Navigation.h @@ -0,0 +1,34 @@ +#ifndef NAVIGATION_H +#define NAVIGATION_H + +#include "Direction.h" + +class Navigation +{ +public: + enum Coordinates { kLng = 0, kLat = 1}; + +public: + Navigation(const int lat, const int lng); + +private: + int lat_{ -1 }; + int lng_{ -1 }; + +public: + static int theta(const int x, const int y); + static int rangeTheta(const int theta); + + static Direction compRose(const int direction); + +private: + void set(int lat, int lng); //to set pushOff_ (boat start coOrds) + +public: + int getlat() const; + int getlng() const; + +public: + void move(const int direction, const unsigned distance); +}; +#endif diff --git a/Waka/Paddle.cpp b/Waka/Paddle.cpp new file mode 100644 index 0000000..575afaa --- /dev/null +++ b/Waka/Paddle.cpp @@ -0,0 +1,8 @@ +#include "stdafx.h" + +#include "Paddle.h" + +Speed Paddle::doSpeed() noexcept +{ + return Speed::kModerate; +} diff --git a/Waka/Paddle.h b/Waka/Paddle.h new file mode 100644 index 0000000..5e88f93 --- /dev/null +++ b/Waka/Paddle.h @@ -0,0 +1,14 @@ +#ifndef PADDLE_H +#define PADDLE_H + +#include "Propulsion.h" + +class Paddle final: public Propulsion +{ +public: + Paddle() = default; + +protected: + Speed doSpeed() noexcept override; +}; +#endif \ No newline at end of file diff --git a/Waka/Propulsion.cpp b/Waka/Propulsion.cpp new file mode 100644 index 0000000..21ba2ab --- /dev/null +++ b/Waka/Propulsion.cpp @@ -0,0 +1,10 @@ +#include "stdafx.h" + +#include "Propulsion.h" + + + +Speed Propulsion::getSpeed() noexcept +{ + return doSpeed(); +} diff --git a/Waka/Propulsion.h b/Waka/Propulsion.h new file mode 100644 index 0000000..047e753 --- /dev/null +++ b/Waka/Propulsion.h @@ -0,0 +1,18 @@ +#ifndef PROPULSION_H +#define PROPULSION_H + +#include "Speed.h" + +class Propulsion +{ +protected: + virtual Speed doSpeed() noexcept = 0; + +public: + Speed getSpeed() noexcept; + +public: + virtual ~Propulsion() = default; + +}; +#endif \ No newline at end of file diff --git a/Waka/Raft.cpp b/Waka/Raft.cpp new file mode 100644 index 0000000..2919a7b --- /dev/null +++ b/Waka/Raft.cpp @@ -0,0 +1,17 @@ +#include "stdafx.h" +#include "Raft.h" + + +Raft::Raft(std::string const name, Propulsion & prop, Hull & hull): +Boat(name, prop, hull) +{} + +void Raft::nav(Navigation & nav) +{ + setNav(nav); +} + +std::string Raft::doGetName() noexcept +{ + return Boat::getName(); +} diff --git a/Waka/Raft.h b/Waka/Raft.h new file mode 100644 index 0000000..99b9fef --- /dev/null +++ b/Waka/Raft.h @@ -0,0 +1,18 @@ +#ifndef RAFT_H +#define RAFT_H + +#include "Boat.h" + +class Raft final: public Boat //is-a: Inheritance +{ +public: + Raft(std::string const name, Propulsion& prop, Hull& hull); + +protected: + std::string doGetName() noexcept override; + +public: + void nav(Navigation& nav); +}; +//has no propulsion, can only drift with current->water +#endif \ No newline at end of file diff --git a/Waka/Sail.cpp b/Waka/Sail.cpp new file mode 100644 index 0000000..d980e3c --- /dev/null +++ b/Waka/Sail.cpp @@ -0,0 +1,8 @@ +#include "stdafx.h" + +#include "Sail.h" + +Speed Sail::doSpeed() noexcept +{ + return Speed::kFast; +} \ No newline at end of file diff --git a/Waka/Sail.h b/Waka/Sail.h new file mode 100644 index 0000000..7131cfc --- /dev/null +++ b/Waka/Sail.h @@ -0,0 +1,14 @@ +#ifndef SAIL_H +#define SAIL_H + +#include "Propulsion.h" + +class Sail final: public Propulsion +{ +public: + Sail() = default; + +protected: + Speed doSpeed() noexcept override; +}; +#endif \ No newline at end of file diff --git a/Waka/Sailboat.cpp b/Waka/Sailboat.cpp new file mode 100644 index 0000000..0c0685a --- /dev/null +++ b/Waka/Sailboat.cpp @@ -0,0 +1,17 @@ +#include "stdafx.h" + +#include "Sailboat.h" + +Sailboat::Sailboat(std::string const name, Propulsion & prop, Hull & hull): +Boat(name, prop, hull) +{} + +void Sailboat::nav(Navigation & nav) +{ + setNav(nav); +} + +std::string Sailboat::doGetName() noexcept +{ + return Boat::getName(); +} \ No newline at end of file diff --git a/Waka/Sailboat.h b/Waka/Sailboat.h new file mode 100644 index 0000000..84bb934 --- /dev/null +++ b/Waka/Sailboat.h @@ -0,0 +1,17 @@ +#ifndef SAILBOAT_H +#define SAILBOAT_H + +#include "Boat.h" + +class Sailboat: public Boat +{ +public: + Sailboat(std::string const name, Propulsion & prop, Hull & hull); + +protected: + std::string doGetName() noexcept override; + +public: + void nav(Navigation& nav); +}; +#endif \ No newline at end of file diff --git a/Waka/Speed.h b/Waka/Speed.h new file mode 100644 index 0000000..14cf471 --- /dev/null +++ b/Waka/Speed.h @@ -0,0 +1,6 @@ +#ifndef SPEED_H +#define SPEED_H + +enum Speed { kSlow, kModerate, kFast}; + +#endif diff --git a/Waka/Strength.h b/Waka/Strength.h new file mode 100644 index 0000000..5d9fd7a --- /dev/null +++ b/Waka/Strength.h @@ -0,0 +1,6 @@ +#ifndef STRENGTH_H +#define STRENGTH_H + +enum Strength { kWeak = 10, kSteady = 50, kStrong = 100 }; //basically the strength multiplier applied by the current to a boat's speed at any given moment in sim + +#endif diff --git a/Waka/Waka.vcxproj b/Waka/Waka.vcxproj new file mode 100644 index 0000000..8dfda3e --- /dev/null +++ b/Waka/Waka.vcxproj @@ -0,0 +1,217 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {5FEF05EA-51EF-44E8-98F5-A9FC2195A738} + Win32Proj + Waka + 10.0.16299.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + true + + + true + + + false + + + false + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/Waka/Waka.vcxproj.filters b/Waka/Waka.vcxproj.filters new file mode 100644 index 0000000..e965bb0 --- /dev/null +++ b/Waka/Waka.vcxproj.filters @@ -0,0 +1,153 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + + + + + Resource Files + + + Resource Files + + + Resource Files + + + \ No newline at end of file diff --git a/Waka/Water.cpp b/Waka/Water.cpp new file mode 100644 index 0000000..3f2c21c --- /dev/null +++ b/Waka/Water.cpp @@ -0,0 +1,7 @@ +#include "stdafx.h" + +#include "Water.h" + +Water::Water(Current & current): +current_(current) +{} diff --git a/Waka/Water.h b/Waka/Water.h new file mode 100644 index 0000000..9b6635c --- /dev/null +++ b/Waka/Water.h @@ -0,0 +1,16 @@ +#ifndef WATER_H +#define WATER_H + +#include "Current.h" + +class Water +{ +public: + Water(Current& current); + +private: + Current current_; //this has direction and speed. +}; +#endif +//association w/ Boat +//has-a relationship with Current \ No newline at end of file diff --git a/Waka/Wind.cpp b/Waka/Wind.cpp new file mode 100644 index 0000000..0ccae5c --- /dev/null +++ b/Waka/Wind.cpp @@ -0,0 +1,7 @@ +#include "stdafx.h" + +#include "Wind.h" + +Wind::Wind(Current & current): +current_(current) +{} diff --git a/Waka/Wind.h b/Waka/Wind.h new file mode 100644 index 0000000..9fb6351 --- /dev/null +++ b/Waka/Wind.h @@ -0,0 +1,17 @@ +#ifndef WIND_H +#define WIND_H + +#include "Current.h" + +class Wind +{ +public: + Wind(Current& current); + +private: + Current current_; + +}; +#endif +//association w/ Boat +//has-a relationship with Current \ No newline at end of file diff --git a/Waka/main.cpp b/Waka/main.cpp new file mode 100644 index 0000000..673e66f Binary files /dev/null and b/Waka/main.cpp differ diff --git a/Waka/packages.config b/Waka/packages.config new file mode 100644 index 0000000..f8a1db9 --- /dev/null +++ b/Waka/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Waka/stdafx.cpp b/Waka/stdafx.cpp new file mode 100644 index 0000000..e6d49a6 Binary files /dev/null and b/Waka/stdafx.cpp differ diff --git a/Waka/stdafx.h b/Waka/stdafx.h new file mode 100644 index 0000000..94d4ed8 Binary files /dev/null and b/Waka/stdafx.h differ diff --git a/Waka/targetver.h b/Waka/targetver.h new file mode 100644 index 0000000..567cd34 Binary files /dev/null and b/Waka/targetver.h differ diff --git a/feature_(NZLand).jpg b/feature_(NZLand).jpg new file mode 100644 index 0000000..6508b51 Binary files /dev/null and b/feature_(NZLand).jpg differ