-
Notifications
You must be signed in to change notification settings - Fork 1
Lostmap #2
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
lostmap
wants to merge
4
commits into
master
Choose a base branch
from
lostmap
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
Lostmap #2
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| build/ | ||
| .DS_Store | ||
| .qmake.stash |
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,82 @@ | ||
| # Это комментарий, который говорит, что переменная CC указывает компилятор, используемый для сборки | ||
| CC=g++ -std=c++14 | ||
| #Это еще один комментарий. Он поясняет, что в переменной CFLAGS лежат флаги, которые передаются компилятору | ||
| CFLAGS=-c | ||
| SFML_FLAGS=-lsfml-graphics -lsfml-window -lsfml-system -lsfml-network | ||
|
|
||
| all: card_game | ||
|
|
||
| card_game: abstractcard.o client.o deck.o droparea.o dropspace.o entitycard.o entitywithpropertycard.o field.o game.o info.o interlayer.o log.o main.o mainwindow.o menu.o party.o player.o propertycard.o pugixml.o sfmlcard.o user.o clientparser.o config.o | ||
| $(CC) abstractcard.o client.o deck.o droparea.o dropspace.o entitycard.o entitywithpropertycard.o field.o game.o info.o interlayer.o log.o main.o mainwindow.o menu.o party.o player.o propertycard.o pugixml.o sfmlcard.o user.o clientparser.o config.o -o card_game $(SFML_FLAGS) | ||
|
|
||
| client.o : client.cpp | ||
| $(CC) $(CFLAGS) client.cpp | ||
|
|
||
| abstractcard.o: abstractcard.cpp | ||
| $(CC) $(CFLAGS) abstractcard.cpp | ||
|
|
||
| deck.o : deck.cpp | ||
| $(CC) $(CFLAGS) deck.cpp | ||
|
|
||
| droparea.o : droparea.cpp | ||
| $(CC) $(CFLAGS) droparea.cpp | ||
|
|
||
| dropspace.o : dropspace.cpp | ||
| $(CC) $(CFLAGS) dropspace.cpp | ||
|
|
||
| entitycard.o : entitycard.cpp | ||
| $(CC) $(CFLAGS) entitycard.cpp | ||
|
|
||
| entitywithpropertycard.o : entitywithpropertycard.cpp | ||
| $(CC) $(CFLAGS) entitywithpropertycard.cpp | ||
|
|
||
| field.o : field.cpp | ||
| $(CC) $(CFLAGS) field.cpp | ||
|
|
||
| game.o : game.cpp | ||
| $(CC) $(CFLAGS) game.cpp | ||
|
|
||
| info.o: info.cpp | ||
| $(CC) $(CFLAGS) info.cpp | ||
|
|
||
| interlayer.o : interlayer.cpp | ||
| $(CC) $(CFLAGS) interlayer.cpp | ||
|
|
||
| log.o : log.cpp | ||
| $(CC) $(CFLAGS) log.cpp | ||
|
|
||
| main.o : main.cpp | ||
| $(CC) $(CFLAGS) main.cpp | ||
|
|
||
| mainwindow.o : mainwindow.cpp | ||
| $(CC) $(CFLAGS) mainwindow.cpp | ||
|
|
||
| menu.o : menu.cpp | ||
| $(CC) $(CFLAGS) menu.cpp | ||
|
|
||
| party.o : party.cpp | ||
| $(CC) $(CFLAGS) party.cpp | ||
|
|
||
| player.o : player.cpp | ||
| $(CC) $(CFLAGS) player.cpp | ||
|
|
||
| propertycard.o : propertycard.cpp | ||
| $(CC) $(CFLAGS) propertycard.cpp | ||
|
|
||
| pugixml.o : pugixml.cpp | ||
| $(CC) $(CFLAGS) pugixml.cpp | ||
|
|
||
| sfmlcard.o : sfmlcard.cpp | ||
| $(CC) $(CFLAGS) sfmlcard.cpp | ||
|
|
||
| user.o : user.cpp | ||
| $(CC) $(CFLAGS) user.cpp | ||
|
|
||
| clientparser.o : clientparser.cpp | ||
| $(CC) $(CFLAGS) clientparser.cpp | ||
|
|
||
| config.o : config.cpp | ||
| $(CC) $(CFLAGS) config.cpp | ||
|
|
||
| clean: | ||
| rm -rf *.o card_game |
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,20 @@ | ||
| #include "abstractcard.h" | ||
|
|
||
|
|
||
| AbstractCard::AbstractCard(int id, std::string info, float x, float y, | ||
| Entity_type entity_typy, Property_type property_type): | ||
| SfmlCard(x, y, entity_typy, property_type), | ||
| _id(id), _info(info) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| int AbstractCard::getId() | ||
| { | ||
| return _id; | ||
| } | ||
|
|
||
| std::string AbstractCard::getInfo() | ||
| { | ||
| return _info; | ||
| } |
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,32 @@ | ||
| #ifndef ABSTRACTCARD_H | ||
| #define ABSTRACTCARD_H | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "sfmlcard.h" | ||
| #include "config.h" | ||
|
|
||
| class AbstractCard: public SfmlCard | ||
| { | ||
| public: | ||
| AbstractCard(int id, std::string info, float x, float y, | ||
| Entity_type entity_typy = NO_ENTITY, Property_type property_type = NO_PROPERTY); | ||
|
|
||
| virtual ~AbstractCard() {}; | ||
|
|
||
| int getId(); | ||
| std::string getInfo(); | ||
|
|
||
| virtual Entity_type getEntityType() = 0; | ||
| virtual int getStrength() = 0; | ||
| virtual void setStrength(int) = 0; | ||
| virtual Property_type getPropertyType() = 0; | ||
|
|
||
| virtual void update(float time) = 0; | ||
|
|
||
| private: | ||
| int _id; | ||
| std::string _info; | ||
| }; | ||
|
|
||
| #endif // ABSTRACTCARD_H |
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,96 @@ | ||
| #include "client.h" | ||
|
|
||
| #include "config.h" | ||
| #include "interlayer.h" | ||
| #include "log.h" | ||
|
|
||
| #include <iostream> | ||
|
|
||
| Client::Client():_interLayer(nullptr){ | ||
|
|
||
| sf::Socket::Status status = connect(Config::Instance().ADDRESS, Config::Instance().PORT); | ||
| if (status != sf::Socket::Done) | ||
|
|
||
| Log::Instance().error("couldn't connect to " + Config::Instance().ADDRESS); | ||
| else | ||
| Log::Instance().log("connect to " + Config::Instance().ADDRESS); | ||
|
|
||
| } | ||
|
|
||
| void Client::signUp(std::string login, std::string password) { | ||
| sendSignUp(login, password); | ||
| } | ||
|
|
||
| void Client::signIn(std::string login, std::string password) { | ||
| sendSignIn(login, password); | ||
| } | ||
|
|
||
| Client::~Client(){ | ||
|
|
||
| } | ||
|
|
||
|
|
||
| sf::Socket::Status Client::connect(const std::string ipaddr, unsigned short port){ | ||
| return socket.connect(ipaddr, port); | ||
| } | ||
|
|
||
| sf::Socket::Status Client::sendData(std::string data){ | ||
| return socket.send(data.c_str(), data.size()); | ||
| } | ||
|
|
||
| sf::Socket::Status Client::sendSignIn(std::string login, std::string password){ | ||
| std::string sendData = ("<user><signin><login>" + login + "</login><password>" + password + | ||
| "</password></signin></user>"); | ||
| return socket.send(sendData.c_str(), sendData.size()); | ||
| } | ||
|
|
||
| sf::Socket::Status Client::sendSignUp(std::string login, std::string password){ | ||
| std::string sendData = ("<user><signup><login>" + login + "</login><password>" + password + | ||
| "</password></signup></user>"); | ||
| return socket.send(sendData.c_str(), sendData.size()); | ||
| } | ||
|
|
||
| sf::Socket::Status Client::sendCard(int id){ | ||
| std::string s = "<user><card><id>" + std::to_string(id) + "</id></card></user>"; | ||
| return socket.send(s.c_str(), s.size()); | ||
| } | ||
|
|
||
| sf::Socket::Status Client::sendStart(){ | ||
| std::string s = "<user><start>1</start></user>"; | ||
| return socket.send(s.c_str(), s.size()); | ||
| } | ||
|
|
||
| sf::Socket::Status Client::sendPass(){ | ||
| std::string s = "<user><pass>0</pass></user>"; | ||
| return socket.send(s.c_str(), s.size()); | ||
| } | ||
|
|
||
| std::string Client::getMessage(){ | ||
| socket.setBlocking(false); | ||
| char buffer[BUFFER_LIMIT]; | ||
| std::size_t recieved; | ||
| std::string msg = ""; | ||
| sf::Socket::Status status; | ||
|
|
||
| while(RECEIVE_LIMIT < 256){ | ||
| status = socket.receive(buffer, BUFFER_LIMIT, recieved); | ||
| std::string tmp = std::string(buffer, recieved); | ||
| msg += tmp; | ||
| if(recieved < BUFFER_LIMIT){ | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (msg != "") | ||
| std::cout<<msg<<std::endl; | ||
|
|
||
| socket.setBlocking(true); | ||
| return msg; | ||
| } | ||
|
|
||
|
|
||
| void Client::setInterLayer(std::shared_ptr<InterLayer> interLayer) | ||
| { | ||
| _interLayer = interLayer; | ||
| } | ||
|
|
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,38 @@ | ||
| #ifndef CLIENT_H | ||
| #define CLIENT_H | ||
|
|
||
|
|
||
| class InterLayer; | ||
|
|
||
| #include <SFML/Network.hpp> | ||
| #include <string> | ||
| #include <memory> | ||
|
|
||
| class Client { | ||
|
|
||
| public: | ||
| Client(); | ||
| ~Client(); | ||
| sf::Socket::Status connect(const std::string ipaddr, unsigned short port); | ||
| sf::Socket::Status sendData(std::string data); | ||
| sf::Socket::Status sendSignIn(std::string login, std::string password); | ||
| sf::Socket::Status sendSignUp(std::string login, std::string password); | ||
| sf::Socket::Status sendCard(int id); | ||
| sf::Socket::Status sendStart(); | ||
| sf::Socket::Status sendPass(); | ||
|
|
||
| std::string getMessage(); | ||
| void setInterLayer(std::shared_ptr<InterLayer>); | ||
|
|
||
| void signUp(std::string login, std::string password); | ||
| void signIn(std::string login, std::string password); | ||
|
|
||
|
|
||
| private: | ||
| std::shared_ptr<InterLayer> _interLayer; | ||
| const unsigned short RECEIVE_LIMIT = 255; | ||
| const unsigned short BUFFER_LIMIT = 127; | ||
| sf::TcpSocket socket; | ||
| }; | ||
|
|
||
| #endif // CLIENT_H | ||
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.
привязки на уровне интерфейса к библиотекам реализации быть не должно
нужно делать либо развязку на уровне классов-адаптеров, либо, например, использовать идиому PIMPL