Changes in / [cdb4bec:da692b9] in network-game


Ignore:
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • client/Client/Client.vcxproj

    rcdb4bec rda692b9  
    7373  </ItemGroup>
    7474  <ItemGroup>
    75     <ClInclude Include="..\..\common\Common.h" />
    7675    <ClInclude Include="..\..\common\Compiler.h" />
    7776    <ClInclude Include="..\..\common\Message.h" />
  • client/Client/Client.vcxproj.filters

    rcdb4bec rda692b9  
    7272      <Filter>Header Files\common</Filter>
    7373    </ClInclude>
    74     <ClInclude Include="..\..\common\Common.h">
    75       <Filter>Header Files\common</Filter>
    76     </ClInclude>
    7774  </ItemGroup>
    7875</Project>
  • client/Client/Textbox.cpp

    rcdb4bec rda692b9  
    1010   str = "";
    1111   selected = false;
    12    shiftPressed = false;
    13    
    14    // populate the shift map
    15    for(int i=0; i<26; i++)
    16       shiftMap['a'+i] = 'A'+i;
    17 
    18    shiftMap['1'] = '!';
    19    shiftMap['2'] = '@';
    20    shiftMap['3'] = '#';
    21    shiftMap['4'] = '$';
    22    shiftMap['5'] = '%';
    23    shiftMap['6'] = '^';
    24    shiftMap['7'] = '&';
    25    shiftMap['8'] = '*';
    26    shiftMap['9'] = '(';
    27    shiftMap['0'] = ')';
    28 
    29    shiftMap['`'] = '~';
    30    shiftMap['-'] = '_';
    31    shiftMap['='] = '+';
    32    shiftMap['['] = '{';
    33    shiftMap[']'] = '}';
    34    shiftMap['\\'] = '|';
    35    shiftMap[';'] = ':';
    36    shiftMap['\''] = '\"';
    37    shiftMap[','] = '<';
    38    shiftMap['.'] = '>';
    39    shiftMap['/'] = '?';
    40    shiftMap[' '] = ' ';
    4112}
    4213
     
    9970      char newChar = 0;
    10071
    101       if (ALLEGRO_KEY_A <= e.keyboard.keycode && e.keyboard.keycode <= ALLEGRO_KEY_Z)
     72      if (ALLEGRO_KEY_A <= e.keyboard.keycode && e.keyboard.keycode <= ALLEGRO_KEY_Z) {
    10273         newChar = 'a'+e.keyboard.keycode-ALLEGRO_KEY_A;
     74         if (al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT))
     75            newChar -= 32;
     76      }
    10377      else if (ALLEGRO_KEY_0 <= e.keyboard.keycode && e.keyboard.keycode <= ALLEGRO_KEY_9)
    10478         newChar = '0'+e.keyboard.keycode-ALLEGRO_KEY_0;
    105       else {
    106          switch(e.keyboard.keycode)
    107          {
    108          case ALLEGRO_KEY_TILDE:
    109             newChar = '`';
    110             break;
    111          case ALLEGRO_KEY_MINUS:
    112             newChar = '-';
    113             break;
    114          case ALLEGRO_KEY_EQUALS:
    115             newChar = '=';
    116             break;
    117          case ALLEGRO_KEY_OPENBRACE:
    118             newChar = '[';
    119             break;
    120          case ALLEGRO_KEY_CLOSEBRACE:
    121             newChar = ']';
    122             break;
    123          case ALLEGRO_KEY_SEMICOLON:
    124             newChar = ';';
    125             break;
    126          case ALLEGRO_KEY_QUOTE:
    127             newChar = '\'';
    128             break;
    129          case ALLEGRO_KEY_BACKSLASH:
    130             newChar = '\\';
    131             break;
    132          case ALLEGRO_KEY_COMMA:
    133             newChar = ',';
    134             break;
    135          case ALLEGRO_KEY_FULLSTOP:
    136             newChar = '.';
    137             break;
    138          case ALLEGRO_KEY_SLASH:
    139             newChar = '/';
    140             break;
    141          case ALLEGRO_KEY_SPACE:
    142             newChar = ' ';
    143             break;
    144          case  ALLEGRO_KEY_BACKSPACE:
    145             if (str.size() > 0)
    146             {
    147                str = str.substr(0, str.size()-1);
    148                return true;
    149             }
    150             else
    151                return false;
    152             break;
    153          case  ALLEGRO_KEY_LSHIFT:
    154          case  ALLEGRO_KEY_RSHIFT:
    155             shiftPressed = true;
    156             break;
    157          default:
    158             cout << "unknown keycode: " << e.keyboard.keycode << endl;
    159             break;
    160          }
    161       }
     79      else if (e.keyboard.keycode = ALLEGRO_KEY_BACKSPACE && str.size() > 0)
     80         str = str.substr(0, str.size()-1);
    16281
    16382      if (newChar != 0) {
    164          if (al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT))
    165             newChar = shiftMap[newChar];
    166 
    16783         str.append(1, newChar);
    16884         return true;
    169       }
    170    }
    171    else if (e.type == ALLEGRO_EVENT_KEY_UP) {
    172       switch(e.keyboard.keycode)
    173       {
    174       case ALLEGRO_KEY_LSHIFT:
    175       case ALLEGRO_KEY_RSHIFT:
    176          shiftPressed = false;
    177          break;
    17885      }
    17986   }
  • client/Client/Textbox.h

    rcdb4bec rda692b9  
    55
    66#include <string>
    7 #include <map>
    87
    98using namespace std;
     
    1514   string str;
    1615   bool selected;
    17    bool shiftPressed;
    18    map<char, char> shiftMap;
    1916
    2017public:
  • client/Client/main.cpp

    rcdb4bec rda692b9  
    2323#include "../../common/Compiler.h"
    2424#include "../../common/Message.h"
    25 #include "../../common/Common.h"
    2625
    2726#include "Window.h"
     
    201200      error("socket");
    202201
    203    set_nonblock(sock);
    204 
    205202   server.sin_family = AF_INET;
    206203   hp = gethostbyname(argv[1]);
     
    212209
    213210   al_start_timer(timer);
    214 
     211 
    215212   while(!doexit)
    216213   {
     
    285282         }
    286283      }
    287 
    288       if (receiveMessage(&msgFrom, sock, &from) >= 0)
    289       {
    290          processMessage(msgFrom, state, chatConsole);
    291          cout << "state: " << state << endl;
    292       }
    293  
    294       if (redraw && al_is_event_queue_empty(event_queue))
    295       {
     284 
     285      if(redraw && al_is_event_queue_empty(event_queue)) {
    296286         redraw = false;
    297287 
     
    374364      case STATE_START:
    375365      {
    376          cout << "In STATE_START" << endl;
    377 
    378366         chatConsole.addLine(response);
    379367
     
    460448
    461449   sendMessage(&msgTo, sock, &server);
     450   receiveMessage(&msgFrom, sock, &from);
     451   processMessage(msgFrom, state, chatConsole);
     452   cout << "state: " << state << endl;
    462453}
    463454
     
    477468
    478469   sendMessage(&msgTo, sock, &server);
     470   receiveMessage(&msgFrom, sock, &from);
     471   processMessage(msgFrom, state, chatConsole);
     472   cout << "state: " << state << endl;
    479473}
    480474
     
    488482
    489483   sendMessage(&msgTo, sock, &server);
     484   receiveMessage(&msgFrom, sock, &from);
     485   processMessage(msgFrom, state, chatConsole);
    490486}
    491487
     
    506502
    507503   sendMessage(&msgTo, sock, &server);
    508 }
     504   receiveMessage(&msgFrom, sock, &from);
     505   processMessage(msgFrom, state, chatConsole);
     506}
  • common/Common.h

    rcdb4bec rda692b9  
    44void set_nonblock(int sock)
    55{
    6    #ifdef WIN32
    7       unsigned long mode = 1;
    8       ioctlsocket(sock, FIONBIO, &mode);
    9    #else
    10       int flags;
    11       flags = fcntl(sock, F_GETFL,0);
    12       assert(flags != -1);
    13       fcntl(sock, F_SETFL, flags | O_NONBLOCK);
    14    #endif
     6    int flags;
     7    flags = fcntl(sock, F_GETFL,0);
     8    assert(flags != -1);
     9    fcntl(sock, F_SETFL, flags | O_NONBLOCK);
    1510}
    1611
Note: See TracChangeset for help on using the changeset viewer.