- Timestamp:
- Nov 25, 2012, 1:13:45 AM (12 years ago)
- Branches:
- master
- Children:
- 2488852
- Parents:
- 9a3e6b1
- Location:
- client
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
client/.gitignore
r9a3e6b1 r6475138 4 4 Client.sdf 5 5 Client.opensdf 6 client 6 allegro.log -
client/Client/Client.vcxproj
r9a3e6b1 r6475138 65 65 <ItemGroup> 66 66 <ClCompile Include="..\..\common\message.cpp" /> 67 <ClCompile Include="chat.cpp" /> 67 68 <ClCompile Include="main.cpp" /> 68 69 </ItemGroup> … … 70 71 <ClInclude Include="..\..\common\compiler.h" /> 71 72 <ClInclude Include="..\..\common\message.h" /> 73 <ClInclude Include="chat.h" /> 72 74 </ItemGroup> 73 75 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> -
client/Client/Client.vcxproj.filters
r9a3e6b1 r6475138 17 17 <UniqueIdentifier>{9ecfb491-9e8e-4a29-bc07-dd887204d590}</UniqueIdentifier> 18 18 </Filter> 19 <Filter Include="Header Files\common"> 20 <UniqueIdentifier>{6c9ad2f2-bc8d-4e25-9c5c-c4440c60991c}</UniqueIdentifier> 21 </Filter> 19 22 </ItemGroup> 20 23 <ItemGroup> … … 25 28 <Filter>Source Files\common</Filter> 26 29 </ClCompile> 30 <ClCompile Include="chat.cpp"> 31 <Filter>Source Files</Filter> 32 </ClCompile> 27 33 </ItemGroup> 28 34 <ItemGroup> 29 <ClInclude Include=" ..\..\common\message.h">30 <Filter> Source Files\common</Filter>35 <ClInclude Include="chat.h"> 36 <Filter>Header Files</Filter> 31 37 </ClInclude> 32 38 <ClInclude Include="..\..\common\compiler.h"> 33 <Filter>Source Files\common</Filter> 39 <Filter>Header Files\common</Filter> 40 </ClInclude> 41 <ClInclude Include="..\..\common\message.h"> 42 <Filter>Header Files\common</Filter> 34 43 </ClInclude> 35 44 </ItemGroup> -
client/Client/main.cpp
r9a3e6b1 r6475138 26 26 #include "../../common/message.h" 27 27 28 #include "chat.h" 29 28 30 #ifdef WINDOWS 29 31 #pragma comment(lib, "ws2_32.lib") 30 32 #endif 31 33 … … 56 58 bool doexit = false; 57 59 58 vector<string> vctChat; 59 string strPrompt; 60 string strEnteredInput; 60 chat chatConsole; 61 61 62 62 if(!al_init()) { … … 161 161 error("receiveMessage"); 162 162 163 vctChat.push_back(string(msgFrom.buffer));163 chatConsole.addLine(msgFrom.buffer); 164 164 165 165 al_start_timer(timer); … … 193 193 } 194 194 else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { 195 switch(ev.keyboard.keycode) { 196 case ALLEGRO_KEY_UP: 197 key[KEY_UP] = true; 198 break; 199 200 case ALLEGRO_KEY_DOWN: 201 key[KEY_DOWN] = true; 202 break; 203 204 case ALLEGRO_KEY_LEFT: 205 key[KEY_LEFT] = true; 206 break; 207 208 case ALLEGRO_KEY_RIGHT: 209 key[KEY_RIGHT] = true; 210 break; 211 212 case ALLEGRO_KEY_ENTER: 213 strEnteredInput = strPrompt; 214 strPrompt.clear(); 215 216 if (strEnteredInput.compare("q") == 0) { 217 doexit = true; 218 } 219 else 220 { 221 strcpy(msgTo.buffer, strEnteredInput.c_str()); 222 n=sendMessage(&msgTo, sock, &server); 223 if (n < 0) 224 error("sendMessage"); 225 226 n = receiveMessage(&msgFrom, sock, &from); 227 if (n < 0) 228 error("receiveMessage"); 229 230 vctChat.push_back(string(msgFrom.buffer)); 231 } 232 233 break; 234 } 235 236 if(ALLEGRO_KEY_A <= ev.keyboard.keycode && ev.keyboard.keycode <= ALLEGRO_KEY_Z) 237 { 238 char newChar = 'a'+ev.keyboard.keycode-ALLEGRO_KEY_A; 239 strPrompt.append(1, newChar); 240 } 241 242 if(ALLEGRO_KEY_0 <= ev.keyboard.keycode && ev.keyboard.keycode <= ALLEGRO_KEY_9) 243 { 244 char newChar = '0'+ev.keyboard.keycode-ALLEGRO_KEY_0; 245 strPrompt.append(1, newChar); 246 } 195 bool eventConsumed = chatConsole.processEvent(ev); 196 197 if (eventConsumed) { 198 string input = chatConsole.getInput(); 199 if (!input.empty()) { 200 cout << "input: " << input << endl; 201 strcpy(msgTo.buffer, input.c_str()); 202 203 n=sendMessage(&msgTo, sock, &server); 204 if (n < 0) 205 error("sendMessage"); 206 207 n = receiveMessage(&msgFrom, sock, &from); 208 if (n < 0) 209 error("receiveMessage"); 210 211 chatConsole.addLine(string(msgFrom.buffer)); 212 cout << "Added new line" << endl; 213 } 214 }else { 215 switch(ev.keyboard.keycode) { 216 case ALLEGRO_KEY_UP: 217 key[KEY_UP] = true; 218 break; 219 220 case ALLEGRO_KEY_DOWN: 221 key[KEY_DOWN] = true; 222 break; 223 224 case ALLEGRO_KEY_LEFT: 225 key[KEY_LEFT] = true; 226 break; 227 228 case ALLEGRO_KEY_RIGHT: 229 key[KEY_RIGHT] = true; 230 break; 231 } 232 } 247 233 } 248 234 else if(ev.type == ALLEGRO_EVENT_KEY_UP) { … … 277 263 al_draw_bitmap(bouncer, bouncer_x, bouncer_y, 0); 278 264 279 for(int x=0; x<vctChat.size(); x++) 280 al_draw_text(font, al_map_rgb(255,255,255), 10, 10+x*15, ALLEGRO_ALIGN_LEFT, vctChat[x].c_str()); 281 282 al_draw_text(font, al_map_rgb(255,255,255), 10, 460, ALLEGRO_ALIGN_LEFT, strPrompt.c_str()); 283 265 chatConsole.draw(font, al_map_rgb(255,255,255)); 266 284 267 al_flip_display(); 285 268 }
Note:
See TracChangeset
for help on using the changeset viewer.