Skip to content
Open
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
Binary file added .DS_Store
Binary file not shown.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
/.dep.inc
/Makefile
/nbproject/
/core
Empty file modified CommonSpear.cpp
100644 → 100755
Empty file.
Empty file modified CommonSpear.h
100644 → 100755
Empty file.
Empty file modified CommonSword.cpp
100644 → 100755
Empty file.
Empty file modified CommonSword.h
100644 → 100755
Empty file.
20 changes: 20 additions & 0 deletions CrazyRandoSword.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* File: CommonSword.cpp
* Author: Javier <jrescobara@gmail.com>
*
*/

#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;
}
31 changes: 31 additions & 0 deletions CrazyRandoSword.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* File: CommonSword.h
* Author: Javier <jrescobara@gmail.com>
*
* Created on September 25, 2017, 3:31 PM
*/

#include <string>
#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 */

19 changes: 19 additions & 0 deletions MyOwnWeapon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* File: CommonSpear.cpp
* Author: Javier <jrescobara@gmail.com>
*
* 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;
}
31 changes: 31 additions & 0 deletions MyOwnWeapon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* File: CommonSpear.h
* Author: Javier <jrescobara@gmail.com>
*
* Created on September 27, 2017, 4:15 PM
*/

#include <string>
#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 */

3 changes: 2 additions & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

Name: Emad Abdelmiseh
FSUID: eea17b
18 changes: 18 additions & 0 deletions SimpleHammer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* File: CommonSword.cpp
* Author: Javier <jrescobara@gmail.com>
*
*/
#include "SimpleHammer.h"


double SimpleHammer::hit(double armor){

double damage = hitPoints - armor ;
if ( armor < 30 )
damage = hitPoints;
if(damage < 0){
return 0;
}
return damage;
}
32 changes: 32 additions & 0 deletions SimpleHammer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* File: CommonSpear.h
* Author: Javier <jrescobara@gmail.com>
*
* Created on September 27, 2017, 4:15 PM
*/

#include <string>
#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 */

Empty file modified Weapon.cpp
100644 → 100755
Empty file.
22 changes: 18 additions & 4 deletions Weapon.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
*/

#include <string>

#include <iostream>
#include <cstdlib>
#include <ctime>
#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
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions WeaponFactory.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "WeaponFactory.h"
#include "CommonSword.h"
#include "CommonSpear.h"
#include "SimpleHammer.h"
#include "CrazyRandoSword.h"

WeaponFactory* WeaponFactory::instance = NULL;

Expand All @@ -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";
}
Empty file modified WeaponFactory.h
100644 → 100755
Empty file.
52 changes: 52 additions & 0 deletions docs/answers.txt
Original file line number Diff line number Diff line change
@@ -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.



4 changes: 4 additions & 0 deletions docs/status.txt
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions main.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}