From 09979f1e72ef67798c99d0bb1d778baa4b9ae603 Mon Sep 17 00:00:00 2001 From: mduval76 <9343789@etu.cegepsth.qc.ca> Date: Sat, 9 Dec 2023 00:00:52 -0500 Subject: [PATCH] Push connexion multiplayer. --- SQCSim2021/define.h | 2 +- SQCSim2021/engine.cpp | 43 +++++++------------------------------------ SQCSim2021/engine.h | 1 + 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h index c9b3322..7f99020 100644 --- a/SQCSim2021/define.h +++ b/SQCSim2021/define.h @@ -41,7 +41,7 @@ enum GameState { SPLASH, LOBBY, OPTIONS, - QUIT, + QUIT, PLAY, PAUSE }; diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 4cf9757..011b373 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -576,43 +576,8 @@ int Engine::GetOptionsChoice() { } void Engine::StartMultiplayerGame() { - char* ch = new char[2]; - - //std::cout << "Jouer en ligne? [o/N] "; - //std::cin.getline(ch, 2); - //std::cout << std::endl; - - char* input = new char[32]; - std::string playname, srvname; - - /*if (*ch == 'o' || *ch == 'O') { - char* input = new char[32]; - std::string playname, srvname; - - while (playname.size() < 1) { - std::cout << "Veuillez entrer un nom de joueur: "; - std::cin.getline(input, 32); - std::cout << std::endl; - playname = input; - if (playname.size() < 1 || playname.size() > 32) - std::puts("Nom invalide."); - } - while (srvname.size() < 1) { - std::cout << "Veuillez entrer une adresse de serveur: "; - std::cin.getline(input, 32); - std::cout << std::endl; - srvname = input; - if (srvname.size() < 1 || srvname.size() > 32) - std::puts("Adresse serveur invalide."); - } - delete[] input; - - - } - delete[] ch;*/ - if (!m_conn.Init()) { - if (!m_conn.Connect(srvname.c_str(), playname)) { + if (!m_conn.Connect(m_serverAddr.c_str(), m_username)) { // 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; @@ -1228,6 +1193,10 @@ void Engine::Render(float elapsedTime) { if (m_gamestate == GameState::LOBBY) { DisplayLobbyMenu(elapsedTime); + if (m_multiReady) { + StartMultiplayerGame(); + std::cout << "Starting multiplayer game reached" << std::endl; + } return; } @@ -1910,6 +1879,8 @@ void Engine::HandlePlayerInput(float elapsedTime) { m_serverAddr = m_currentInputString; m_currentInputString = ""; m_settingServer = false; + m_multiReady = true; + m_gamestate = GameState::PLAY; } } m_keyEnter = false; diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 3303a11..d7dc4cc 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -214,6 +214,7 @@ private: bool m_charChanged = false; bool m_settingUsername = false; bool m_settingServer = false; + bool m_multiReady = false; bool m_key1 = false; bool m_key2 = false;