Changes in / [cdb4bec:da692b9] in network-game
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/Client.vcxproj
rcdb4bec rda692b9 73 73 </ItemGroup> 74 74 <ItemGroup> 75 <ClInclude Include="..\..\common\Common.h" />76 75 <ClInclude Include="..\..\common\Compiler.h" /> 77 76 <ClInclude Include="..\..\common\Message.h" /> -
client/Client/Client.vcxproj.filters
rcdb4bec rda692b9 72 72 <Filter>Header Files\common</Filter> 73 73 </ClInclude> 74 <ClInclude Include="..\..\common\Common.h">75 <Filter>Header Files\common</Filter>76 </ClInclude>77 74 </ItemGroup> 78 75 </Project> -
client/Client/Textbox.cpp
rcdb4bec rda692b9 10 10 str = ""; 11 11 selected = false; 12 shiftPressed = false;13 14 // populate the shift map15 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[' '] = ' ';41 12 } 42 13 … … 99 70 char newChar = 0; 100 71 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) { 102 73 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 } 103 77 else if (ALLEGRO_KEY_0 <= e.keyboard.keycode && e.keyboard.keycode <= ALLEGRO_KEY_9) 104 78 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); 162 81 163 82 if (newChar != 0) { 164 if (al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT))165 newChar = shiftMap[newChar];166 167 83 str.append(1, newChar); 168 84 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;178 85 } 179 86 } -
client/Client/Textbox.h
rcdb4bec rda692b9 5 5 6 6 #include <string> 7 #include <map>8 7 9 8 using namespace std; … … 15 14 string str; 16 15 bool selected; 17 bool shiftPressed;18 map<char, char> shiftMap;19 16 20 17 public: -
client/Client/main.cpp
rcdb4bec rda692b9 23 23 #include "../../common/Compiler.h" 24 24 #include "../../common/Message.h" 25 #include "../../common/Common.h"26 25 27 26 #include "Window.h" … … 201 200 error("socket"); 202 201 203 set_nonblock(sock);204 205 202 server.sin_family = AF_INET; 206 203 hp = gethostbyname(argv[1]); … … 212 209 213 210 al_start_timer(timer); 214 211 215 212 while(!doexit) 216 213 { … … 285 282 } 286 283 } 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)) { 296 286 redraw = false; 297 287 … … 374 364 case STATE_START: 375 365 { 376 cout << "In STATE_START" << endl;377 378 366 chatConsole.addLine(response); 379 367 … … 460 448 461 449 sendMessage(&msgTo, sock, &server); 450 receiveMessage(&msgFrom, sock, &from); 451 processMessage(msgFrom, state, chatConsole); 452 cout << "state: " << state << endl; 462 453 } 463 454 … … 477 468 478 469 sendMessage(&msgTo, sock, &server); 470 receiveMessage(&msgFrom, sock, &from); 471 processMessage(msgFrom, state, chatConsole); 472 cout << "state: " << state << endl; 479 473 } 480 474 … … 488 482 489 483 sendMessage(&msgTo, sock, &server); 484 receiveMessage(&msgFrom, sock, &from); 485 processMessage(msgFrom, state, chatConsole); 490 486 } 491 487 … … 506 502 507 503 sendMessage(&msgTo, sock, &server); 508 } 504 receiveMessage(&msgFrom, sock, &from); 505 processMessage(msgFrom, state, chatConsole); 506 } -
common/Common.h
rcdb4bec rda692b9 4 4 void set_nonblock(int sock) 5 5 { 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); 15 10 } 16 11
Note:
See TracChangeset
for help on using the changeset viewer.