Skip to content
Snippets Groups Projects
Commit a868006a authored by adriansmakaliu's avatar adriansmakaliu
Browse files

Adrian push

parent 9c2a69c7
No related branches found
No related tags found
No related merge requests found
{
"files.associations": {
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"cwchar": "cpp",
"array": "cpp",
"atomic": "cpp",
"hash_map": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"chrono": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"cwctype": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"ranges": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"ctime": "cpp",
"deque": "cpp",
"optional": "cpp",
"ratio": "cpp",
"fstream": "cpp",
"iomanip": "cpp",
"stop_token": "cpp"
}
}
\ No newline at end of file
File added
#include "ghost.h"
Ghost::Ghost(const string &colorName, Point const &start_position)
: color_index(colorName), pos(start_position)
{}
void Ghost::set_pos( Point &new_pos) {
pos = new_pos;
}
Point Ghost::get_pos() {
return pos;
}
bool Blinky::get_angry(){
return angry;
}
void Blinky::set_angry(bool state) {
angry = state;
}
Blinky::Blinky(std::string const &color, Point const &start_pos)
: Ghost("red", start_pos)
{}
void Blinky::set_pos(Point &new_pos) {
set_pos(new_pos);
}
Point Blinky::get_scatter(const Point &pos_pacman) {
if (angry == true)
{
return Point{pos_pacman.x, pos_pacman.y}; // stämmer?
} else
{
return Point{6, 6};
}
}
Point Blinky::get_chase(const Point &pos_pacman, const Point &dir_pacman) {
return Point{pos_pacman.x, pos_pacman.y};
}
Point Blinky::get_pos() {
return pos;
}
std::string Blinky::get_color() {
return "pink";
}
\ No newline at end of file
#ifndef GHOST_H
#define GHOST_H
#include "given.h"
#include "string"
using namespace std;
......@@ -8,48 +5,36 @@ using namespace std;
class Ghost
{
public:
Ghost(Point const& start_position, std::string const& color);
Ghost(std::string const &color, Point const &start_pos);
virtual void set_pos( Point &new_pos);
virtual Point get_scatter(const Point &pos_pacman) = 0;
virtual Point get_chase(const Point &pos_pacman, const Point &dir_pacman) = 0;
virtual Point get_pos();
virtual std::string get_color()const = 0;
virtual ~Ghost() = default;
virtual Point get_scatter_point(const Point& pacmanPosition) const = 0;
virtual Point get_chase_point(const Point& pacmanPosition, const Point& pacmanDirection) = 0;
virtual void set_position(const Point& new_position);
virtual Point get_position();
virtual std::string get_color() const = 0;
// virtual Point get_target_position() const = 0;
virtual void set_blinky_position(const Point& new_position)
{
blinkyPosition.x = new_position.x;
blinkyPosition.y = new_position.y;
}
virtual void set_pinky_position(const Point& new_position)
{
pinkyPosition.x = new_position.x;
pinkyPosition.y = new_position.y;
}
protected:
Point position;
std::string colorName;
Point blinkyPosition;
Point pinkyPosition;
public:
std::string color_index;
Point pos;
};
class Clyde
class Clyde: public Ghost
{
public:
Clyde(std::string const &color, Point const &start_pos);
void set_pos(const Point &new_pos);
void set_pos(Point &new_pos);
Point get_scatter(const Point &pos_pacman);
Point get_chase(const Point &pos_pacman, const Point &dir_pacman);
Point get_pos();
std::string get_color()const;
};
class Pinky
class Pinky: public Ghost
{
public:
Pinky(std::string const &color, Point const &start_pos);
void set_pos(const Point &new_pos);
void set_pos(Point &new_pos);
Point get_scatter(const Point &pos_pacman);
Point get_chase(const Point &pos_pacman, const Point &dir_pacman);
Point get_pos();
......@@ -58,17 +43,17 @@ public:
class Blinky
class Blinky : public Ghost
{
public:
bool angry();
bool anger_activated(bool state);
bool get_angry();
void set_angry(bool state);
Blinky(std::string const &color, Point const &start_pos);
void set_pos(const Point &new_pos);
void set_pos(Point &new_pos);
Point get_scatter(const Point &pos_pacman);
Point get_chase(const Point &pos_pacman, const Point &dir_pacman);
Point get_pos();
std::string get_color()const;
std::string get_color();
private:
bool angry;
};
#endif
\ No newline at end of file
......@@ -10,11 +10,11 @@ using namespace std;
Ledning och Tips:
- Modifiera stukturen till en header-fil och en implementationsfil
- Utöka 'run()' och 'draw_map()' med övrig funktionalitet.
- Lägg alla spöken i en lämplig behållare som en datamedlem.
- Utöka 'run()' och 'draw_map()' med övrig funktionalitet.
- Lägg alla spöken i en lämplig behållare som en datamedlem.
- Bryt ut stora kodblock till egna funktioner.
- Använd hjälpfunktioner för att undvika duplicering av kod.
- Tänk på att varje funktion inte borde vara längre än 25 rader.
- Använd hjälpfunktioner för att undvika duplicering av kod.
- Tänk på att varje funktion inte borde vara längre än 25 rader.
*/
class Ghost_Tester
......@@ -60,7 +60,7 @@ public:
private:
/*
En hjälpfunktion som avgör vilka två tecken som ska ritas ut för en given position på
 
spelplanen.
*/
string to_draw(Point const& curr_pos)
......@@ -76,13 +76,13 @@ private:
}
/*
En hjälpfunktion för att rita ut spelplanen för testprogrammet.
En hjälpfunktion för att rita ut spelplanen för testprogrammet.
Itererar över varje rad och column i kartan. Index för raderna är flippade för att placera
y = 0 längst ned.
Itererar över varje rad och column i kartan. Index för raderna är flippade för att placera
y = 0 längst ned.
Varje punkt i kartan ritas som två tecken eftersom ett tecken i terminalen är ca dubbelt så
högt som det är brett.
Varje punkt i kartan ritas som två tecken eftersom ett tecken i terminalen är ca dubbelt så
högt som det är brett.
*/
void draw_map()
{
......@@ -110,3 +110,4 @@ int main()
gt.run();
return 0;
}
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment