Online ghost Game Development 2: Ghost Game Development

Source: Internet
Author: User

Online ghost Game Development 2: Ghost Game Development

Finally, it's time to analyze + code. I think so. The first part of this article is the half version I made before (the voting stage will be put on hold after the final exam ), the previous version was used to enhance the transition from the previous many rules of the game to code implementation. The second part further discusses the shortcomings of the first part and the solutions for preliminary consideration.

Home/Index

Whether watching or gamers, you must write a nickname to enter, at that time, considering that opening the interface may exit the page and go to the circle of friends to refresh the page to continue the game (that is, to turn off the browser and then return back), the Session was used to solve the problem, however, I still haven't completed the occasional Session failure problem, and I plan to delete it in the new version.

Home/Login

It is equivalent to a table that has already entered the QQ room. You may have noticed four points:

(1) Project name: Catghost (haha ~) Catch + ghost = Catghost

(2) The page has the same merits as Views/Shared.

<A href = "/"> homepage </a> <a href = "@ Url. action ("Restart", "Home") "onclick =" return confirm ('Are you sure you want to end this Council and start again? ') "> Reopen the game </a> <a href =" @ Url. action ("Signout", "Home") "> completely exit </a> <div> @ RenderBody () (3) enter the nickname and enter the table instead of the room. That's right. In order not to die, I am lazy and have a room with only one table, so only one table can play this game ~

(4) In order to facilitate testing, the maximum number of registrants is three. During the test, due to the Session relationship, starting a new instance is also the same as Michael Jacob, so I used other browsers. (at that time, I felt tired when I got together with 6 browsers for testing, therefore, you can first set up three people to test the interface seen by good people, idiots, and ghosts ).

The number of people is set in Web. config and called in Models/Setting

Private Setting () {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 (Uncle Liu) enters the room and chooses whether to sign up or sit on the sidelines, the page of Michael will change (regularly refresh)

PS: Considering the traffic issue, the Mobile End needs to refresh jq, which is a dead end. So I used the HTML5 server to send events (W3SCHOOL address ), 1 k per second (60 k in 1 minute), 60 k * 60 = 3600 k = 3.5 M in a game for an hour (I feel like it can be done within 5 M, but there must be plenty of room for optimization)

Computing traffic

Wait for the game to start

Here two points:

(1) If you want to speak, the system will prompt "Please wait for the game to begin"

(2) You can see the Arrow between players, indicating the order of speech, that is, the seat (because you sit anywhere on the network, it is randomly assigned a role ). Do you think of the Round Table of Texas hold'em? You can sit next to the person you want to be. Okay ~ I admit that I was too lazy to do so professionally [grievance]

Tang Wu

After Tang clicks "register" at, the following page appears:

Game started

The operations are as follows: take words from the question bank (write them to the program first), randomly assign roles (this is true random, and we will know about the models in the future ), I also started to talk to people who are not ghosts, because they have reached the stage where ghosts can discuss and determine who to start speaking. (do you have the buttons with three names on the ghost interface ?), In this case, the speaker will be blocked by the system.

Ghost Discussion

When all the ghosts specify the same speaker, the following interface appears:

Start to speak

At this time, the speech of the non-Liu Ye will be blocked by the system (the blocking is meaningless and will not be able to be completed ).

The first round ends and the second round begins.

Did you find Zhang San (ghost) started to fish in the water according to Liu Ye and Tang Wu? Okay. The second round will speak like the first round (because my hands are slow and I am late ):

Start voting

You have noticed two points:

(1) That's right. The previous chat record disappears (because my hand was slow to reach the second round, Liu Ye began to suspect Zhang San in the second round, Tang Wu was not sure, and Zhang San continued to argue ), why does the record disappear? This is also to test your memory and prevent you from turning back who has said what, who has doubts about who has voted for whom.

(2) Why did the vote fail? Yes, there should indeed be a vote of no privilege. I have told you I only want to vote ~~ I have to review the exam before I finish it ~~~

So far, this is the feel. There are many details to consider. The following are considerations for the business logic section:

(The following parts cannot be updated in the last two days! First Outline)

1. Models

 

2. Common:

WebCommon obtains various sessions.

Public static class WebCommon {public static Audience GetAudienceFromSession () {return HttpContext. current. session ["player"] as Audience;} public static Civilian GetCivilianFromSession () {return HttpContext. current. session ["player"] as Civilian;} public static Ghost GetGhostFromSession () {return HttpContext. current. session ["player"] as Ghost;} public static void RenewPlayerSession (Audience newAudience) {HttpContext. current. session ["player"] = newAudience;} public static void AddPlayerSession (Audience audience) {HttpContext. current. session. add ("player", audience);} public static void RemovePlayerSession () {HttpContext. current. session. remove ("player ");}}WebCommon

AudienceFilterAttribute is used to filter the audience, that is, to distinguish operations and interfaces between players and onlookers.

Public class AudienceFilterAttribute: ActionFilterAttribute {public override void OnActionExecuting (ActionExecutingContext filterContext) {HttpContextBase context = filterContext. httpContext; if (context. session ["player"] = null) {context. response. redirect ("/"); return;} base. onActionExecuting (filterContext );}}AudienceFilterAttribute

Filter calls in Controller

[AudienceFilter] public class PlayController: Controller {} public class HomeController: Controller {[HttpPost] [AudienceFilter] public ActionResult Logout (){//...} [AudienceFilter] public ActionResult Signout (){//...} [AudienceFilter] public ActionResult Restart (){//...}}[AudienceFilter]

3. Controller

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.