diff --git a/Uppgift-3-Spel/.vscode/settings.json b/Uppgift-3-Spel/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..c5dc643e1d07f50e01daeda529bdb508f6b96a82 --- /dev/null +++ b/Uppgift-3-Spel/.vscode/settings.json @@ -0,0 +1,67 @@ +{ + "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 diff --git a/Uppgift-3-Spel/a.out b/Uppgift-3-Spel/a.out new file mode 100755 index 0000000000000000000000000000000000000000..c1c47349945b8778a077b12755772931be7875c5 Binary files /dev/null and b/Uppgift-3-Spel/a.out differ diff --git a/Uppgift-3-Spel/ghost.cc b/Uppgift-3-Spel/ghost.cc new file mode 100644 index 0000000000000000000000000000000000000000..703cecd6e17a4e811ea0bc361bc15bac52bc6f16 --- /dev/null +++ b/Uppgift-3-Spel/ghost.cc @@ -0,0 +1,51 @@ +#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 diff --git a/Uppgift-3-Spel/ghost.h b/Uppgift-3-Spel/ghost.h index 74e375053fea15e27c9e33d97cb17d7b5fcb429b..8f5078368bc4fd68f5ba0ef7577ebfb413ba4bc2 100644 --- a/Uppgift-3-Spel/ghost.h +++ b/Uppgift-3-Spel/ghost.h @@ -1,6 +1,3 @@ -#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 diff --git a/Uppgift-3-Spel/main.cc b/Uppgift-3-Spel/main.cc index 6f829e54e3d32bb6fc49c9732a18e72c9d0023c7..38bbfc157c07c9346b267bc101938fde0cee97ee 100644 --- a/Uppgift-3-Spel/main.cc +++ b/Uppgift-3-Spel/main.cc @@ -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� + 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; } + diff --git a/Uppgift-3-Spel/main.o b/Uppgift-3-Spel/main.o new file mode 100644 index 0000000000000000000000000000000000000000..e9dfced89aa5f4db9b4709672a8b8850d1b9d22f Binary files /dev/null and b/Uppgift-3-Spel/main.o differ