Changeset 1785314 in network-game


Ignore:
Timestamp:
Sep 24, 2013, 12:31:56 AM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
b72ed16
Parents:
c044a36
Message:

Added a lobby screen to the client where players will create and join games

Location:
client/Client
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • client/Client/Client.vcxproj

    rc044a36 r1785314  
    6868  <ItemGroup>
    6969    <ClCompile Include="..\..\common\Common.cpp" />
     70    <ClCompile Include="..\..\common\Game.cpp" />
    7071    <ClCompile Include="..\..\common\MessageContainer.cpp" />
    7172    <ClCompile Include="..\..\common\MessageProcessor.cpp" />
     
    8586    <ClInclude Include="..\..\common\Common.h" />
    8687    <ClInclude Include="..\..\common\Compiler.h" />
     88    <ClInclude Include="..\..\common\Game.h" />
    8789    <ClInclude Include="..\..\common\MessageContainer.h" />
    8890    <ClInclude Include="..\..\common\MessageProcessor.h" />
  • client/Client/Client.vcxproj.filters

    rc044a36 r1785314  
    7070      <Filter>Source Files\common</Filter>
    7171    </ClCompile>
     72    <ClCompile Include="..\..\common\Game.cpp">
     73      <Filter>Source Files\common</Filter>
     74    </ClCompile>
    7275  </ItemGroup>
    7376  <ItemGroup>
     
    114117      <Filter>Header Files\common</Filter>
    115118    </ClInclude>
     119    <ClInclude Include="..\..\common\Game.h">
     120      <Filter>Header Files\common</Filter>
     121    </ClInclude>
    116122  </ItemGroup>
    117123  <ItemGroup>
  • client/Client/main.cpp

    rc044a36 r1785314  
    7676enum STATE {
    7777   STATE_START,
    78    STATE_LOGIN // this means you're already logged in
     78   STATE_LOBBY,
     79   STATE_GAME
    7980};
    8081
     
    8586Window* wndLogin;
    8687Window* wndRegister;
    87 Window* wndMain;
    88 Window* wndMainDebug;
     88Window* wndLobby;
     89Window* wndGame;
     90Window* wndGameDebug;
    8991Window* wndCurrent;
    9092
     
    100102TextLabel* lblRegisterStatus;
    101103
    102 // wndMain
     104// wndGame
    103105Textbox* txtChat;
    104106
     
    238240   cout << "Created register screen" << endl;
    239241
    240    wndMain = new Window(0, 0, SCREEN_W, SCREEN_H);
    241    wndMain->addComponent(new Textbox(95, 40, 300, 20, font));
    242    wndMain->addComponent(new Button(95, 70, 60, 20, font, "Send", sendChatMessage));
    243    wndMain->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging));
    244    wndMain->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout));
    245 
    246    txtChat = (Textbox*)wndMain->getComponent(0);
    247 
    248    wndMainDebug = new Window(0, 0, SCREEN_W, SCREEN_H);
    249    wndMainDebug->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging));
    250    wndMainDebug->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout));
    251 
    252    cout << "Created main screen" << endl;
     242   wndLobby = new Window(0, 0, SCREEN_W, SCREEN_H);
     243
     244   cout << "Created lobby screen" << endl;
     245
     246   wndGame = new Window(0, 0, SCREEN_W, SCREEN_H);
     247   wndGame->addComponent(new Textbox(95, 40, 300, 20, font));
     248   wndGame->addComponent(new Button(95, 70, 60, 20, font, "Send", sendChatMessage));
     249   wndGame->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging));
     250   wndGame->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout));
     251
     252   txtChat = (Textbox*)wndGame->getComponent(0);
     253
     254   wndGameDebug = new Window(0, 0, SCREEN_W, SCREEN_H);
     255   wndGameDebug->addComponent(new Button(20, 10, 160, 20, font, "Toggle Debugging", toggleDebugging));
     256   wndGameDebug->addComponent(new Button(920, 10, 80, 20, font, "Logout", logout));
     257
     258   cout << "Created game screen" << endl;
    253259
    254260   goToLoginScreen();
     
    319325               break;
    320326            case ALLEGRO_KEY_S:  // pickup an item next to you
    321                if (state == STATE_LOGIN) {
     327               if (state == STATE_LOBBY) {
    322328                  msgTo.type = MSG_TYPE_PICKUP_FLAG;
    323329                  memcpy(msgTo.buffer, &curPlayerId, 4);
     
    326332               break;
    327333            case ALLEGRO_KEY_D:  // drop the current item
    328                if (state == STATE_LOGIN) {
     334               if (state == STATE_LOBBY) {
    329335                  // find the current player in the player list
    330336                  map<unsigned int, Player>::iterator it;
     
    355361      }
    356362      else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
    357          if(wndCurrent == wndMain) {
     363         if(wndCurrent == wndLobby) {
     364            if (ev.mouse.button == 1) { // left click
     365               state = STATE_GAME;
     366               wndCurrent = wndGame;
     367            }
     368         }else if(wndCurrent == wndGame) {
    358369            if (ev.mouse.button == 1) {   // left click
    359370               msgTo.type = MSG_TYPE_PLAYER_MOVE;
     
    414425         //msgProcessor.cleanAckedMessages(&outputLog);
    415426
    416          if (debugging && wndCurrent == wndMain)
    417             wndMainDebug->draw(display);
     427         if (debugging && wndCurrent == wndGame)
     428            wndGameDebug->draw(display);
    418429         else
    419430            wndCurrent->draw(display);
    420431
    421          if(wndCurrent == wndMain) {
     432         if(wndCurrent == wndGame) {
    422433            if (!debugging)
    423434               chatConsole.draw(font, al_map_rgb(255,255,255));
     
    494505   
    495506   delete wndLogin;
    496    delete wndMain;
     507   delete wndRegister;
     508   delete wndLobby;
     509   delete wndGame;
     510   delete wndGameDebug;
    497511
    498512   delete gameMap;
     
    600614         break;
    601615      }
    602       case STATE_LOGIN:
     616      case STATE_LOBBY:
     617      case STATE_GAME:
    603618      {
    604619         switch(msg.type)
     
    622637               else
    623638               {
    624                   wndCurrent = wndMain;
     639                  wndCurrent = wndLobby;
    625640                 
    626641                  Player p("", "");
     
    689704            case MSG_TYPE_OBJECT:
    690705            {
    691                cout << "Received object message in STATE_LOGIN." << endl;
     706               cout << "Received object message in STATE_LOBBY." << endl;
    692707
    693708               WorldMap::Object o(0, WorldMap::OBJECT_NONE, 0, 0);
     
    779794            default:
    780795            {
    781                cout << "(STATE_LOGIN) Received invlaid message of type " << msg.type << endl;
     796               cout << "(STATE_LOBBY) Received invlaid message of type " << msg.type << endl;
    782797               break;
    783798            }
     
    977992   msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);
    978993
    979    state = STATE_LOGIN;
     994   state = STATE_LOBBY;
    980995}
    981996
Note: See TracChangeset for help on using the changeset viewer.