From e25148231807dfd310b6cf843f8e2958dfd3e68b Mon Sep 17 00:00:00 2001 From: marvel16 Date: Sat, 8 Feb 2014 00:16:12 +0200 Subject: [PATCH 1/5] push --- 1.cpp | 11 ++++++++--- 2.cpp | 12 +++++++++++- 3.cpp | 14 ++++++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/1.cpp b/1.cpp index 898198d..27ed8fa 100644 --- a/1.cpp +++ b/1.cpp @@ -1,11 +1,16 @@ // Разверните строку. Указатель reverse_string должен // указывать на развернутую строку. -char* string = "The string!"; +char* string = “The string!”; int main() { char* reverse_string; - + int sz = strlen(string); + reverse_string= new char[sz+1]; + for(int i=0; i m[i][j]) temp=m[i][j]; + return temp; } int _tmain(int argc, _TCHAR* argv[]) { Matrix matrix; + for(int i=0; i +#include +#include +#include "Polyline.h" + + + +int _tmain(int argc, _TCHAR* argv[]) +{ + using namespace std; + + Points points; + Handler handle; + handle.InputPoints(points); + handle.ShowInput(points); + handle.cycle(points); + handle.ShowCrossPoints(); + + system("pause"); + return 0; +} + diff --git a/Polyline/Polyline.h b/Polyline/Polyline.h new file mode 100644 index 0000000..08c5395 --- /dev/null +++ b/Polyline/Polyline.h @@ -0,0 +1,86 @@ +#include +#include +#include +#include + +using namespace std; + +typedef std::vector> Points; + +//class that handles vector of entered points +class Handler +{ + int size; // number of points + Points crossPts; // vector of cross points for all segments +public: + void InputPoints(Points & obj); + void ShowInput(const Points & obj) const; + friend ostream& operator<<(ostream& os, const pair & obj); + void crossPoint(const Points& obj, int s1, int s2, int s3, int s4); + void ShowCrossPoints() const; + void cycle(const Points& obj); +}; + +void Handler::InputPoints(Points & obj) +{ + + cout << "Input number of points > 3: "; + cin >> size; + obj.resize(size); + cout << "Enter " << size << " points in format: x y\n"; + for(int i=0; i> obj[i].first >> obj[i].second; + } +} + +void Handler::ShowInput(const Points & obj) const +{ + int i=1; + for(Points::const_iterator it = obj.begin(); it != obj.end();++it,++i) + cout << "\n#" << i << *it; +} + +ostream& operator<<(ostream& os,const pair & obj) +{ + os << "(" << obj.first << "," << obj.second << ") "; + return os; +} + +// looking for cross point of 2 segments and pushing into vector of points +void Handler::crossPoint(const Points& obj, int s1 , int s2, int s3, int s4) +{ + double a1,a2,b1,b2; //coefs + double x,y; //cross point coordinates + a1 = (obj[s2].second - obj[s1].second)/(obj[s2].first - obj[s1].first); // y=a1*x+b + a2 = (obj[s4].second - obj[s3].second)/(obj[s4].first - obj[s3].first);// + b1 = obj[s1].second - a1*obj[s1].first;// + b2 = obj[s3].second - a2*obj[s3].first;// + if(a1 == a2 ) return; // paralel no points + x = (b2-b1)/(a1-a2); + y = a1*x + b1; + //checking if point belongs the segments + if( x <= max(obj[s1].first, obj[s2].first) && x >= min(obj[s1].first, obj[s2].first) + && x <= max(obj[s3].first, obj[s4].first) && x >= min(obj[s3].first, obj[s4].first) + && y <= max(obj[s1].second, obj[s2].second) && y >= min(obj[s1].second, obj[s2].second) + && y <= max(obj[s3].second, obj[s4].second) && y >= min(obj[s3].second, obj[s4].second)) + crossPts.push_back(make_pair(x,y)); +} + +void Handler::ShowCrossPoints() const +{ + int i=1; + cout << "\nCross points: "; + for(Points::const_iterator it = crossPts.begin(); it != crossPts.end(); ++it, ++i) + cout << "\n#"< Date: Wed, 26 Mar 2014 21:55:22 +0200 Subject: [PATCH 3/5] update: fixed finding coef for paralell OY segments, excluding repeating points from vector of crossPoints --- Polyline/Polyline.cpp | 1 + Polyline/Polyline.h | 81 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 72 insertions(+), 10 deletions(-) diff --git a/Polyline/Polyline.cpp b/Polyline/Polyline.cpp index b542bb5..0041172 100644 --- a/Polyline/Polyline.cpp +++ b/Polyline/Polyline.cpp @@ -16,6 +16,7 @@ int _tmain(int argc, _TCHAR* argv[]) Points points; Handler handle; handle.InputPoints(points); + handle.InitGraph(points); handle.ShowInput(points); handle.cycle(points); handle.ShowCrossPoints(); diff --git a/Polyline/Polyline.h b/Polyline/Polyline.h index 08c5395..c4edb42 100644 --- a/Polyline/Polyline.h +++ b/Polyline/Polyline.h @@ -2,9 +2,11 @@ #include #include #include +#include using namespace std; - +#define EPS 1.0E-6 +typedef vector>> Graph; typedef std::vector> Points; //class that handles vector of entered points @@ -12,15 +14,52 @@ class Handler { int size; // number of points Points crossPts; // vector of cross points for all segments + Graph graph; + public: + Handler::Handler() {} + void InitGraph(const Points& obj); void InputPoints(Points & obj); void ShowInput(const Points & obj) const; friend ostream& operator<<(ostream& os, const pair & obj); void crossPoint(const Points& obj, int s1, int s2, int s3, int s4); void ShowCrossPoints() const; void cycle(const Points& obj); + // func to compare doubles + }; +bool myfunction (pair i, pair j) + { return abs(i.first-j.first) i, pair j) +{ + if(abs(i.first-j.first)< EPS) + return i.second < j.second; + else return i.first < j.first; +} + + +void Handler::InitGraph(const Points& obj) +{ + graph.resize(obj.size()); + graph[0].push_back(obj[0]); + graph[0].push_back(obj[obj.size()-1]); + graph[0].push_back(obj[1]); + + graph[obj.size()-1].push_back(obj[obj.size()-1]); + graph[obj.size()-1].push_back(obj[obj.size()-2]); + graph[obj.size()-1].push_back(obj[0]); + + for(int i=1; i < obj.size()-2; i++) + { + graph[i].push_back(obj[i]); + graph[i].push_back(obj[i+1]); + graph[i].push_back(obj[i-1]); + } +} + +//user input-point-function void Handler::InputPoints(Points & obj) { @@ -35,6 +74,7 @@ void Handler::InputPoints(Points & obj) } } +//shows what did used input void Handler::ShowInput(const Points & obj) const { int i=1; @@ -51,21 +91,37 @@ ostream& operator<<(ostream& os,const pair & obj) // looking for cross point of 2 segments and pushing into vector of points void Handler::crossPoint(const Points& obj, int s1 , int s2, int s3, int s4) { - double a1,a2,b1,b2; //coefs + double a1,a2,b1,b2,c1,c2; //coefs double x,y; //cross point coordinates - a1 = (obj[s2].second - obj[s1].second)/(obj[s2].first - obj[s1].first); // y=a1*x+b - a2 = (obj[s4].second - obj[s3].second)/(obj[s4].first - obj[s3].first);// - b1 = obj[s1].second - a1*obj[s1].first;// - b2 = obj[s3].second - a2*obj[s3].first;// - if(a1 == a2 ) return; // paralel no points - x = (b2-b1)/(a1-a2); - y = a1*x + b1; + + a1 = obj[s1].second - obj[s2].second; // ax+by+c=0 + a2 = obj[s3].second - obj[s4].second;// + b1 = obj[s2].first - obj[s1].first;// + b2 = obj[s4].first - obj[s3].first;// + c1 = obj[s1].first * obj[s2].second - obj[s2].first * obj[s1].second; + c2 = obj[s3].first * obj[s4].second - obj[s4].first * obj[s3].second; + + if( abs(a1-a2) < EPS && abs(b1-b2) < EPS ) return; // paralel no points + + x = ( b1*c2 - b2*c1 ) / (a1*b2-a2*b1); + y = (a2*c1 - a1*c2) / (a1*b2 - a2*b1); + //checking if point belongs the segments if( x <= max(obj[s1].first, obj[s2].first) && x >= min(obj[s1].first, obj[s2].first) && x <= max(obj[s3].first, obj[s4].first) && x >= min(obj[s3].first, obj[s4].first) && y <= max(obj[s1].second, obj[s2].second) && y >= min(obj[s1].second, obj[s2].second) && y <= max(obj[s3].second, obj[s4].second) && y >= min(obj[s3].second, obj[s4].second)) - crossPts.push_back(make_pair(x,y)); + { + crossPts.push_back(make_pair(x,y)); + vector > point_vector; + graph.push_back(point_vector); + graph[graph.size()-1].push_back(make_pair(x,y));//push_back(make_pair(x,y)); + graph[graph.size()-1].push_back(make_pair(obj[s1].first,obj[s1].second)); + graph[graph.size()-1].push_back(make_pair(obj[s2].first,obj[s2].second)); + graph[graph.size()-1].push_back(make_pair(obj[s3].first,obj[s3].second)); + graph[graph.size()-1].push_back(make_pair(obj[s4].first,obj[s4].second)); + } + } void Handler::ShowCrossPoints() const @@ -83,4 +139,9 @@ void Handler::cycle(const Points& obj) crossPoint(obj, i,i+1,j+1,j+2); for(int i=0; i Date: Sat, 29 Mar 2014 12:33:11 +0200 Subject: [PATCH 4/5] Pacman --- Pacman/Pacman.pro | 35 +++++ Pacman/Pacman.pro.user | 251 ++++++++++++++++++++++++++++++++ Pacman/Source_files.qrc | 11 ++ Pacman/ThreadPool.h | 98 +++++++++++++ Pacman/creature.cpp | 55 +++++++ Pacman/creature.h | 33 +++++ Pacman/finish.png | Bin 0 -> 138 bytes Pacman/gamemap.cpp | 103 +++++++++++++ Pacman/gamemap.h | 65 +++++++++ Pacman/gold.png | Bin 0 -> 313 bytes Pacman/level1.txt | 16 +++ Pacman/level2.txt | 16 +++ Pacman/log.txt | 1 + Pacman/log2.txt | 3 + Pacman/main.cpp | 12 ++ Pacman/monster.png | Bin 0 -> 173 bytes Pacman/monster_creature.cpp | 73 ++++++++++ Pacman/monster_creature.h | 15 ++ Pacman/pacman.cpp | 278 ++++++++++++++++++++++++++++++++++++ Pacman/pacman.h | 69 +++++++++ Pacman/pacman.png | Bin 0 -> 659 bytes Pacman/pacman.ui | 179 +++++++++++++++++++++++ Pacman/pacman_creature.cpp | 38 +++++ Pacman/pacman_creature.h | 17 +++ Pacman/wall.png | Bin 0 -> 173 bytes 25 files changed, 1368 insertions(+) create mode 100644 Pacman/Pacman.pro create mode 100644 Pacman/Pacman.pro.user create mode 100644 Pacman/Source_files.qrc create mode 100644 Pacman/ThreadPool.h create mode 100644 Pacman/creature.cpp create mode 100644 Pacman/creature.h create mode 100644 Pacman/finish.png create mode 100644 Pacman/gamemap.cpp create mode 100644 Pacman/gamemap.h create mode 100644 Pacman/gold.png create mode 100644 Pacman/level1.txt create mode 100644 Pacman/level2.txt create mode 100644 Pacman/log.txt create mode 100644 Pacman/log2.txt create mode 100644 Pacman/main.cpp create mode 100644 Pacman/monster.png create mode 100644 Pacman/monster_creature.cpp create mode 100644 Pacman/monster_creature.h create mode 100644 Pacman/pacman.cpp create mode 100644 Pacman/pacman.h create mode 100644 Pacman/pacman.png create mode 100644 Pacman/pacman.ui create mode 100644 Pacman/pacman_creature.cpp create mode 100644 Pacman/pacman_creature.h create mode 100644 Pacman/wall.png diff --git a/Pacman/Pacman.pro b/Pacman/Pacman.pro new file mode 100644 index 0000000..1c2bd47 --- /dev/null +++ b/Pacman/Pacman.pro @@ -0,0 +1,35 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-06-07T16:25:03 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = Pacman +TEMPLATE = app + + +SOURCES += main.cpp\ + pacman.cpp \ + gamemap.cpp \ + creature.cpp \ + pacman_creature.cpp \ + monster_creature.cpp + +HEADERS += pacman.h \ + gamemap.h \ + creature.h \ + pacman_creature.h \ + monster_creature.h \ + ThreadPool.h + +FORMS += pacman.ui + +RESOURCES += \ + Source_files.qrc +CONFIG += c++11 +OTHER_FILES += + diff --git a/Pacman/Pacman.pro.user b/Pacman/Pacman.pro.user new file mode 100644 index 0000000..8ce06a6 --- /dev/null +++ b/Pacman/Pacman.pro.user @@ -0,0 +1,251 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.3.0 MinGW 32bit + Desktop Qt 5.3.0 MinGW 32bit + qt.53.win32_mingw482_kit + 0 + 0 + 0 + + D:/Qt_Projects/build-Pacman-Desktop_Qt_5_3_0_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + D:/Qt_Projects/build-Pacman-Desktop_Qt_5_3_0_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Pacman + + Qt4ProjectManager.Qt4RunConfiguration:D:/Qt_Projects/Pacman/Pacman.pro + + Pacman.pro + false + false + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {1ef6cdab-f21e-4980-a51d-da4ecd6e5454} + + + ProjectExplorer.Project.Updater.FileVersion + 15 + + diff --git a/Pacman/Source_files.qrc b/Pacman/Source_files.qrc new file mode 100644 index 0000000..2398d39 --- /dev/null +++ b/Pacman/Source_files.qrc @@ -0,0 +1,11 @@ + + + finish.png + gold.png + level1.txt + level2.txt + monster.png + pacman.png + wall.png + + diff --git a/Pacman/ThreadPool.h b/Pacman/ThreadPool.h new file mode 100644 index 0000000..d15fd87 --- /dev/null +++ b/Pacman/ThreadPool.h @@ -0,0 +1,98 @@ +#ifndef THREAD_POOL_H +#define THREAD_POOL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +class ThreadPool { +public: + ThreadPool(size_t); + void joinAll(); + template + auto enqueue(F&& f, Args&&... args) + -> std::future::type>; + ~ThreadPool(); +private: + // need to keep track of threads so we can join them + std::vector< std::thread > workers; + // the task queue + std::queue< std::function > tasks; + + // synchronization + std::mutex queue_mutex; + std::condition_variable condition; + bool stop; +}; + +// the constructor just launches some amount of workers +inline ThreadPool::ThreadPool(size_t threads) + : stop(false) +{ + for(size_t i = 0;i lock(this->queue_mutex); + while(!this->stop && this->tasks.empty()) + this->condition.wait(lock); + if(this->stop && this->tasks.empty()) + return; + std::function task(this->tasks.front()); + this->tasks.pop(); + lock.unlock(); + task(); + } + } + ); +} + + +// add new work item to the pool +template +auto ThreadPool::enqueue(F&& f, Args&&... args) + -> std::future::type> +{ + typedef typename std::result_of::type return_type; + + // don't allow enqueueing after stopping the pool + if(stop) + throw std::runtime_error("enqueue on stopped ThreadPool"); + + auto task = std::make_shared< std::packaged_task >( + std::bind(std::forward(f), std::forward(args)...) + ); + + std::future res = task->get_future(); + { + std::unique_lock lock(queue_mutex); + tasks.push([task](){ (*task)(); }); + } + condition.notify_one(); + return res; +} + +// the destructor joins all threads +inline ThreadPool::~ThreadPool() +{ + { + std::unique_lock lock(queue_mutex); + stop = true; + } + condition.notify_all(); + for(size_t i = 0;isetPixmap(m_creature_image); + m_label->setScaledContents(true); + m_label->resize(CELL_SIZE,CELL_SIZE); + m_label->show(); + +} + +Creature::~Creature(){} + +void Creature::move(const int dx,const int dy) +{ + if(m_pmap->getCell(m_x+dx,m_y-dy) != WALL ) + { + m_x += dx; + m_y -= dy; + } +} + +void Creature::move(const Point &point) +{ + move(point.x - m_x, m_y - point.y ); +} + +void Creature::setPosition(const size_t x,const size_t y) +{ + m_x = x; + m_y = y; +} + +void Creature::setPosition(const Point &point) +{ + m_x = point.x; + m_y = point.y; +} + +void Creature::drawCreature() +{ + m_label->move(m_x*CELL_SIZE, m_y*CELL_SIZE); +} + +Point Creature::getPosition() const +{ + return Point(m_x,m_y); +} + diff --git a/Pacman/creature.h b/Pacman/creature.h new file mode 100644 index 0000000..b4faca1 --- /dev/null +++ b/Pacman/creature.h @@ -0,0 +1,33 @@ +#ifndef CREATURE_H +#define CREATURE_H + +#include "gamemap.h" +#include +#include +#include + +typedef std::shared_ptr QLabelPtr; +// Creature class to handle move-events and containing +//data for displaying on main window +class Creature +{ +public: + const size_t CELL_SIZE = 25; + Creature(GameMapPtr pmap, QPixmap image, QWidget* parent ); + virtual ~Creature(); + void move(const int dx,const int dy); + void move(const Point& point); + void setPosition(const size_t x,const size_t y); + void setPosition(const Point& point); + virtual void drawCreature(); + Point getPosition() const; + +protected: + size_t m_x; + size_t m_y; + GameMapPtr m_pmap; + QPixmap m_creature_image; + QLabelPtr m_label; +}; + +#endif // CREATURE_H diff --git a/Pacman/finish.png b/Pacman/finish.png new file mode 100644 index 0000000000000000000000000000000000000000..c0c2de8fedf38f3991cb4a92589d8f27e232ea40 GIT binary patch literal 138 zcmZ?wbhEHblw^=(n8?8J|Nnm=!2kw|KUu)E4u}NFGcZL@>0c>%mnli)-APaFJvVbR zLk^mEst9C>XRTZLeA^wT>uzg`p52Vxb!>8DnZ=Fs!e@9Jx2ZWr1SKud(OhM&^~>SL hl8N4Lcg;z8Z`O4st)KsM)y%a07jw7negm|`8US?UHr4 + +#include +#include + +GameMap::GameMap() : m_level(0) +{ + m_wall_icon = QPixmap(":/wall.png"); + m_gold_icon = QPixmap(":/gold.png"); + m_finish_icon = QPixmap(":/finish.png"); + + levelFiles.push_back(":/level1.txt"); + levelFiles.push_back(":/level2.txt"); +} + +void GameMap::loadMap() +{ + if(map.size()) map.clear(); + std::vector vecStr; + QString levelString(levelFiles[m_level]); + QFile file(levelString); + file.open(QIODevice::ReadOnly | QIODevice::Text); + + QTextStream in(&file); + QString line = in.readLine();; + while (!line.isNull()) + { + vecStr.push_back(line.toStdString()); + line = in.readLine(); + } + + map.resize(vecStr.size()); + for(size_t i = 0; i < vecStr.size(); i++) + for(size_t j = 0; j < vecStr[i].size(); j++) + { + map[i].push_back(MAP_OBJECTS((int)(vecStr[i][j] - '0'))); + switch(map[i][j]) + { + case START: m_startPoint.x=j; + m_startPoint.y=i; + break; + case FINISH: m_finishPoint.x=j; + m_finishPoint.y=i; + break; + case MONSTER: m_mnstrPoints.push(Point(j,i)); + break; + default: break; + } + } +} + +MAP_OBJECTS GameMap::getCell(const size_t j,const size_t i) const +{ + return map[i][j]; +} + +void GameMap::setCell(const size_t j,const size_t i, MAP_OBJECTS val) +{ + map[i][j] = val; +} + +size_t GameMap::mapSizeY() const +{ + return map.size(); +} + + +size_t GameMap::mapSizeX() const +{ + return map[0].size(); +} + +size_t GameMap::monstersAmount() const +{ + return m_mnstrPoints.size(); +} + +Point GameMap::startPoint() const +{ + return m_startPoint; +} + + +Point GameMap::finishPoint() const +{ + return m_finishPoint; +} + +Point GameMap::startPointMonster() +{ + Point temp = m_mnstrPoints.top(); + m_mnstrPoints.pop(); + return temp; +} + +GameMap::~GameMap(){} + +void GameMap::levelUp() +{ + if(m_level < (levelFiles.size()-1)) + m_level++; +} diff --git a/Pacman/gamemap.h b/Pacman/gamemap.h new file mode 100644 index 0000000..13c9145 --- /dev/null +++ b/Pacman/gamemap.h @@ -0,0 +1,65 @@ +#ifndef GAMEMAP_H +#define GAMEMAP_H + +#include +#include +#include +#include + +// types of map containment +enum MAP_OBJECTS {SPACE=0,WALL,GOLD, START,FINISH,MONSTER}; + +struct Point +{ + size_t x; + size_t y; + Point() :x(0),y(0){} + Point(size_t x,size_t y) : x(x),y(y){} + Point(const Point& obj) + { + x=obj.x; + y=obj.y; + } + Point& operator=(const Point& obj) + { + x=obj.x; + y=obj.y; + return *this; + } + bool operator ==(const Point& obj) + { + return (obj.x==this->x && obj.y==this->y); + } +}; + +// Game map containing its elements for filling cells +// and displaying on main window +class GameMap +{ +public: + GameMap(); + MAP_OBJECTS getCell(const size_t i,const size_t j) const; //returns map cell containment + void loadMap(); + size_t mapSizeY() const; + size_t mapSizeX() const; + size_t monstersAmount() const; //call once when initializing monsters + void setCell(const size_t i,const size_t j, MAP_OBJECTS); //used by pacman creature to change cell + Point startPoint() const;// returns start and finish + Point finishPoint() const;// coordinates + Point startPointMonster();// returns st.point from stack to monster obj + ~GameMap(); + void levelUp(); +private: + std::vector > map; + Point m_startPoint; + Point m_finishPoint; + std::stack m_mnstrPoints; + QPixmap m_wall_icon; + QPixmap m_gold_icon; + QPixmap m_finish_icon; + size_t m_level; + std::vector levelFiles; +}; + +typedef std::shared_ptr GameMapPtr; +#endif // GAMEMAP_H diff --git a/Pacman/gold.png b/Pacman/gold.png new file mode 100644 index 0000000000000000000000000000000000000000..a1e50baa7959f8d63a7057491857556f44bd4b76 GIT binary patch literal 313 zcmeAS@N?(olHy`uVBq!ia0vp^k|4~)3?z59=Y9ZEEa{HEjtmSN`?>!lvI6-E$sR$z z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBD8U)v6XFV_|HNzl`}gmq z*3o}J4r57>UoeBivm0q3PLj8~3sV|*O$tbPfk$L90|Vbd5N6ylG5al0P|nlEF@)oK za)N@i0h>d{#efhilPiq+z3b%C_<&|-KVbcQbm4s^pi0#e*NBpo#FA92H$NpatrE9}icL4 + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Pacman w; + + w.show(); + + return a.exec(); +} diff --git a/Pacman/monster.png b/Pacman/monster.png new file mode 100644 index 0000000000000000000000000000000000000000..adfd424c6fd2d7bb9a14d3da922f922a52094fc0 GIT binary patch literal 173 zcmZ?wbhEHblw^=(_{abP-u?f90LW1M$->CMz|5cn5(UXKaMUrdbI5pXSa7hJLs%>3 z#0Q0jb_OXa7J&tej&=yK2W&YZsC>9r#@dX>)9AqQE~cO;A5Db@_ZE@JZ9EE>pB|dQ zB)8~{=f|bavuw&=eX-n_;<1R;QEKbTfR%wuSmsV^u?o=gT*b6jZtu=7O4rx + +enum GRAPH_OBJ {BAD =-1 , BLANK =-2}; + +Monster_creature::Monster_creature(GameMapPtr pmap, QPixmap image, QWidget* parent) + : Creature(pmap, image , parent ) , flag(false) +{ + m_movePoint = Point(m_pmap->startPointMonster()); + setPosition(m_movePoint); +} + + +Point Monster_creature::persuitPacman(const Point &point) +{ + + size_t SIZE = m_pmap->mapSizeY(); + std::vector > graph(m_pmap->mapSizeY()); + std::vector path; + Point start(m_x,m_y) ,end(point); + Point current(point); + + if(start==end) return end; + //graph init + for(size_t i=0; i < m_pmap->mapSizeY(); ++i) + for(size_t j=0; j < m_pmap->mapSizeX(); ++j) + { + if(m_pmap->getCell(j,i) == WALL) + graph[i].push_back(BAD); + else graph[i].push_back(BLANK); + } + + //wave expansion + int dx[4] = {1, 0, -1, 0};//shifts + int dy[4] = {0, 1, 0, -1};//up,down,left,right + int d = 0; + bool stop=false; + + graph[start.y][start.x] = 0; + while(!stop && graph[point.y][point.x] == BLANK) + { + stop=true; + for(size_t y=0; y < SIZE; ++y) + for(size_t x=0; x < SIZE; ++x) + if(graph[y][x] == d) + for(size_t k = 0; k < 4; ++k) //marking all unmarked neighbours + if(graph[y + dy[k]][x + dx[k]] == BLANK) + { + graph[y+dy[k]][x+dx[k]] = d+1; //wave expansion + stop = false; + } + ++d; + } + if (graph[point.y][point.x] == BLANK) return Point(); + + //writing backpath + while(d>0) + { + path.push_back(current); + d--; + + + for(size_t k=0; k < 4; ++k) + if(graph[current.y + dy[k]][current.x + dx[k]] == d) + { + current.x += dx[k]; + current.y += dy[k]; + break; + } + } + //path.push_back(start); //not using in this impl + return path.back(); +} diff --git a/Pacman/monster_creature.h b/Pacman/monster_creature.h new file mode 100644 index 0000000..47952b3 --- /dev/null +++ b/Pacman/monster_creature.h @@ -0,0 +1,15 @@ +#ifndef MONSTER_CREATURE_H +#define MONSTER_CREATURE_H +#include "creature.h" + +class Monster_creature: public Creature +{ +public: + Monster_creature(GameMapPtr pmap, QPixmap image, QWidget* parent); + Point persuitPacman(const Point &point);//finds path to point, and returns its first point + virtual ~Monster_creature(){} + Point m_movePoint; + bool flag; +}; + +#endif // MONSTER_CREATURE_H diff --git a/Pacman/pacman.cpp b/Pacman/pacman.cpp new file mode 100644 index 0000000..9e38764 --- /dev/null +++ b/Pacman/pacman.cpp @@ -0,0 +1,278 @@ +#include "pacman.h" +#include "ui_pacman.h" +#include "pacman_creature.h" +#include "gamemap.h" +#include "monster_creature.h" +#include +#include + +Pacman::Pacman(QWidget *parent) + :QMainWindow(parent) + ,ui(new Ui::Pacman) + ,m_pmap(new GameMap) + ,m_timer(new QTimer(this)) + ,m_monsterTimer(new QTimer(this)) + ,m_count(20) + ,m_keyIsPressed(false) + ,m_isUpdated(true) + ,m_startPause(true) + ,m_lostGameFlag(false) + ,m_key(Qt::Key_0) + ,m_score(0) + ,m_speed(5) + ,m_pool(4) +{ + + ui->setupUi(this); + + m_pmap->loadMap(); + m_pacman = PacmanPtr (new Pacman_creature( + m_pmap + ,QPixmap(":/pacman.png") + ,this)); + + size_t tempSize = m_pmap->monstersAmount(); + for(size_t i=0; idrawCreature(m_pacman->rotateFaceDirection(Qt::Key_0)); + + for(size_t i=0; idrawCreature(); + + //Setting timer, so speed of pacman and mosters are equal + connect(m_timer, SIGNAL(timeout()), this, SLOT(updateGame())); + connect(m_monsterTimer, SIGNAL(timeout()), this, SLOT(monsterBehaviourTimer()) ); +} + +void Pacman::drawMap() +{ + size_t size_x = m_pmap->mapSizeX(); + size_t size_y = m_pmap->mapSizeY(); + + for(size_t i=0; i < size_x; ++i) + for(size_t j=0; j< size_y; ++j) + switch(m_pmap->getCell(j,i)) + { + case WALL: + m_mapLabels[i][j]->setPixmap(QPixmap(":/wall.png")); + break; + case FINISH: + m_mapLabels[i][j]->setPixmap(QPixmap(":/finish.png")); + break; + case GOLD: + m_mapLabels[i][j]->setPixmap(QPixmap(":/gold.png")); + break; + case SPACE: + m_mapLabels[i][j]->clear(); + default: break; + } +} + +void Pacman::setLabels() +{ + + size_t size_x = m_pmap->mapSizeX(); + size_t size_y = m_pmap->mapSizeY(); + if(m_mapLabels.size()) + m_mapLabels.clear(); + m_mapLabels.resize(size_x); + for(size_t i=0; i < size_y; ++i) + for(size_t j=0; j< size_x; ++j) + { + m_mapLabels[i].push_back( QLabelPtr(new QLabel(this))); + m_mapLabels[i][j]->resize(CELL_SIZE,CELL_SIZE); + m_mapLabels[i][j]->move(j*CELL_SIZE,i*CELL_SIZE); + m_mapLabels[i][j]->show(); + } +} + +void Pacman::keyPressEvent(QKeyEvent * event) +{ + m_keyIsPressed = true; + m_isUpdated = false; + m_key = (Qt::Key)event->key(); +} + +void Pacman::keyReleaseEvent(QKeyEvent * event) +{ + m_keyIsPressed = false; +} + +void Pacman::interaction() +{ + int x = m_pacman->getPosition().x; + int y = m_pacman->getPosition().y; + //monster interaction + for(size_t i=0; i < m_monsters.size(); ++i) + if( m_pacman->getPosition() == m_monsters[i]->getPosition()) + { + m_timer->stop(); + m_lostGameFlag = true; + ui->startButton->setDisabled(true); + QMessageBox::information(this, "GAME INFO", "YOU LOST!!!"); + break; + } + //pacman-map interaction + switch(m_pmap->getCell(x,y)) + { + case GOLD: + m_pmap->setCell(x,y,SPACE); + m_score+=50; + ui->ScoreBox->setText(QString::number(m_score,10)); + break; + case FINISH: + if(m_score > 1000) + { + m_timer->stop(); + QMessageBox::information(this, "GAME INFO", "YOU WON!!!"); + m_pmap->levelUp(); + } + break; + default: break; + } +} + +void Pacman::setInterface() +{ + size_t size_x = m_pmap->mapSizeX(); + size_t size_y = m_pmap->mapSizeY(); + setMaximumSize(size_x*CELL_SIZE, size_y*CELL_SIZE+50); + ui->label_2->move(10,CELL_SIZE*size_x+10); + ui->difficulty->move(60,CELL_SIZE*size_x+10); + ui->startButton->move(100,CELL_SIZE*size_x+10); + ui->restartButton->move(160,CELL_SIZE*size_x+10); + ui->label->move(270,CELL_SIZE*size_x+10); + ui->ScoreBox->move(340,CELL_SIZE*size_x+10); +} + +void Pacman::updateGame() +{ + if(m_keyIsPressed || !m_isUpdated) + switch (m_key) + { + case Qt::Key_Right: + m_pacman->move(1,0); + break; + case Qt::Key_Left: + m_pacman->move(-1,0); + break; + case Qt::Key_Up: + m_pacman->move(0,1); + break; + case Qt::Key_Down: + m_pacman->move(0,-1); + break; + default: break; + } + m_isUpdated = true; + m_pacman->drawCreature(m_pacman->rotateFaceDirection(m_key)); + + //monster behaviour logic + Point temp , pacmanPoint; + + std::vector > nextPoints; //results of next points + pacmanPoint = m_pacman->getPosition(); + + if(m_count) + { + for(size_t i=0; i < m_monsters.size(); ++i) + nextPoints.push_back( m_pool.enqueue( &Monster_creature::persuitPacman, m_monsters[i], pacmanPoint )); + m_count--; + } + else + { + for(size_t i=0; i < m_monsters.size(); ++i) + { + if(m_monsters[i]->getPosition() == m_monsters[i]->m_movePoint || m_monsters[i]->flag) + { + nextPoints.push_back( m_pool.enqueue( &Monster_creature::persuitPacman, m_monsters[i], pacmanPoint )); + m_monsters[i]->flag = true; + } + else + nextPoints.push_back(m_pool.enqueue( &Monster_creature::persuitPacman, m_monsters[i], m_monsters[i]->m_movePoint )); + } + } + + + for(size_t i=0; i < m_monsters.size(); ++i) + m_monsters[i]->move(nextPoints[i].get() ); + + for(size_t i=0; i < m_monsters.size(); ++i) + m_monsters[i]->drawCreature(); + + + interaction(); + drawMap(); +} + +void Pacman::monsterBehaviourTimer() +{ + m_count = size_t(m_pmap->mapSizeX()*1.8); + for(size_t i = 0; i < m_monsters.size(); ++i) + m_monsters[i]->flag = false; +} + +Pacman::~Pacman() +{ + delete ui; +} + + + + +void Pacman::on_startButton_clicked() +{ + if(m_startPause) + { + m_timer->start(500-m_speed*50); + m_monsterTimer->start(12000); + ui->startButton->setText("PAUSE"); + m_startPause = false; + } + else + { + m_timer->stop(); + m_monsterTimer->stop(); + ui->startButton->setText("START"); + m_startPause = true; + } + +} + +void Pacman::on_difficulty_valueChanged(int arg1) +{ + m_speed = arg1; +} + +void Pacman::on_restartButton_clicked() +{ + m_timer->stop(); + m_monsterTimer->stop(); + m_count = size_t(m_pmap->mapSizeX()*1.4); + m_lostGameFlag = false; + ui->startButton->setDisabled(false); + m_pmap->loadMap(); + + m_monsters.clear(); + size_t tempSize = m_pmap->monstersAmount(); + for(size_t i=0; isetPosition(m_pmap->startPoint()); + + m_score = 0; + ui->ScoreBox->setText(QString::number(m_score,10)); + m_timer->start(500-m_speed*50); + m_monsterTimer->start(12000); +} diff --git a/Pacman/pacman.h b/Pacman/pacman.h new file mode 100644 index 0000000..784b77a --- /dev/null +++ b/Pacman/pacman.h @@ -0,0 +1,69 @@ +#ifndef PACMAN_H +#define PACMAN_H + +#include +#include +#include +#include +#include +#include +#include +#include "ThreadPool.h" + +class GameMap; +class Pacman_creature; +class Monster_creature; + +typedef std::shared_ptr MonsterPtr; +typedef std::shared_ptr PacmanPtr; +typedef std::shared_ptr QLabelPtr; + +namespace Ui { +class Pacman; +} + +class Pacman : public QMainWindow +{ + Q_OBJECT +public: + + explicit Pacman(QWidget *parent = 0); + ~Pacman(); +private: + void drawMap(); + void setLabels(); + void keyPressEvent(QKeyEvent *); + void keyReleaseEvent(QKeyEvent *); + void interaction(); + void setInterface(); +private slots: + void updateGame(); + void monsterBehaviourTimer(); + void on_startButton_clicked(); + void on_difficulty_valueChanged(int arg1); + void on_restartButton_clicked(); + +private: + const size_t CELL_SIZE = 25; + const size_t WIDGET_SIZE_X = 600; + const size_t WIDGET_SIZE_Y = 600; + Ui::Pacman *ui; + std::shared_ptr m_pmap; + std::shared_ptr m_pacman; + std::vector m_monsters; + std::vector > m_mapLabels; + QTimer *m_timer; + QTimer *m_monsterTimer; + size_t m_count; + bool m_keyIsPressed; + bool m_isUpdated; + bool m_startPause; + bool m_lostGameFlag; + Qt::Key m_key; + size_t m_score; + size_t m_speed; + ThreadPool m_pool; + +}; + +#endif // PACMAN_H diff --git a/Pacman/pacman.png b/Pacman/pacman.png new file mode 100644 index 0000000000000000000000000000000000000000..fee9e5b9e3472e1ad19f5270cc2a8aa84ec7fb19 GIT binary patch literal 659 zcmV;E0&M+>P)(_`g8%^e{{R4h=>PzAFaQARU;qF*m;eA5Z<1fd zMgRZ;8A(JzRCwC#o4-!OFc8L_Q`Ci_W7n|28-%Cf>3ACa2C(22sY{WNKuEX)A`QWI zEr||SZ-!pdEGXyEyh-cTF2{P z<*(0=kg|PMxNrOY@5i=M_nyw3+s&pHSnaJ6hr_s?k_4-RrEkOuV=GIgv}l>k#F`Rn zwzBs2hJLMkdOmwk`A3#|`=XTU7Esox{&1bUk=EJp62L!+9%~H4(MDgm*PD*BTBS#5LUjGoeY4< zkVI9(u#(mF^c_+%B}vuuu%`?eF`xlQ0@f0e?2B1vja2)_!Sc4Vnd?A6Sj0#Kjo&Wv z0*(U3?TvW=M}xXcyt(nWj_is;B3Fs@f0CE0e+?Fr4mQ8aNovx=x}j6RO^%ICwpU#c t;8_66z=pvW*_t+MdOhuO232bu2LS5m|1b- + + Pacman + + + + 0 + 0 + 419 + 457 + + + + + 625 + 625 + + + + Qt::NoFocus + + + Pacman + + + + Qt::NoFocus + + + + + 270 + 390 + 61 + 21 + + + + + Showcard Gothic + 12 + 75 + true + false + + + + SCORE: + + + + + + 340 + 390 + 51 + 21 + + + + + Showcard Gothic + 12 + 75 + true + + + + + + + + + + 100 + 390 + 51 + 23 + + + + + Showcard Gothic + 10 + 75 + true + + + + Qt::NoFocus + + + START + + + + + + 60 + 390 + 31 + 31 + + + + + Showcard Gothic + 12 + 75 + true + + + + Qt::NoFocus + + + + + + 1 + + + 6 + + + 3 + + + + + + 10 + 390 + 46 + 31 + + + + + Showcard Gothic + 10 + 75 + true + + + + SPEED + + + + + + 160 + 390 + 71 + 23 + + + + + Showcard Gothic + 10 + 75 + true + + + + Qt::NoFocus + + + RESTART + + + + + + + + diff --git a/Pacman/pacman_creature.cpp b/Pacman/pacman_creature.cpp new file mode 100644 index 0000000..2baf196 --- /dev/null +++ b/Pacman/pacman_creature.cpp @@ -0,0 +1,38 @@ +#include "pacman_creature.h" + + +Pacman_creature::Pacman_creature(GameMapPtr pmap, QPixmap image, QWidget* parent) + : Creature(pmap, image , parent ) +{ + m_x = m_pmap->startPoint().x; + m_y = m_pmap->startPoint().y; +} + +QPixmap Pacman_creature::rotateFaceDirection(Qt::Key key) +{ + QTransform transform; + QPixmap tempPixmap(m_creature_image); + switch (key) + { + case Qt::Key_Left: + transform.rotate(180); + tempPixmap = tempPixmap.transformed(transform); + break; + case Qt::Key_Up: + transform.rotate(-90); + tempPixmap = tempPixmap.transformed(transform); + break; + case Qt::Key_Down: + transform.rotate(90); + tempPixmap = tempPixmap.transformed(transform); + break; + default: break; + } + return tempPixmap; +} + +void Pacman_creature::drawCreature(QPixmap image) +{ + m_label->setPixmap(image); + m_label->move(m_x*CELL_SIZE, m_y*CELL_SIZE); +} diff --git a/Pacman/pacman_creature.h b/Pacman/pacman_creature.h new file mode 100644 index 0000000..89701ed --- /dev/null +++ b/Pacman/pacman_creature.h @@ -0,0 +1,17 @@ +#ifndef PACMAN_CREATURE_H +#define PACMAN_CREATURE_H +#include "creature.h" + + + + +class Pacman_creature: public Creature +{ +public: + Pacman_creature(GameMapPtr pmap, QPixmap image, QWidget* parent ); + QPixmap rotateFaceDirection(Qt::Key); + virtual void drawCreature(QPixmap);//draws rotated face pixmap + virtual ~Pacman_creature(){} +}; + +#endif // PACMAN_CREATURE_H diff --git a/Pacman/wall.png b/Pacman/wall.png new file mode 100644 index 0000000000000000000000000000000000000000..6beff2542feeed7efcc5858f6876751e7fdf9789 GIT binary patch literal 173 zcmeAS@N?(olHy`uVBq!ia0vp^k|4~%1SGw?g-n1HOS+@4BLl<6e(pbstUx|zfk$L9 z0|Vb75M~tB@M-`G`g^)KhIn{CJ!#0tpup2`;NSntR)^i*JZtU!d9srGOV)yL=Dkuc pt~#t|t1`W?x-pIypHSJ^n1sOX;ak>l+yWZS;OXk;vd$@?2>{pyI#>Vz literal 0 HcmV?d00001 From 49db387d5c11c19296e4b4a6db006a80fba5a20f Mon Sep 17 00:00:00 2001 From: marvel16 Date: Fri, 1 Aug 2014 07:57:19 +0300 Subject: [PATCH 5/5] commit --- Polyline/Polyline.cpp | 4 +- Polyline/Polyline.h | 174 +++++++++++++++++++++++++++++++----------- 2 files changed, 130 insertions(+), 48 deletions(-) diff --git a/Polyline/Polyline.cpp b/Polyline/Polyline.cpp index 0041172..591bd77 100644 --- a/Polyline/Polyline.cpp +++ b/Polyline/Polyline.cpp @@ -16,11 +16,9 @@ int _tmain(int argc, _TCHAR* argv[]) Points points; Handler handle; handle.InputPoints(points); - handle.InitGraph(points); - handle.ShowInput(points); handle.cycle(points); handle.ShowCrossPoints(); - + handle.fillNode(); system("pause"); return 0; } diff --git a/Polyline/Polyline.h b/Polyline/Polyline.h index c4edb42..2f59665 100644 --- a/Polyline/Polyline.h +++ b/Polyline/Polyline.h @@ -9,24 +9,54 @@ using namespace std; typedef vector>> Graph; typedef std::vector> Points; +struct Node +{ + double x; + double y; + vector pNodes; + + Node() : x(0), y(0) {} + bool operator==(pair pr) + { + return abs(pr.first-x) pr) + { + x=pr.first; + y=pr.second; + return *this; + } + + + friend ostream& operator<<(ostream& os, Node obj) + { + os << "("<< obj.x <<"," << obj.y << ") "; + return os; + } + +}; + //class that handles vector of entered points class Handler { int size; // number of points Points crossPts; // vector of cross points for all segments - Graph graph; - + Graph graph; // Nodes with connections to other nodes + vector node; public: - Handler::Handler() {} - void InitGraph(const Points& obj); + Handler() {} void InputPoints(Points & obj); void ShowInput(const Points & obj) const; - friend ostream& operator<<(ostream& os, const pair & obj); - void crossPoint(const Points& obj, int s1, int s2, int s3, int s4); + void FindCrossPoint(const Points& obj, int s1, int s2, int s3, int s4); void ShowCrossPoints() const; void cycle(const Points& obj); - // func to compare doubles - + void showGraph() const; + void findNeibours(const Points& obj, int s1 , int s2); + void fillNode(); + void findFigure(); + friend ostream& operator<<(ostream& os, const pair & obj); + friend ostream& operator<<(ostream& os, const vector> & obj); }; bool myfunction (pair i, pair j) @@ -39,26 +69,6 @@ bool pairComp(pair i, pair j) else return i.first < j.first; } - -void Handler::InitGraph(const Points& obj) -{ - graph.resize(obj.size()); - graph[0].push_back(obj[0]); - graph[0].push_back(obj[obj.size()-1]); - graph[0].push_back(obj[1]); - - graph[obj.size()-1].push_back(obj[obj.size()-1]); - graph[obj.size()-1].push_back(obj[obj.size()-2]); - graph[obj.size()-1].push_back(obj[0]); - - for(int i=1; i < obj.size()-2; i++) - { - graph[i].push_back(obj[i]); - graph[i].push_back(obj[i+1]); - graph[i].push_back(obj[i-1]); - } -} - //user input-point-function void Handler::InputPoints(Points & obj) { @@ -87,9 +97,18 @@ ostream& operator<<(ostream& os,const pair & obj) os << "(" << obj.first << "," << obj.second << ") "; return os; } - -// looking for cross point of 2 segments and pushing into vector of points -void Handler::crossPoint(const Points& obj, int s1 , int s2, int s3, int s4) + +ostream& operator<<(ostream& os, const vector> & obj) +{ + int i=1; + for(Points::const_iterator it = obj.begin(); it != obj.end();++it,++i) + os << "(" << (*it).first << "," << (*it).second << ") ;"; + return os; +} + + +// looking for cross point of 2 segments and pushing into vector of cross points +void Handler::FindCrossPoint(const Points& obj, int s1 , int s2, int s3, int s4) { double a1,a2,b1,b2,c1,c2; //coefs double x,y; //cross point coordinates @@ -101,7 +120,8 @@ void Handler::crossPoint(const Points& obj, int s1 , int s2, int s3, int s4) c1 = obj[s1].first * obj[s2].second - obj[s2].first * obj[s1].second; c2 = obj[s3].first * obj[s4].second - obj[s4].first * obj[s3].second; - if( abs(a1-a2) < EPS && abs(b1-b2) < EPS ) return; // paralel no points + if( abs(a1-a2) < EPS && abs(b1-b2) < EPS ) + return; // paralel no points, even if segments have conjunction that point wont matter x = ( b1*c2 - b2*c1 ) / (a1*b2-a2*b1); y = (a2*c1 - a1*c2) / (a1*b2 - a2*b1); @@ -111,17 +131,8 @@ void Handler::crossPoint(const Points& obj, int s1 , int s2, int s3, int s4) && x <= max(obj[s3].first, obj[s4].first) && x >= min(obj[s3].first, obj[s4].first) && y <= max(obj[s1].second, obj[s2].second) && y >= min(obj[s1].second, obj[s2].second) && y <= max(obj[s3].second, obj[s4].second) && y >= min(obj[s3].second, obj[s4].second)) - { crossPts.push_back(make_pair(x,y)); - vector > point_vector; - graph.push_back(point_vector); - graph[graph.size()-1].push_back(make_pair(x,y));//push_back(make_pair(x,y)); - graph[graph.size()-1].push_back(make_pair(obj[s1].first,obj[s1].second)); - graph[graph.size()-1].push_back(make_pair(obj[s2].first,obj[s2].second)); - graph[graph.size()-1].push_back(make_pair(obj[s3].first,obj[s3].second)); - graph[graph.size()-1].push_back(make_pair(obj[s4].first,obj[s4].second)); - } - + } void Handler::ShowCrossPoints() const @@ -135,13 +146,86 @@ void Handler::ShowCrossPoints() const void Handler::cycle(const Points& obj) { for(int i=0; i indexCrossPts; // index for relation between CrossPts and tempVec: crossPts[indexCrossPts[i]] == tempVec[i]; + for(int i=0; i= min(obj[s1].first, obj[s2].first) + && crossPts[i].second <= max(obj[s1].second, obj[s2].second) + && crossPts[i].second >= min(obj[s1].second, obj[s2].second) ) + { + tempVec.push_back(make_pair(crossPts[i].first,crossPts[i].second)); + indexCrossPts.push_back(i);//index in crossPts is value of indexCrossPts + } + + for(int i=0; i