C # server WeChat games - multiplayer online role-playing (II)

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

C # server WeChat games - multiplayer online role-playing (II)

Either with human-computer interaction software, nothing more than to solve the input and output operations on three major issues, namely, what data is coming from, where to go.
- Uncle Mao

A leveling Daguai game is no exception.

general idea

Simply speaking, is that we want a pre-World (World), then there are a number of space, or it is in terms of a number of 2D game map (Map), then each map (Map) there are some content (Object), each content of each space in this world which is running in the agreed manner, while the user initiates some commands from the client to control some content, such as player characters, then the final content in a certain way feedback to the user. If this process has been the cycle continues, the game is complete.

服务端
世界
空间
空间
空间
客户端
输入
输出
接口
接口
循环运行机制
内容
内容
内容
用户

So look, is not it simple?
All things are complicated by the simple things constituted so good at decomposing the problem, there is no complicated thing.

Server

Let's take the world how to make and run it?

First, we should define a class games and a world class Game GameWorld, then of course the map class GameMap, then there is content classes GameObject.

Game class to focus GameWorld interact with the outside world, such GameWorld can operate at relatively independent closed state. Just outside of the Game class to interact, regardless of how specific GameWorld is running; and GameWorld only need to provide some way to the Game class, regardless of the state of the outside world to interact. The benefits of this plan is that the scope and the time of writing optimized code, we will consider the relative concentration, which is not surrounded by digging and inefficient.

Then define a GameServer, for processing the request sent by the client, interact with the Game class, feedback data to the client according to the situation.

我们还需要一个运行在Windows服务端的监控界面,.Net提供了多种可视化界面的解决方案,直接把GameServer做成Windows Service当然比较方便,但是具体操作起来就不够直观。Console App当然是比较简单的,不过界面实在不是很友好,所以么,我们还是用个简单的Windows Forms App来解决,就叫GameMonitor吧。

为了避免所有操作都必须登服务器,我们还应该提供一个Web管理网站AdminWeb。这样可以随时随地对服务端进行操作。

好了,服务端主要就是这么几块了。
Game - 游戏类
GameWorld - 世界类
GameServer - 游戏服务类
GameMonitor - 服务器控制界面
AdminWeb - 远程控制界面

交互
本机管理
远程管理
交互
交互
交互
交互
管理员
用户
GameMonitor
AdminWeb
GameServer
Game
GameWorld

客户端

客户端相对而言要简单一些。主要就是完成数据传输、用户输入以及界面渲染三个功能。而微信小游戏的API提供了足够的支持来满足我们的需要。

首先,我们需要一个net.js来处理网络通信,毕竟是网游啊,兄嘚~
然后,用一个setTouch.js来处理用户输入,将用户的设备点击翻译为界面点击并启动相应的处理。
最后,用一个refresher.js来处理服务器轮询,将用户指令传递给服务端,并取回渲染界面所需要的数据。

客户端启动后调用小游戏API自动完成用户的注册和登录,直接与微信公众平台分配的openid绑定,授权这一块,就交给马化腾了,微信被黑了可别找我。
登录后立即启动refresher开始轮询并渲染界面,直到用户退出或网络断开。

主要就这么三块了。

net - Network Communication
setTouch - input process
refresher - Polling and rendering

调用
渲染信息
控制信息
交互
渲染界面
处理输入
用户
setTouch
refresher
net
服务端

Communication system

The ability of real-time online games, and micro-channel mini-games based on the provided, we chose based WebSocket wss agreement as a major client and server interaction protocol. WebApi also provides a non-interactive mode based duplex https protocol.
WebSocket is mainly used for the transmission of information required to render a high transmission efficiency, and WebApi mainly deal with some of the data server does not actively sent, for example, get the latest announcements from the server or something ......
for AdminWeb management side, will be used in WCF interface for complete interaction between the management-side page with GameServer.

So far, we know little about how to start up.
Next, we will discuss how to begin to write server-side code, because, nonsense, easy to rip the first to write a client to force good!

Previous: C # server WeChat games - multiplayer online role-playing (a)
Next: C # server WeChat games - multiplayer online role-playing (c)

Check out the game demo with the ultimate effect of micro-channel scan

Entrance demo

Guess you like

Origin blog.csdn.net/foomow/article/details/92080416