setup louche en console

This commit is contained in:
MarcEricMartel 2023-10-18 09:59:34 -04:00
parent 2cb7d4c776
commit 0e7b8973e7
4 changed files with 27 additions and 25 deletions

View File

@ -69,7 +69,7 @@ int Connector::Connect(char* srv_addr, std::string name) {
buf = new char[150] {0}; buf = new char[150] {0};
buflen = 150; buflen = 150;
int rpack = 0; int rpack = 0;
int errors = 0;
while (rpack < 2) { while (rpack < 2) {
recv(m_sock_tcp, buf, buflen, 0); recv(m_sock_tcp, buf, buflen, 0);
@ -89,9 +89,12 @@ int Connector::Connect(char* srv_addr, std::string name) {
++rpack; ++rpack;
break; break;
default: default:
std::cout << "Packet invalide." << std::endl; ++errors;
//std::cout << "Packet invalide." << std::endl;
break; break;
} }
if (errors > 100)
return 1;
} }
return 0; return 0;
} }

View File

@ -20,7 +20,6 @@
#include <climits> #include <climits>
#endif #endif
#define NETWORK_TEST false
#define SRV_ADDR "127.0.0.1" #define SRV_ADDR "127.0.0.1"
#define COUNTDOWN 300 #define COUNTDOWN 300

View File

@ -265,28 +265,28 @@ void Engine::Init() {
m_whoosh[x] = nullptr; m_whoosh[x] = nullptr;
} }
#ifdef NETWORK_TEST if (true) {
std::cout << "Jouer en ligne? [o/N] "; std::cout << "Jouer en ligne? [o/N] ";
std::cin >> ch; std::cin >> ch;
std::cout << std::endl;
if (ch == 'o' || ch == 'O') {
std::cout << "Veuillez entrer un nom de joueur: ";
std::getline(std::cin, playname);
std::cout << std::endl; std::cout << std::endl;
if (!m_conn.Init()) { if (ch == 'o' || ch == 'O') {
if (!m_conn.Connect(SRV_ADDR, playname)) { std::cout << "Veuillez entrer un nom de joueur: ";
// setup jeu en reseau. std::cin >> playname;
std::cout << "ID recu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl; std::cout << std::endl;
std::cout << "Seed recu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
seed = m_conn.getSeed(); if (!m_conn.Init()) {
if (!m_conn.Connect(SRV_ADDR, playname)) {
// setup jeu en reseau.
std::cout << "ID recu du serveur: " << std::to_string(m_conn.getId()) << "!" << std::endl;
std::cout << "Seed recu du serveur: " << std::to_string(m_conn.getSeed()) << "!" << std::endl;
seed = m_conn.getSeed();
}
else std::cout << "Erreur de connexion." << std::endl;
} }
else std::cout << "Erreur de connexion." << std::endl; else std::cout << "Erreur de creation de socket." << std::endl;
} }
else std::cout << "Erreur de creation de socket." << std::endl;
} }
#endif
m_world.SetSeed(seed); m_world.SetSeed(seed);

View File

@ -82,11 +82,11 @@ private:
//Menu //Menu
enum class GameState { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY }; enum class GameState { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY };
GameState m_gamestate = GameState::MAIN_MENU; GameState m_gamestate = GameState::MAIN_MENU;
Texture MenuTitleTexture; Texture MenuTitleTexture,
Texture MenuBGTexture; MenuBGTexture,
Texture MenuStartTexture; MenuStartTexture,
Texture MenuQuitTexture; MenuQuitTexture,
Texture MenuOptionsTexture; MenuOptionsTexture;
float m_scale; float m_scale;
float m_time = 0; float m_time = 0;