Changeset b8abc90 in network-game for client/Client


Ignore:
Timestamp:
Dec 21, 2013, 7:17:02 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
483a2cb
Parents:
ffadc8e
Message:

Client sends a START_ATTACK message when a player right-clicks on another player in an individual game and processes START_ATTACK messages in individual games

File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    rffadc8e rb8abc90  
    417417                  cout << "Invalid point: User did not click on the map" << endl;
    418418            }else if (ev.mouse.button == 2) {   // right click
    419                   map<unsigned int, Player*>::iterator it;
    420 
    421                   cout << "Detected a right-click" << endl;
    422 
    423                   Player* curPlayer;
    424                   for(it = mapPlayers.begin(); it != mapPlayers.end(); it++)
     419               cout << "Detected a right-click" << endl;
     420               map<unsigned int, Player*>::iterator it;
     421
     422               Player* curPlayer;
     423               for(it = mapPlayers.begin(); it != mapPlayers.end(); it++)
     424               {
     425                  if (it->second->id == curPlayerId)
     426                     curPlayer = it->second;
     427               }
     428
     429               cout << "Got current player" << endl;
     430               cout << "current game: " << game << endl;
     431
     432               map<unsigned int, Player*> playersInGame = game->getPlayers();
     433               Player* target;
     434
     435               for(it = playersInGame.begin(); it != playersInGame.end(); it++)
     436               {
     437                  // need to check if the right-click was actually on this player
     438                  // right now, this code will target all players other than the current one
     439                  target = it->second;
     440                  cout << "set target" << endl;
     441                  if (target->id != curPlayerId && target->team != curPlayer->team)
    425442                  {
    426                      if (it->second->id == curPlayerId)
    427                         curPlayer = it->second;
     443                     cout << "Found valid target" << endl;
     444
     445                     msgTo.type = MSG_TYPE_START_ATTACK;
     446                     memcpy(msgTo.buffer, &curPlayerId, 4);
     447                     memcpy(msgTo.buffer+4, &target->id, 4);
     448
     449                     msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);
    428450                  }
    429 
    430                   Player* target;
    431                   for(it = mapPlayers.begin(); it != mapPlayers.end(); it++)
    432                   {
    433                      // need to check if the right-click was actually on this player
    434                      // right now, this code will target all players other than the current one
    435                      target = it->second;
    436                      if (target->id != curPlayerId && target->team != curPlayer->team)
    437                      {
    438                         msgTo.type = MSG_TYPE_START_ATTACK;
    439                         memcpy(msgTo.buffer, &curPlayerId, 4);
    440                         memcpy(msgTo.buffer+4, &target->id, 4);
    441 
    442                         msgProcessor.sendMessage(&msgTo, sock, &server, &outputLog);
    443                      }
    444                   }
     451               }
    445452            }
    446453         }
     
    10531060               cout << "Processed SCORE message!" << endl;
    10541061 
     1062               break;
     1063            }
     1064            case MSG_TYPE_ATTACK:
     1065            {
     1066               cout << "Received ATTACK message" << endl;
     1067
     1068               break;
     1069            }
     1070            case MSG_TYPE_START_ATTACK:
     1071            {
     1072               cout << "Received START_ATTACK message" << endl;
     1073
     1074               unsigned int id, targetId;
     1075               memcpy(&id, msg.buffer, 4);
     1076               memcpy(&targetId, msg.buffer+4, 4);
     1077
     1078               cout << "source id: " << id << endl;
     1079               cout << "target id: " << targetId << endl;
     1080
     1081               // need to check the target exists in the current game
     1082               Player* source = game->getPlayers()[id];
     1083               source->targetPlayer = targetId;
     1084               source->isChasing = true;
     1085
    10551086               break;
    10561087            }
Note: See TracChangeset for help on using the changeset viewer.