Changeset b29ff6b in network-game for client/Client
- Timestamp:
- Jan 26, 2014, 10:22:41 PM (11 years ago)
- Branches:
- master
- Children:
- 11ad6fb
- Parents:
- c991530
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
rc991530 rb29ff6b 57 57 void initWinSock(); 58 58 void shutdownWinSock(); 59 void createGui(ALLEGRO_FONT* font); 59 60 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId); 60 61 int getRefreshRate(int width, int height); … … 162 163 al_init_ttf_addon(); 163 164 165 ALLEGRO_FONT* font; 164 166 #if defined WINDOWS 165 ALLEGRO_FONT *font = al_load_ttf_font("../pirulen.ttf", 12, 0);167 font = al_load_ttf_font("../pirulen.ttf", 12, 0); 166 168 #elif defined LINUX 167 ALLEGRO_FONT *font = al_load_ttf_font("pirulen.ttf", 12, 0);169 font = al_load_ttf_font("pirulen.ttf", 12, 0); 168 170 #endif 169 171 … … 206 208 debugConsole.addLine(""); 207 209 208 wndLogin = new Window(0, 0, SCREEN_W, SCREEN_H); 209 vctComponents.push_back(wndLogin->addComponent(new Textbox(516, 40, 100, 20, font))); 210 vctComponents.push_back(wndLogin->addComponent(new Textbox(516, 70, 100, 20, font))); 211 vctComponents.push_back(wndLogin->addComponent(new TextLabel(410, 40, 100, 20, font, "Username:", ALLEGRO_ALIGN_RIGHT))); 212 vctComponents.push_back(wndLogin->addComponent(new TextLabel(410, 70, 100, 20, font, "Password:", ALLEGRO_ALIGN_RIGHT))); 213 vctComponents.push_back(wndLogin->addComponent(new TextLabel((SCREEN_W-600)/2, 100, 600, 20, font, "", ALLEGRO_ALIGN_CENTRE))); 214 vctComponents.push_back(wndLogin->addComponent(new Button(SCREEN_W/2-100, 130, 90, 20, font, "Register", goToRegisterScreen))); 215 vctComponents.push_back(wndLogin->addComponent(new Button(SCREEN_W/2+10, 130, 90, 20, font, "Login", login))); 216 vctComponents.push_back(wndLogin->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit))); 217 vctComponents.push_back(wndLogin->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging))); 218 219 txtUsername = (Textbox*)wndLogin->getComponent(0); 220 txtPassword = (Textbox*)wndLogin->getComponent(1); 221 lblLoginStatus = (TextLabel*)wndLogin->getComponent(4); 222 223 cout << "Created login screen" << endl; 224 225 wndRegister = new Window(0, 0, SCREEN_W, SCREEN_H); 226 vctComponents.push_back(wndRegister->addComponent(new Textbox(516, 40, 100, 20, font))); 227 vctComponents.push_back(wndRegister->addComponent(new Textbox(516, 70, 100, 20, font))); 228 vctComponents.push_back(wndRegister->addComponent(new TextLabel(410, 40, 100, 20, font, "Username:", ALLEGRO_ALIGN_RIGHT))); 229 vctComponents.push_back(wndRegister->addComponent(new TextLabel(410, 70, 100, 20, font, "Password:", ALLEGRO_ALIGN_RIGHT))); 230 vctComponents.push_back(wndRegister->addComponent(new RadioButtonList(432, 100, "Pick a class", font))); 231 vctComponents.push_back(wndRegister->addComponent(new TextLabel((SCREEN_W-600)/2, 190, 600, 20, font, "", ALLEGRO_ALIGN_CENTRE))); 232 vctComponents.push_back(wndRegister->addComponent(new Button(SCREEN_W/2-100, 220, 90, 20, font, "Back", goToLoginScreen))); 233 vctComponents.push_back(wndRegister->addComponent(new Button(SCREEN_W/2+10, 220, 90, 20, font, "Submit", registerAccount))); 234 vctComponents.push_back(wndRegister->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit))); 235 vctComponents.push_back(wndRegister->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging))); 236 237 txtUsernameRegister = (Textbox*)wndRegister->getComponent(0); 238 txtPasswordRegister = (Textbox*)wndRegister->getComponent(1); 239 240 rblClasses = (RadioButtonList*)wndRegister->getComponent(4); 241 rblClasses->addRadioButton("Warrior"); 242 rblClasses->addRadioButton("Ranger"); 243 244 lblRegisterStatus = (TextLabel*)wndRegister->getComponent(5); 245 246 cout << "Created register screen" << endl; 247 248 txtJoinGame = new Textbox(SCREEN_W*1/2+15+4, 40, 100, 20, font); 249 txtCreateGame = new Textbox(SCREEN_W*3/4+4, 40, 100, 20, font); 250 251 vctComponents.push_back(txtJoinGame); 252 vctComponents.push_back(txtCreateGame); 253 254 wndLobby = new Window(0, 0, SCREEN_W, SCREEN_H); 255 vctComponents.push_back(wndLobby->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout))); 256 vctComponents.push_back(wndLobby->addComponent(new TextLabel(SCREEN_W*1/2+15-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT))); 257 wndLobby->addComponent(txtJoinGame); 258 vctComponents.push_back(wndLobby->addComponent(new Button(SCREEN_W*1/2+15-100, 80, 200, 20, font, "Join Existing Game", joinGame))); 259 vctComponents.push_back(wndLobby->addComponent(new TextLabel(SCREEN_W*3/4-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT))); 260 wndLobby->addComponent(txtCreateGame); 261 vctComponents.push_back(wndLobby->addComponent(new Button(SCREEN_W*3/4-100, 80, 200, 20, font, "Create New Game", createGame))); 262 vctComponents.push_back(wndLobby->addComponent(new Textbox(95, 40, 300, 20, font))); 263 vctComponents.push_back(wndLobby->addComponent(new Button(95, 70, 60, 20, font, "Send", sendChatMessage))); 264 vctComponents.push_back(wndLobby->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging))); 265 266 267 txtChat = (Textbox*)wndLobby->getComponent(7); 268 269 cout << "Created lobby screen" << endl; 270 271 wndLobbyDebug = new Window(0, 0, SCREEN_W, SCREEN_H); 272 vctComponents.push_back(wndLobbyDebug->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout))); 273 vctComponents.push_back(wndLobbyDebug->addComponent(new TextLabel(SCREEN_W*1/2+15-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT))); 274 wndLobbyDebug->addComponent(txtJoinGame); 275 vctComponents.push_back(wndLobbyDebug->addComponent(new Button(SCREEN_W*1/2+15-100, 80, 200, 20, font, "Join Existing Game", joinGame))); 276 vctComponents.push_back(wndLobbyDebug->addComponent(new TextLabel(SCREEN_W*3/4-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT))); 277 wndLobbyDebug->addComponent(txtCreateGame); 278 vctComponents.push_back(wndLobbyDebug->addComponent(new Button(SCREEN_W*3/4-100, 80, 200, 20, font, "Create New Game", createGame))); 279 vctComponents.push_back(wndLobbyDebug->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging))); 280 281 cout << "Created debug lobby screen" << endl; 282 283 wndGame = new Window(0, 0, SCREEN_W, SCREEN_H); 284 vctComponents.push_back(wndGame->addComponent(new Button(880, 10, 120, 20, font, "Leave Game", leaveGame))); 285 286 cout << "Created new game screen" << endl; 287 288 wndGameSummary = new Window(0, 0, SCREEN_W, SCREEN_H); 289 vctComponents.push_back(wndGameSummary->addComponent(new Button(840, 730, 160, 20, font, "Back to Lobby", closeGameSummary))); 290 291 cout << "Created game summary screen" << endl; 210 createGui(font); 292 211 293 212 goToLoginScreen(); … … 622 541 } 623 542 543 void createGui(ALLEGRO_FONT* font) { 544 // wndLogin 545 546 wndLogin = new Window(0, 0, SCREEN_W, SCREEN_H); 547 vctComponents.push_back(wndLogin->addComponent(new Textbox(516, 40, 100, 20, font))); 548 vctComponents.push_back(wndLogin->addComponent(new Textbox(516, 70, 100, 20, font))); 549 vctComponents.push_back(wndLogin->addComponent(new TextLabel(410, 40, 100, 20, font, "Username:", ALLEGRO_ALIGN_RIGHT))); 550 vctComponents.push_back(wndLogin->addComponent(new TextLabel(410, 70, 100, 20, font, "Password:", ALLEGRO_ALIGN_RIGHT))); 551 vctComponents.push_back(wndLogin->addComponent(new TextLabel((SCREEN_W-600)/2, 100, 600, 20, font, "", ALLEGRO_ALIGN_CENTRE))); 552 vctComponents.push_back(wndLogin->addComponent(new Button(SCREEN_W/2-100, 130, 90, 20, font, "Register", goToRegisterScreen))); 553 vctComponents.push_back(wndLogin->addComponent(new Button(SCREEN_W/2+10, 130, 90, 20, font, "Login", login))); 554 vctComponents.push_back(wndLogin->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit))); 555 vctComponents.push_back(wndLogin->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging))); 556 557 txtUsername = (Textbox*)wndLogin->getComponent(0); 558 txtPassword = (Textbox*)wndLogin->getComponent(1); 559 lblLoginStatus = (TextLabel*)wndLogin->getComponent(4); 560 561 cout << "Created login screen" << endl; 562 563 564 // wndRegister 565 566 wndRegister = new Window(0, 0, SCREEN_W, SCREEN_H); 567 vctComponents.push_back(wndRegister->addComponent(new Textbox(516, 40, 100, 20, font))); 568 vctComponents.push_back(wndRegister->addComponent(new Textbox(516, 70, 100, 20, font))); 569 vctComponents.push_back(wndRegister->addComponent(new TextLabel(410, 40, 100, 20, font, "Username:", ALLEGRO_ALIGN_RIGHT))); 570 vctComponents.push_back(wndRegister->addComponent(new TextLabel(410, 70, 100, 20, font, "Password:", ALLEGRO_ALIGN_RIGHT))); 571 vctComponents.push_back(wndRegister->addComponent(new RadioButtonList(432, 100, "Pick a class", font))); 572 vctComponents.push_back(wndRegister->addComponent(new TextLabel((SCREEN_W-600)/2, 190, 600, 20, font, "", ALLEGRO_ALIGN_CENTRE))); 573 vctComponents.push_back(wndRegister->addComponent(new Button(SCREEN_W/2-100, 220, 90, 20, font, "Back", goToLoginScreen))); 574 vctComponents.push_back(wndRegister->addComponent(new Button(SCREEN_W/2+10, 220, 90, 20, font, "Submit", registerAccount))); 575 vctComponents.push_back(wndRegister->addComponent(new Button(920, 10, 80, 20, font, "Quit", quit))); 576 vctComponents.push_back(wndRegister->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging))); 577 578 txtUsernameRegister = (Textbox*)wndRegister->getComponent(0); 579 txtPasswordRegister = (Textbox*)wndRegister->getComponent(1); 580 581 rblClasses = (RadioButtonList*)wndRegister->getComponent(4); 582 rblClasses->addRadioButton("Warrior"); 583 rblClasses->addRadioButton("Ranger"); 584 585 lblRegisterStatus = (TextLabel*)wndRegister->getComponent(5); 586 587 cout << "Created register screen" << endl; 588 589 590 // wndLobby 591 592 txtJoinGame = new Textbox(SCREEN_W*1/2+15+4, 40, 100, 20, font); 593 vctComponents.push_back(txtJoinGame); 594 595 txtCreateGame = new Textbox(SCREEN_W*3/4+4, 40, 100, 20, font); 596 vctComponents.push_back(txtCreateGame); 597 598 wndLobby = new Window(0, 0, SCREEN_W, SCREEN_H); 599 vctComponents.push_back(wndLobby->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout))); 600 vctComponents.push_back(wndLobby->addComponent(new TextLabel(SCREEN_W*1/2+15-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT))); 601 wndLobby->addComponent(txtJoinGame); 602 vctComponents.push_back(wndLobby->addComponent(new Button(SCREEN_W*1/2+15-100, 80, 200, 20, font, "Join Existing Game", joinGame))); 603 vctComponents.push_back(wndLobby->addComponent(new TextLabel(SCREEN_W*3/4-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT))); 604 wndLobby->addComponent(txtCreateGame); 605 vctComponents.push_back(wndLobby->addComponent(new Button(SCREEN_W*3/4-100, 80, 200, 20, font, "Create New Game", createGame))); 606 vctComponents.push_back(wndLobby->addComponent(new Textbox(95, 40, 300, 20, font))); 607 vctComponents.push_back(wndLobby->addComponent(new Button(95, 70, 60, 20, font, "Send", sendChatMessage))); 608 vctComponents.push_back(wndLobby->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging))); 609 610 txtChat = (Textbox*)wndLobby->getComponent(7); 611 612 cout << "Created lobby screen" << endl; 613 614 615 // wndLobbyDebug 616 617 wndLobbyDebug = new Window(0, 0, SCREEN_W, SCREEN_H); 618 vctComponents.push_back(wndLobbyDebug->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout))); 619 vctComponents.push_back(wndLobbyDebug->addComponent(new TextLabel(SCREEN_W*1/2+15-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT))); 620 wndLobbyDebug->addComponent(txtJoinGame); 621 vctComponents.push_back(wndLobbyDebug->addComponent(new Button(SCREEN_W*1/2+15-100, 80, 200, 20, font, "Join Existing Game", joinGame))); 622 vctComponents.push_back(wndLobbyDebug->addComponent(new TextLabel(SCREEN_W*3/4-112, 40, 110, 20, font, "Game Name:", ALLEGRO_ALIGN_RIGHT))); 623 wndLobbyDebug->addComponent(txtCreateGame); 624 vctComponents.push_back(wndLobbyDebug->addComponent(new Button(SCREEN_W*3/4-100, 80, 200, 20, font, "Create New Game", createGame))); 625 vctComponents.push_back(wndLobbyDebug->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging))); 626 627 cout << "Created debug lobby screen" << endl; 628 629 630 // wndGame 631 632 wndGame = new Window(0, 0, SCREEN_W, SCREEN_H); 633 vctComponents.push_back(wndGame->addComponent(new Button(880, 10, 120, 20, font, "Leave Game", leaveGame))); 634 635 cout << "Created new game screen" << endl; 636 637 wndGameSummary = new Window(0, 0, SCREEN_W, SCREEN_H); 638 vctComponents.push_back(wndGameSummary->addComponent(new Button(840, 730, 160, 20, font, "Back to Lobby", closeGameSummary))); 639 640 cout << "Created game summary screen" << endl; 641 } 642 624 643 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId) 625 644 {
Note:
See TracChangeset
for help on using the changeset viewer.