亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? full tutorial.htm

?? 通用網絡游戲開發框架
?? HTM
?? 第 1 頁 / 共 3 頁
字號:
player details to see if there is a free player position in thegame. The code is currently set to handle up to 6 players(<i>max_players</i>) but that is easy to change (increase<i>max_players</i> and create colours for the new players in the<i>Board</i> class). <p>Once a free slot has been found the details ofthe client connecting are stashed away and a new thread(<i>client_handler</i>) is started to look after the new player. Thegame handler then loops back to the listen call where it will wait formore clients to connect.  So, to take an example of 2 clientsconnected we would have the following server threads running:<P><IMG SRC="Full Tutorial_files/image005.gif" ><p>The <i>client_handler</i> thread creates a socket (called<i>client</i>) and initialises it with the details saved in the gamethread so that it can talk to the newly joined client. <pre>   Socket   client;   client.set_connection(clients[player].connection);</pre><p>Then the client handler sits in a loop that performs the following:<pre>while (true) {   string command;   client >> command;      for (int i = 0; i < num_commands; i++) {      if (command == command_list[i].command) {         command_list[i].function(client, player);      }   }}</pre><p>This just reads a command text string from the client connected to thisthread, looks it up in a table of commands and, if it is found, callsthe appropriate function to deal with that command. From the clientend, the code to actually send some command is trivial, for example:<pre>server << "some-command\n";</pre><p>The very first thing that a client does when starting up is to start athread to receive updates from the server update handler (the code fordoing this is almost identical to that shown above). Once that threadis running, the client sends the following command to the server:<pre>connect computer_name port</pre><p>This command is used to tell the client handler which computer namethe client is running on and which port the server should use to talkto the client (we could have just hard-coded a value as we did for theserver but it's handy to run multiple clients on the same PC fortesting and this lets us do this without messing about in thecode). The server code for handling this command looks like this:<pre>   int    port;   string hostname;   client >> hostname >> port;   client << player << "\n";   Socket * socket = (new Socket());   socket->connect(hostname.c_str(), port);   clients[player].socket = socket; </pre><p>The first part of the code reads in the hostname and port and sendsthe player number back to the client. This tells the client whichplayer he is in the game and is used to select the colour of histroops as the board is updated (amongst other things). The <i>client_handler</i> thread then creates a socket which is connectedto the hostname and port which the client has just asked us touse. This will be used later to send the client the game updates andother commands. The socket we have just created is then stashed awayin a table where we keep the details of the connected clients.<p>So, once a client has fully started, we have the followingcommunication relationships between the threads of the client andserver:<P><IMG SRC="Full Tutorial_files/image006.gif" ><h3>Game Start</h3> <p>When the start button is pressed on the server dialog the followingcode is executed:<pre>   board.initialise(exploring, hidden);   for (int i = 0; i < max_players; i++) {      if (clients[i].in_use) {         board.setup_player(i, number_of_bases, group_bases);      }   }   for (int k = 0; k < max_players; k++) {      if (clients[k].in_use) {         Socket * socket = clients[k].socket;         (*socket) << "new-board\n";           board.transmit(socket);      }   }   game_running = true;</pre><p>First, we ask the board to initialise itself, passing over some of theoptions from the dialog (this is when the terrain is generated). Then,for each player, we ask the board to set up that player (this is wherebases are created).<p>Finally, we ask the board to copy itself to each of the clients overthe socket connection we have established with the client. Thisdeviates from our preferred streaming approach and uses the socket<i>transmit</i> function. I did start out streaming the board into and outof the socket but it was just too slow.<p>It's important to point out that the server has one copy of the boardand every client has its own that is partly synchronised to the servermaster. This allows every client to have their own unique view on theboard relating to what they can see (this feature is used to implementexplore mode, for example).<p>On the client side, the code that responds to the new-board command isvery predictable:<pre>   board.receive(inbound);</pre><h3>Client Commands</h3><p>When the game is running the client can send the commands below to theserver in response to mouse clicks and key presses (x and y are theWindows co-ordinates where the mouse is positioned:<p>mouse x y<br>key value x y<br><p>When a key is pressed the command key is followed by the ASCII code ofthe character pressed.<p>Why do we do it this way? We could, of course, build in knowledge inthe client that a left mouse click means add a vector and send acommand to that effect to the server. However, this is buildingknowledge of the game into the client, the server and the game classesthemselves. This means that there could be a lot of work should wewant to re-use the client or server code in a new project where keysand mouse buttons imply different commands.<p>The design aim is to make the client (and the server) as generic as wecan. All they need to know is that they are playing a multi-usergame. They don't need to know they are playing WinBattle or any othergame. Consequently the client and server are dumb. If somebody clicksa mouse button they just blindly pass it on to the game classes whoknow what to do with it. In an ideal world, if you want to write atotally different multi-player game all you would have to do is changethe game classes. You wouldn't have to touch the core client or servercode at all. <p>However, back in the real world this isn't completely practical(although it is possible with some work). For example, the serverdialog needs to know about the various game options so that they canbe displayed and set. So, the pragmatic design goal is to keep thedependencies as small as we can and if you look at the code in theclient and server directories you'll see that, although they know theyhave a game board, they know nothing else about it. For example, if wesuddenly decided to make the board cells tiled octagons instead ofhexagons then there would be no changes needed to either the client orthe server code.  <h3>Game Updates</h3> <p>As the game progresses, the server <i>update_handler</i> threadperiodically sends the updated state of the board to the clients. Thecode is as follows:<pre>   vector<Client>::iterator k;   for (k = clients.begin(); k != clients.end(); k++) {      if (k->in_use) {         Socket * socket = k->socket;         (*socket) << "update-board\n";         board.send_updates(socket);      }   }   board.end_of_updates();</pre><p>This loops for each possible client. If a particular client isconnected then we warn it that an update is about to follow with the<i>update-board</i> command and then send across the updates. Once allupdates have been sent we let the board know that (with the call to<i>end_of_updates</i> so that it can prepare the next set).<p>The client code to deal with this is the rather boring:<pre>   board.get_updates(&inbound);</pre><p>Note that neither the client nor the server has any idea what theseupdates are. They both just know that periodic updates are beingexchanged. <h3>Shut Down</h3><p>OK, we've got all these threads up and running how do we handleclients and servers being terminated? Quite simply, if either stopsit's polite enough to send a message to the other to that effect. Forexample, if the server is killed while clients are still running itruns through its list of connected clients and sends each one amessage so that the client server handler thread can exit gracefully:<pre>   vector<Client>::iterator i;   for (i = clients.begin(); i != clients.end(); i++) {      if (i->in_use) {         *(i->socket) << "shut-down\n";      }   }</pre><p>Similarly, if a client terminates it sends a message to the server sothat the server client handler thread can close down and free up aslot for another client:<pre>      server << "disconnect\n";</pre><p>The code that runs in the server when this command is received is asfollows:<pre>   Socket * socket = (clients[player].socket);   (*socket) << "shut-down\n";   client.close();   socket->close();   free(socket);   clients[player].in_use = false;   ExitThread(0);</pre><p>As the command to shut down comes from the main thread of the clientwe send a message to the client's other thread to ask it to shut downtoo. We close the sockets to release their resources and flag that wenow have a free slot in our list of clients.<p>Note that, in this simple example, it assumes that a server isstarted before any clients are and that if a server is shut-downclients are too. It wouldn't be hard for clients to carry on workingwhen the server is restarted but I'll leave that as "an exercise forthe reader".  <h3>Summary</h3><p>So far we've described an almost generic client-server environmentthat can run any game of a certain class (it has a board, players andreal-time updates). The framework described so far should be a goodbase for implementing anything that fits into this model and the nextsection shows some of the additional techniques that were used toimplement WinBattle.<h3>Board Class</h3><p>All of the code that knows about the game can be found in the gamefolder. It is just two classes: <i>Board</i> and <i>Cell</i> (althoughthese classes are implemented using a number of separate files forreadability). The <i>Board</i> class implements the game itself, the<i>Cell</i> class is used to implement the individual cells on theboard. So, ignoring the functions for copying the board from theserver to the client which we've already covered, the <i>Board</i>class has the following additional functions we can call:<pre>   draw        	Draws the whole game board.   get_size    	Returns the window size of the board.   initialise  	Prepares the board for a new game (generates terrain, etc.).   key         	Deals with a key press.

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美成人一区二区三区| 亚洲综合精品久久| 国产超碰在线一区| 中文字幕欧美激情| 色天天综合久久久久综合片| 国产一区二区久久| av激情亚洲男人天堂| www.亚洲免费av| 欧美性做爰猛烈叫床潮| 精品国产一区二区亚洲人成毛片| 在线电影一区二区三区| 欧美精品一区二区三区视频| 久久亚洲一区二区三区四区| 欧美国产精品一区| 亚洲gay无套男同| 大陆成人av片| 精品黑人一区二区三区久久 | 国产精品乱码一区二区三区软件| 国产亚洲精品超碰| 夜夜爽夜夜爽精品视频| 久久精品国产亚洲a| 99久久久国产精品免费蜜臀| 日韩欧美中文字幕公布| 国产欧美综合在线| 日韩av不卡一区二区| 不卡av免费在线观看| 欧美哺乳videos| 亚洲chinese男男1069| 色综合久久中文字幕综合网| 久久综合久久鬼色| 免费人成网站在线观看欧美高清| www.激情成人| 综合久久给合久久狠狠狠97色| 精品一区二区三区免费视频| 欧美日韩成人在线| 五月激情综合色| 51精品久久久久久久蜜臀| 亚洲v中文字幕| 欧美日韩久久一区| 欧美aa在线视频| 久久看人人爽人人| 岛国av在线一区| 中文字幕一区二区三区精华液| 国产大陆a不卡| 最新热久久免费视频| 92国产精品观看| 亚洲美女区一区| 欧美无砖砖区免费| 美国三级日本三级久久99| 精品国产一区二区亚洲人成毛片 | 欧洲人成人精品| 日本欧美韩国一区三区| 日韩欧美123| 青草国产精品久久久久久| 日韩一区和二区| 国产91高潮流白浆在线麻豆 | 天堂一区二区在线免费观看| 欧美美女一区二区三区| 日日夜夜一区二区| 国产日产欧产精品推荐色| av在线一区二区| 天堂一区二区在线| 亚洲欧美日韩一区二区 | 日本va欧美va精品发布| 国产清纯在线一区二区www| 色狠狠av一区二区三区| 国产在线视频精品一区| 日韩毛片高清在线播放| 欧美一级二级在线观看| 91成人在线精品| 成人av电影在线| 国产精品一区免费视频| 日韩av在线发布| 亚洲综合激情另类小说区| 国产日韩欧美精品综合| 欧美xxxxx裸体时装秀| 欧美性感一区二区三区| 日本高清视频一区二区| www.成人网.com| 91麻豆精东视频| 色999日韩国产欧美一区二区| 国产aⅴ综合色| av一本久道久久综合久久鬼色| 国产激情一区二区三区| 国产一区二区三区在线观看精品| 午夜精品久久久久久不卡8050| 亚洲欧美一区二区视频| 亚洲欧美综合色| 亚洲一区二区综合| 免费成人小视频| 国产福利电影一区二区三区| 国产一区二区三区四区五区美女| 日本aⅴ亚洲精品中文乱码| 日韩成人伦理电影在线观看| 三级在线观看一区二区| 精品制服美女丁香| 北条麻妃一区二区三区| 欧美亚洲尤物久久| 久久影院午夜论| 成人欧美一区二区三区小说 | 欧美性猛交xxxxxx富婆| 欧美精三区欧美精三区| 精品久久久久久久久久久久久久久久久 | 欧美三区在线观看| 日韩欧美在线影院| 中文字幕日韩一区| 日韩国产成人精品| 成人激情视频网站| 69p69国产精品| 亚洲人成电影网站色mp4| 老司机一区二区| 在线观看国产91| 国产精品久久久久久亚洲伦| 亚洲国产色一区| 99久久精品一区| 亚洲国产精品成人综合| 免费看欧美女人艹b| 在线观看日产精品| 日韩理论片在线| 成人h动漫精品一区二区| 欧美精品在线视频| 有码一区二区三区| 91在线视频18| 亚洲六月丁香色婷婷综合久久 | 国产精品国产精品国产专区不蜜 | 欧美—级在线免费片| 精品午夜一区二区三区在线观看| 一本色道久久综合精品竹菊 | 国产91精品精华液一区二区三区| 国产日韩欧美精品综合| 奇米影视一区二区三区| 欧美成人精品二区三区99精品| 图片区小说区区亚洲影院| 91成人免费在线视频| 亚洲视频一二三| 在线播放国产精品二区一二区四区| 一区精品在线播放| 欧美日韩色综合| 奇米亚洲午夜久久精品| 久久精品无码一区二区三区| 粉嫩一区二区三区在线看| 国产精品久99| 欧美日韩精品一区二区三区| 性感美女极品91精品| 欧美xxx久久| av电影一区二区| 琪琪一区二区三区| 国产午夜亚洲精品午夜鲁丝片| 99九九99九九九视频精品| 亚洲午夜久久久久久久久电影网| 欧美美女bb生活片| 国产在线视频精品一区| 亚洲免费伊人电影| 日韩欧美一卡二卡| 国产精品自拍毛片| 丝袜亚洲另类丝袜在线| 成人av在线影院| 亚洲色图制服丝袜| 欧美tickling网站挠脚心| av影院午夜一区| 久久aⅴ国产欧美74aaa| 亚洲一区二区三区中文字幕在线 | 国产成人综合在线观看| 一区二区三区毛片| 欧美国产禁国产网站cc| 一区在线观看免费| 美女久久久精品| 97精品久久久午夜一区二区三区| 在线免费观看日韩欧美| 欧美大片在线观看一区| 欧美激情一区在线观看| 丝袜国产日韩另类美女| 天堂一区二区在线| 色综合咪咪久久| 国产亚洲一区二区三区四区| 一区二区三区日韩欧美| 国产精品18久久久久久vr| 欧美精品丝袜中出| 亚洲一区二区三区精品在线| 国产精品1024久久| 精品国产123| 狠狠色狠狠色综合系列| 欧美高清性hdvideosex| 亚洲视频资源在线| 97久久精品人人做人人爽50路| 精品va天堂亚洲国产| 国产一二精品视频| 国产性色一区二区| 欧美色中文字幕| 欧美国产日韩在线观看| 精品久久久网站| 亚洲黄色小视频| 国产欧美1区2区3区| 欧美一区二区在线播放| 欧美挠脚心视频网站| 欧美婷婷六月丁香综合色| 91电影在线观看| 欧美日韩一区二区三区视频| 在线免费精品视频| 亚洲福利国产精品|