Changeset bc70282 in network-game for client/Client


Ignore:
Timestamp:
Jul 27, 2013, 5:58:33 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
297682c
Parents:
c4c2a3c
Message:

The chat console resets when the user logs out

Location:
client/Client
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • client/Client/chat.cpp

    rc4c2a3c rbc70282  
    2828{
    2929   vctChat.push_back(s);
     30}
     31
     32void chat::clear() {
     33   vctChat.clear();
    3034}
    3135
  • client/Client/chat.h

    rc4c2a3c rbc70282  
    2323   void draw(ALLEGRO_FONT *font, ALLEGRO_COLOR color);
    2424   void addLine(string s);
     25   void clear();
    2526
    2627   bool handleEvent(ALLEGRO_EVENT e);
  • client/Client/main.cpp

    rc4c2a3c rbc70282  
    395395         wndCurrent->draw(display);
    396396
    397          chatConsole.draw(font, al_map_rgb(255,255,255));
    398 
    399397         if(wndCurrent == wndMain) {
     398            chatConsole.draw(font, al_map_rgb(255,255,255));
     399
    400400            al_draw_text(font, al_map_rgb(0, 255, 0), 4, 43, ALLEGRO_ALIGN_LEFT, "Message:");
    401401
     
    558558               break;
    559559            }
     560            default:
     561            {
     562               cout << "(STATE_REGISTER) Received invalid message of type " << msg.type << endl;
     563               break;
     564            }
     565         }
     566
     567         break;
     568      }
     569      case STATE_LOGIN:
     570      {
     571         switch(msg.type)
     572         {
    560573            case MSG_TYPE_LOGIN:
    561574            {
    562575               if (response.compare("Player has already logged in.") == 0)
    563576               {
    564                   username.clear();
    565                   cout << "User login failed" << endl;
     577                  goToLoginScreen();
     578                  state = STATE_START;
     579
    566580                  lblLoginStatus->setText(response);
    567581               }
    568582               else if (response.compare("Incorrect username or password") == 0)
    569583               {
    570                   username.clear();
    571                   cout << "User login failed" << endl;
     584                  goToLoginScreen();
     585                  state = STATE_START;
     586
    572587                  lblLoginStatus->setText(response);
    573588               }
    574589               else
    575590               {
    576                   state = STATE_LOGIN;
    577591                  wndCurrent = wndMain;
    578592                 
     
    585599                  cout << "Player id: " << curPlayerId << endl;
    586600                  cout << "Player health: " << p.health << endl;
    587                   cout << "map size: " << mapPlayers.size() << endl;
     601                  cout << "player map size: " << mapPlayers.size() << endl;
    588602               }
    589 
    590                break;
    591             }
    592             case MSG_TYPE_PLAYER:
    593             {
    594                Player p("", "");
    595                p.deserialize(msg.buffer);
    596                p.timeLastUpdated = getCurrentMillis();
    597 
    598                mapPlayers[p.id] = p;
    599 
    600                break;
    601             }
    602             case MSG_TYPE_OBJECT:
    603             {
    604                WorldMap::Object o(0, WorldMap::OBJECT_NONE, 0, 0);
    605                o.deserialize(msg.buffer);
    606                cout << "object id: " << o.id << endl;
    607                gameMap->updateObject(o.id, o.type, o.pos.x, o.pos.y);
    608 
    609                break;
    610             }
    611             default:
    612             {
    613                cout << "(STATE_REGISTER) Received invlaid message of type " << msg.type << endl;
    614                break;
    615             }
    616          }
    617 
    618          break;
    619       }
    620       case STATE_LOGIN:
    621       {
    622          switch(msg.type)
    623          {
    624             case MSG_TYPE_LOGIN:
    625             {
    626                cout << "Got a login message" << endl;
    627                
    628                chatConsole.addLine(response);
    629                cout << "Added new line" << endl;
    630603
    631604               break;
     
    639612                  cout << "Logged out" << endl;
    640613                  state = STATE_START;
     614                  chatConsole.clear();
    641615                  goToLoginScreen();
    642616               }
     
    657631                  p.isDead = false;
    658632
    659                cout << mapPlayers[p.id].pos.x << ", " << mapPlayers[p.id].pos.y << endl;
    660                cout << "health:" << mapPlayers[p.id].health << endl;
    661                cout << "is dead?:" << mapPlayers[p.id].isDead << endl;
    662633               mapPlayers[p.id] = p;
    663                cout << mapPlayers[p.id].pos.x << ", " << mapPlayers[p.id].pos.y << endl;
    664                cout << "health:" << mapPlayers[p.id].health << endl;
    665                cout << "is dead?:" << mapPlayers[p.id].isDead << endl;
    666634
    667635               break;
     
    693661               WorldMap::Object o(0, WorldMap::OBJECT_NONE, 0, 0);
    694662               o.deserialize(msg.buffer);
     663               cout << "object id: " << o.id << endl;
    695664               gameMap->updateObject(o.id, o.type, o.pos.x, o.pos.y);
    696665
     
    925894}
    926895
     896// maybe need a goToGameScreen function as well and add state changes to these functions as well
     897
    927898void registerAccount()
    928899{
     
    973944
    974945   msgProcessor.sendMessage(&msgTo, sock, &server);
     946
     947   state = STATE_LOGIN;
    975948}
    976949
Note: See TracChangeset for help on using the changeset viewer.