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
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
64 changes: 64 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"files.associations": {
"cmath": "cpp",
"stdexcept": "cpp",
"numeric": "cpp",
"iostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp"
}
}
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
9 changes: 7 additions & 2 deletions StudentTest1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ TEST_SUITE("Point class tests") {

}

TEST_SUITE("Classes initialization tests and Team modification( add(),stillAlive() )") {

TEST_SUITE("Classes initialization tests and Team modification( add(),stillAlive() )")
{
TEST_CASE("Cowboy initialization") {
Cowboy cowboy{"Bob", Point{2, 3}};
CHECK(cowboy.hasboolets());
CHECK_EQ(cowboy.getName(), "Bob");
CHECK_EQ(cowboy.getLocation().distance(Point{2, 3}), 0);
cout << "cowboy.getLocation():" << cowboy.getLocation().print() << endl;
CHECK_NE(cowboy.getLocation().distance(Point{3, 2}), 0);

CHECK(cowboy.isAlive());
Expand Down Expand Up @@ -141,8 +142,12 @@ TEST_SUITE("Classes initialization tests and Team modification( add(),stillAlive

TEST_CASE("Team initialization") {
auto cowboy = create_cowboy(2, 3);
//cout << cowboy->print() << endl;
auto ninja = create_yninja(2, 3);
//cout << ninja->print() << endl;

Team team{cowboy};

CHECK_EQ(team.stillAlive(), 1);

Team2 team2{ninja};
Expand Down
70 changes: 70 additions & 0 deletions sources/Character.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "Character.hpp"

using namespace std;
using namespace ariel;

Character::Character(string name, Point location, int hitPoint) : _name(name), _location(location), _hitPoints(hitPoint), _captain(false), _teamate(false)
{

}

string Character::getName() const
{
return _name;
}

int Character::getHitPoint() const
{
return _hitPoints;
}

Point Character::getLocation() const
{
return _location;
}

void Character::setLocation(Point& location)
{
_location = location;
return;
}

bool Character::isAlive() const
{
return (_hitPoints>0 ? true : false);
}

double Character::distance(Character *other) const
{
if (other!=nullptr)
{
return _location.distance(other->getLocation());
}
else
{
throw invalid_argument("null character!");
}
}

void Character::hit(int amount)
{
if (amount >= 0)
{
if(_hitPoints - amount < 0)
{
_hitPoints = 0;
cout << _name << "is dead, and inactive :(" << endl;
}
else
{
_hitPoints = _hitPoints - amount;
}

}
else
{
throw invalid_argument("Hit Points can't be negative");
}

cout << _hitPoints << "@@@@@@@@@@@" << endl;
}
37 changes: 37 additions & 0 deletions sources/Character.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once
#include <iostream>
#include <vector>
#include <string>
using namespace std;

#include "Point.hpp"

using namespace ariel;
namespace ariel
{
class Character
{
protected:
string _name;
Point _location;
int _hitPoints;

public:
bool _captain;
bool _teamate;
//bool _active;

Character(string name, Point location, int hitPoint);

string getName() const;
int getHitPoint() const;
Point getLocation() const;
void setLocation(Point& location);
virtual ~Character() {}
bool isAlive() const;
double distance(Character *other) const;
void hit(int amount);
virtual string print() const = 0;

};
}
73 changes: 73 additions & 0 deletions sources/Cowboy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "Cowboy.hpp"

using namespace std;
using namespace ariel;

Cowboy::Cowboy(string name, Point location) : Character(name, location,110), _bullets(6)
{

}
//## copy constructor??

void Cowboy::shoot(Character *other)
{
if (other==nullptr)
{
throw invalid_argument("Null Value");
}

if (other==this)
{
throw runtime_error("Self-Hit is not possible");
}
else if (isAlive() != true)
{
throw runtime_error("Charecter is dead, and inactive 3");
}
else if (other->isAlive() != true)
{
throw runtime_error("Charecter is dead, and inactive 4");
}
else
{
if (_bullets > 0)
{
cout << getName() << " shooting " << other->getName() << " 10 hitPoints" << endl;
_bullets -= 1;
other->hit(10);
}
else
{
cout << "no bulltes left for" << getName() << endl;
}
}
}

bool Cowboy::hasboolets() const
{
return (_bullets>0 ? true : false);
}

void Cowboy::reload()
{
if (isAlive() != true)
{
throw runtime_error("Charecter is dead, and inactive 5");
}
else
{
cout << "reload 6 bullets to: " << getName() << endl;
_bullets = 6;
}
}

string Cowboy::print() const
{
if (isAlive() != true)
{
return "Name(Cowboy): "+getName()+", Location: "+getLocation().print();
}


return "Name(Cowboy): "+getName()+", Location: "+getLocation().print()+", Hit Points: "+to_string(getHitPoint());
}
24 changes: 24 additions & 0 deletions sources/Cowboy.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once
#include <iostream>
#include <vector>
#include <string>
using namespace std;

#include "Character.hpp"
using namespace ariel;
namespace ariel
{
class Cowboy: public Character
{
private:
int _bullets;

public:
Cowboy(string name, Point location);

void shoot(Character *other);
bool hasboolets() const;
void reload();
string print() const override;
};
}
Loading