diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..f50e203 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index 02c345f..e69de29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +0,0 @@ -/.dep.inc -/Makefile -/nbproject/ -/core \ No newline at end of file diff --git a/CommonSpear.cpp b/CommonSpear.cpp old mode 100644 new mode 100755 diff --git a/CommonSpear.h b/CommonSpear.h old mode 100644 new mode 100755 diff --git a/CommonSword.cpp b/CommonSword.cpp old mode 100644 new mode 100755 diff --git a/CommonSword.h b/CommonSword.h old mode 100644 new mode 100755 diff --git a/CrazyRandoSword.cpp b/CrazyRandoSword.cpp new file mode 100755 index 0000000..df597be --- /dev/null +++ b/CrazyRandoSword.cpp @@ -0,0 +1,20 @@ +/* + * File: CommonSword.cpp + * Author: Javier + * + */ + +#include "CrazyRandoSword.h" + + +double CrazyRandoSword::hit(double armor){ + double damage; + if ( armor >=2 && armor < (hitPoints/3)) + damage = hitPoints; + else + damage = hitPoints - armor; + if(damage < 0){ + return 0; + } + return damage; +} \ No newline at end of file diff --git a/CrazyRandoSword.h b/CrazyRandoSword.h new file mode 100755 index 0000000..9f69ca4 --- /dev/null +++ b/CrazyRandoSword.h @@ -0,0 +1,31 @@ +/* + * File: CommonSword.h + * Author: Javier + * + * Created on September 25, 2017, 3:31 PM + */ + +#include +#include "Weapon.h" + +#ifndef CRAZYRANDOMSWORD_H +#define CRAZYRANDOMSWORD_H + + +/** + * Defines the behavior of a common sword (hitpoint = 50, it does not ignore armor points) + */ +class CrazyRandoSword : public Weapon { +public: + CrazyRandoSword() : Weapon("Crazy Random sword",50.0) //Calls Weapon(name, hitpoints) constructor with values Common Sword and 50.0 + { + } + + virtual ~CrazyRandoSword() {}; + + virtual double hit(double armor); + +}; + +#endif /* COMMONSWORD_H */ + diff --git a/MyOwnWeapon.cpp b/MyOwnWeapon.cpp new file mode 100755 index 0000000..d908c70 --- /dev/null +++ b/MyOwnWeapon.cpp @@ -0,0 +1,19 @@ +/* + * File: CommonSpear.cpp + * Author: Javier + * + * Created on September 27, 2017, 4:15 PM + */ + +#include "MyOwnWeapon.h" + +double MyOwnWeapon::hit(double armor) { + double damage = hitPoints - (armor); + if ( damage <= 0) + damage = .1; + + if (damage < 0) { + return 0; + } + return damage; +} diff --git a/MyOwnWeapon.h b/MyOwnWeapon.h new file mode 100755 index 0000000..b842a52 --- /dev/null +++ b/MyOwnWeapon.h @@ -0,0 +1,31 @@ +/* + * File: CommonSpear.h + * Author: Javier + * + * Created on September 27, 2017, 4:15 PM + */ + +#include +#include "Weapon.h" + +#ifndef MYOWNWEAPON_H +#define MYOWNWEAPON_H + +/** + * Defines the behavior of a common spear (hitpoint = 40, ignores 20% of + * armor points) + */ +class MyOwnWeapon : public Weapon { +public: + + MyOwnWeapon() : Weapon("My Own Weapon", 40.0) { //Calls Weapon(name, hitpoints) constructor with values Common Spear and 40.0 + } + + virtual ~MyOwnWeapon() {}; + + virtual double hit(double armor); + +}; + +#endif /* COMMONSPEAR_H */ + diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 8b13789..8cabd3b --- a/README.md +++ b/README.md @@ -1 +1,2 @@ - +Name: Emad Abdelmiseh +FSUID: eea17b diff --git a/SimpleHammer.cpp b/SimpleHammer.cpp new file mode 100755 index 0000000..b7dc261 --- /dev/null +++ b/SimpleHammer.cpp @@ -0,0 +1,18 @@ +/* + * File: CommonSword.cpp + * Author: Javier + * + */ +#include "SimpleHammer.h" + + +double SimpleHammer::hit(double armor){ + + double damage = hitPoints - armor ; + if ( armor < 30 ) + damage = hitPoints; + if(damage < 0){ + return 0; + } + return damage; +} \ No newline at end of file diff --git a/SimpleHammer.h b/SimpleHammer.h new file mode 100644 index 0000000..1330412 --- /dev/null +++ b/SimpleHammer.h @@ -0,0 +1,32 @@ +/* + * File: CommonSpear.h + * Author: Javier + * + * Created on September 27, 2017, 4:15 PM + */ + +#include +#include "Weapon.h" + +#ifndef SIMPLEHAMMER_H +#define SIMPLEHAMMER_H + +/** + * Defines the behavior of a common spear (hitpoint = 40, ignores 20% of + * armor points) + */ +class SimpleHammer : public Weapon { +public: + + SimpleHammer() : Weapon("Simpple Hammer", 25.0) { //Calls Weapon(name, hitpoints) constructor with values Common Spear and 40.0 + + } + + virtual ~SimpleHammer() {}; + + virtual double hit(double armor); + +}; + +#endif /* COMMONSPEAR_H */ + diff --git a/Weapon.cpp b/Weapon.cpp old mode 100644 new mode 100755 diff --git a/Weapon.h b/Weapon.h old mode 100644 new mode 100755 index 199ec86..b6edd9f --- a/Weapon.h +++ b/Weapon.h @@ -6,10 +6,13 @@ */ #include - +#include +#include +#include #ifndef WEAPON_H #define WEAPON_H + /** * Defines the specification of a weapon. A weapon must define its hitpoints * as well as its behavior in the presence of armor. If there is no armor, the @@ -31,9 +34,20 @@ class Weapon { * @param name Weapon's name * @param hitPoints Weapon's hitpoints */ - Weapon(std::string name, double hitPoints) - : name(name), - hitPoints(hitPoints) {} //This is equivalent to this.name = name and this.hitpoints = hitpoitns; + Weapon(std::string name, double hitPoint) + : name(name) + { + srand(time(0)); + int i = rand() % 94 +7; + double x = i / 1.0; + //std :: cout << "\n" << name << "\n"; + if ( name == "Crazy Random sword" || name == "Csword") + hitPoint = x; + else + hitPoints = hitPoint; + //if ( name == "hammer" && hitPoint < 30 ) + // hitPoints = 0; + } /** * Detructor diff --git a/WeaponFactory.cpp b/WeaponFactory.cpp old mode 100644 new mode 100755 index 47ce803..555d11d --- a/WeaponFactory.cpp +++ b/WeaponFactory.cpp @@ -9,6 +9,8 @@ #include "WeaponFactory.h" #include "CommonSword.h" #include "CommonSpear.h" +#include "SimpleHammer.h" +#include "CrazyRandoSword.h" WeaponFactory* WeaponFactory::instance = NULL; @@ -27,6 +29,25 @@ Weapon * WeaponFactory::getWeapon(std::string name) { if (name.compare("spear") == 0) { return new CommonSpear(); } + if (name.compare("hammer") == 0) { + return new SimpleHammer(); + } + if (name.compare("Csword") == 0) { + return new CrazyRandoSword(); + } + if (name.compare("MyOwn") == 0) { + return new CrazyRandoSword(); + } + + + + + + + + + + throw "Invalid weapon"; } \ No newline at end of file diff --git a/WeaponFactory.h b/WeaponFactory.h old mode 100644 new mode 100755 diff --git a/docs/answers.txt b/docs/answers.txt new file mode 100755 index 0000000..0228f3b --- /dev/null +++ b/docs/answers.txt @@ -0,0 +1,52 @@ +(a) +Enumerating objects: 11, done. +Counting objects: 100% (11/11), done. +Delta compression using up to 8 threads +Compressing objects: 100% (5/5), done. +Writing objects: 100% (7/7), 753 bytes | 753.00 KiB/s, done. +Total 7 (delta 2), reused 0 (delta 0) +remote: Resolving deltas: 100% (2/2), completed with 1 local object. +To https://github.com/eea17b/Assignment1 + ffaccff..40ae2aa master -> master + +(B) 19 commits +git rev-list --count HEAD + +(c) +In this line I just added gitignore +Git log gitignore + +(d) +-If two user working in different functions +-if want to test a new feature + +(e)get log prints out all the commits one by one with each on't author +Get status will show the status like how many commits didn't pushed to the repository + +(f) +git log --follow -- Weapon.h + +(g) +git log --all --grep='file' + +(h) +Inheritance: +Different kinds of objects often have a certain amount in common with each other. +polymorphism: +the ability to present the same interface for differing underlying forms (data types). +encapsulation: +the process of combining data and functions into a single unit called class + +(I) +Integration management: public developers send to the manager then manager send to blessed repository to developer private +Dictator and Lieutenants: manager send to blessed repositories then to the public developers while send to lieutenant then the manager + +(J) +Because: +- Regular developers work on their topic branch and rebase their work on top of master. +-Lieutenants merge the developers' topic branches into their master branch. +-The dictator merges the lieutenants' master branches into the dictator’s master branch. +the dictator pushes that master branch to the reference repository so the other developers can rebase on it. + + + diff --git a/docs/status.txt b/docs/status.txt old mode 100644 new mode 100755 index 8b13789..20daacc --- a/docs/status.txt +++ b/docs/status.txt @@ -1 +1,5 @@ +On branch master +Your branch is ahead of 'origin/master' by 1 commit. + (use "git push" to publish your local commits) +nothing to commit, working tree clean \ No newline at end of file diff --git a/main.cpp b/main.cpp old mode 100644 new mode 100755 index c1e7370..bc67a82 --- a/main.cpp +++ b/main.cpp @@ -38,7 +38,22 @@ int main(int argc, char** argv) { weapon = WeaponFactory::getInstance()->getWeapon("spear"); simulateWeapon(weapon, armor); delete(weapon); + + weapon = WeaponFactory::getInstance()->getWeapon("hammer"); + simulateWeapon(weapon, armor); + delete(weapon); + + weapon = WeaponFactory::getInstance()->getWeapon("Csword"); + simulateWeapon(weapon, armor); + delete(weapon); + + + weapon = WeaponFactory::getInstance()->getWeapon("MyOwn"); + simulateWeapon(weapon, armor); + delete(weapon); + + return 0; }