Finally to the analysis + code of the time, I think this, the first part of this chapter I did half of the version (to do the vote, after the final exam is shelved), through the previous version to enhance everyone on the game from the previous a lot of rules to the implementation of the Code transition. The second part discusses the deficiencies of the first part, as well as the initial consideration of the solution.
is the entire Project Explorer, MVC, a total of three pages: Home/index,home/login,play/index. and two controllers, seven model.
0. Views
Let's take a look at the interface.
Home/index
Whether the spectator or the player, to write a nickname to enter, at that time, considering the opening of the interface may exit the page to go to a friend circle brush back to the page to continue the game (that is, to turn off the browser back), using the session to deal with the problem, But occasionally the session failure problem I still did not complete, plan in the new version of the problem KO.
Home/login
The equivalent has entered the QQ room of a table, you may have noticed four points:
(1) The project is called catghost (haha ~) catch+ghost=catghost
(2) the page has the same place, is the credit of views/shared
<ahref="/">Home</a> <ahref= "@Url. Action ("Restart "," Home ")" OnClick= "return confirm (' OK to end this council and start again?") ') ">Re-open a game</a> <ahref= "@Url. Action ("signout "," Home ")">Exit completely</a> <Div>@RenderBody ()<HR/> <Footer> <P>©@DateTime. Now.year-zapup</P> </Footer> </Div>
views/shared/_layout.cshtml
(3) After entering the nickname, enter the table directly, not the room. Yes, in order not to die, lazy made only a table room, so only a table people play this game ~
(4) In order to facilitate the test, the registration limit is 3 people. Test, because of the session relationship, and then start a new instance is also the same three, so I used the other browser (at that time to gather 6 browser test feeling is also heart good tired, it can first set 3 people to play, to test the good guys, idiots, ghosts See the interface).
The number of people is set in Web. config and called in models/setting
PrivateSetting () { This. _civiliancount = Convert.ToInt32 (system.configuration.configurationmanager.appsettings["Civiliancount"]); This. _ghostcount = Convert.ToInt32 (system.configuration.configurationmanager.appsettings["Ghostcount"]); This. _idiocount = Convert.ToInt32 (system.configuration.configurationmanager.appsettings["Idiocount"]);}
Setting
When someone (vi) enters the room and makes a choice to sign up or watch, Zhang San's page changes (timed refresh)
PS: Due to traffic problems, mobile to make JQ refresh, that Cliff killed, so I used the HTML5 server send events (W3school address), per second according to 1k (1 minutes to 60k), one game an hour, you have to 60k*60=3600k= 3.5M (feel 5M can also, but there must be a great space for optimization)
Calculate traffic
Wait for the game to start
Here two points:
(1) To speak will prompt "Please wait for the game to start"
(2) You can see the arrows between the players, indicating the order of the speeches, that is, the seat (because you are in the network where you sit, anyway, randomly assigned roles). Think of Texas hold ' em table? You can sit next to the person you want to do. Well, I admit I'm lazy and don't want to be that professional [grievance]
Tang Five Enter
When the "Registration" button is down at five, the following interface appears:
Game start
One of the operations are: from the question bank to take the word (first written dead in the program), randomly assigned the role (this is true random, follow-up analysis of the model will know), and began to have not ghosts, because it has been to ghosts can discuss and formulate who began to speak the link (see Ghost interface has three names of the button not? ), when non-ghosts want to speak, will be blocked by the system.
Ghost Discussion Session
When all the ghosts have specified the same speaker, the following interface appears:
Start speaking
At this point, the non-Liu Ye speak, will be blocked by the system (the comparison of the stop is not the point).
The first round is over, the second round begins.
Did you find out that Zhang San (ghost) started troubled waters according to the words of Tang and Liu Ye? OK, the second round is like the first round of speaking (because I slowed, a little late):
Start voting
We have noticed two points:
(1) Yes, the previous chat record disappeared (because I slowed not to the second round, the second round is six ye began to doubt Zhang San, Don Five unsure, Zhang San continue to quibble), why the record disappeared, this is to test memory, do not let you go back to who said what, who suspected who, who voted who.
(2) Why did the vote not abstain? Yes, there should be a waiver of votes, all said I only do vote AH ~ ~ have not finished to review the exam well ~ ~ ~
So far, over, the general meaning is this feel, to consider the details of a lot. Here's a look at the Business logic section:
(The following part of today some things will not be updated, to fight for nearly two days to fix!) First, the last outline)
1. Models
2. Common:
Webcommon is responsible for obtaining various session
Public Static classWebcommon { Public StaticAudience getaudiencefromsession () {returnhttpcontext.current.session["player"] asaudience; } Public Staticcivilian getcivilianfromsession () {returnhttpcontext.current.session["player"] ascivilian; } Public StaticGhost getghostfromsession () {returnhttpcontext.current.session["player"] asGhost; } Public Static voidrenewplayersession (Audience newaudience) {httpcontext.current.session["player"] =newaudience; } Public Static voidaddplayersession (audience audience) {HttpContext.Current.Session.Add ("player", audience); } Public Static voidremoveplayersession () {HttpContext.Current.Session.Remove ("player"); } }
Webcommon
Audiencefilterattribute is responsible for filtering the audience, that is, to distinguish between the player and the Spectator's operation and interface
Public classAudiencefilterattribute:actionfilterattribute { Public Override voidonactionexecuting (ActionExecutingContext filtercontext) {httpcontextbase context=Filtercontext.httpcontext; if(Context. session["player"] ==NULL) {context. Response.Redirect ("/"); return; } Base. OnActionExecuting (Filtercontext); } }
Audiencefilterattribute
Filtering is called in the controller
[audiencefilter] public class playcontroller:controller{} class Homecontroller:controller {[HttpPost] [Audiencefilter] public ActionResult Logout () {// ...} [Audiencefilter] public ActionResult SignOut () {// ...} [Audiencefilter] public ActionResult Restart () {// ...} }
[Audiencefilter]
3. Controller
Online Ghost Game Development II-Design business object and object Responsibility Division (1)