-
Notifications
You must be signed in to change notification settings - Fork 7
Ilnitsky V. #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marvel16
wants to merge
5
commits into
vitalWord:master
Choose a base branch
from
marvel16:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ilnitsky V. #8
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e251482
push
marvel16 94a2e8c
Output of all points in figure that was created by input point-polyline
marvel16 4c7c25c
update: fixed finding coef for paralell OY segments, excluding repeat…
marvel16 81c7f89
Pacman
marvel16 49db387
commit
marvel16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<sz;i++) | ||
| reverse_string[i]=string[sz-1-i]; | ||
| reverse_string[sz]='\0'; | ||
| std::cout << reverse_string; | ||
| return 0; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 += | ||
|
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <RCC> | ||
| <qresource prefix="/"> | ||
| <file>finish.png</file> | ||
| <file>gold.png</file> | ||
| <file>level1.txt</file> | ||
| <file>level2.txt</file> | ||
| <file>monster.png</file> | ||
| <file>pacman.png</file> | ||
| <file>wall.png</file> | ||
| </qresource> | ||
| </RCC> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| #ifndef THREAD_POOL_H | ||
| #define THREAD_POOL_H | ||
|
|
||
| #include <vector> | ||
| #include <queue> | ||
| #include <memory> | ||
| #include <thread> | ||
| #include <mutex> | ||
| #include <condition_variable> | ||
| #include <future> | ||
| #include <functional> | ||
| #include <stdexcept> | ||
|
|
||
|
|
||
| class ThreadPool { | ||
| public: | ||
| ThreadPool(size_t); | ||
| void joinAll(); | ||
| template<class F, class... Args> | ||
| auto enqueue(F&& f, Args&&... args) | ||
| -> std::future<typename std::result_of<F(Args...)>::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<void()> > 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<threads;++i) | ||
| workers.emplace_back( | ||
| [this] | ||
| { | ||
| for(;;) | ||
| { | ||
| std::unique_lock<std::mutex> lock(this->queue_mutex); | ||
| while(!this->stop && this->tasks.empty()) | ||
| this->condition.wait(lock); | ||
| if(this->stop && this->tasks.empty()) | ||
| return; | ||
| std::function<void()> task(this->tasks.front()); | ||
| this->tasks.pop(); | ||
| lock.unlock(); | ||
| task(); | ||
| } | ||
| } | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| // add new work item to the pool | ||
| template<class F, class... Args> | ||
| auto ThreadPool::enqueue(F&& f, Args&&... args) | ||
| -> std::future<typename std::result_of<F(Args...)>::type> | ||
| { | ||
| typedef typename std::result_of<F(Args...)>::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<return_type()> >( | ||
| std::bind(std::forward<F>(f), std::forward<Args>(args)...) | ||
| ); | ||
|
|
||
| std::future<return_type> res = task->get_future(); | ||
| { | ||
| std::unique_lock<std::mutex> lock(queue_mutex); | ||
| tasks.push([task](){ (*task)(); }); | ||
| } | ||
| condition.notify_one(); | ||
| return res; | ||
| } | ||
|
|
||
| // the destructor joins all threads | ||
| inline ThreadPool::~ThreadPool() | ||
| { | ||
| { | ||
| std::unique_lock<std::mutex> lock(queue_mutex); | ||
| stop = true; | ||
| } | ||
| condition.notify_all(); | ||
| for(size_t i = 0;i<workers.size();++i) | ||
| workers[i].join(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| #include "creature.h" | ||
| #include "gamemap.h" | ||
|
|
||
| Creature::Creature(GameMapPtr pmap,QPixmap image, QWidget* parent ) | ||
| :m_x(0) | ||
| ,m_y(0) | ||
| ,m_pmap(pmap) | ||
| ,m_creature_image(image) | ||
| ,m_label(new QLabel(parent)) | ||
| { | ||
| m_label->setPixmap(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); | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #ifndef CREATURE_H | ||
| #define CREATURE_H | ||
|
|
||
| #include "gamemap.h" | ||
| #include <QPixmap> | ||
| #include <QLabel> | ||
| #include <memory> | ||
|
|
||
| typedef std::shared_ptr<QLabel> 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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Погані лапки