Player.IO is the next version of the Nonoba Developer Tools.

More Features, No Branding, Integrates with Everything. Read more »

Nonoba Multiplayer API: Serverside

All multiplayer games made with the Nonoba Multiplayer API has code running either on the local development server, or on Nonoba's cluster of game servers, managing the shared state of the game and sending and receiving messages to and from connected players.

For any given multiplayer game, all its serverside code is contained inside a single .NET 2.0 .dll file. The dll must reference Nonoba.GameLibrary.dll and must contain a class inheriting from Nonoba.GameLibrary.NonobaGame<Player>. These .dll files can be created with any .NET 2.0 language, but we recommend that you use C# 2.0, since it's quite close to ActionScript, and all our examples are written in it. :-)

When a users asks for a game instance to be created via a game's lobby, the development server, or the Nonoba cluster of game servers, looks inside the dll file to find the first class inheriting from Nonoba.GameLibrary.NonobaGame<Player>, and then creates an instance of it charged with managing that game instance.

The class Nonoba.GameLibrary.NonobaGame<Player> is generic which means that it's parameterized and must be told what class is used to represent a player connected to a game. The player class must inherit from Nonoba.GameLibrary.NonobaGameUser.

For example, here is a simple, bare bones game that doesn't do anything:

using System;
using Nonoba.GameLibrary;

namespace MyGame {
	// This class represents a user connected to our game
	public class MyPlayer : NonobaGameUser {
	}

	public class Game : NonobaGame<MyPlayer> {
		// This method is called when a game is created. Useful for setting up initial data.
		public override void GameStarted() {
		}

		// This method is called whenever a player sends a message into the game.
		public override void GotMessage(MyPlayer player, Message m) {
		}

		// When a player enters this game instance
		public override void UserJoined(MyPlayer player) {
		}

		// When a player leaves the game instance
		public override void UserLeft(MyPlayer player) {
		}
	}
}

If that game was contained in a file "MyGame.cs" located in a folder that also contained the "Nonoba.GameLibrary.dll" file, it could be compiled into a complete game dll with the C# compiler command (csc)

C:\>csc /out:MyGame.dll /t:library /reference:Nonoba.GameLibrary.dll MyGame.cs

We would however recommend using Visual Studio Express when creating games, since it provides a much easier development and debugging cycle.

Game and Player classes

The nice thing about having a specific class for both a game and a player, is that you can put properties on both and maintain your state that way. For example, if the objective of our game was simply to click a button most times, the serverside code might look like this.

using System;
using Nonoba.GameLibrary;

namespace ClickathonGame {
	public class ClickingPlayer : NonobaGameUser {
		public int ClickCounter = 0; // we'll add one every time
	}

	public class Clickathon : NonobaGame<ClickingPlayer> {
		public int TotalClickCounter = 0;

		public override void GotMessage(ClickingPlayer player, Message m) {
			// player clicked!
			if (m.Type == "Click") {
				player.ClickCounter++; // update the player
				TotalClickCounter++; // keep track of total clicks in this game instance.
			}

			// player wants highscore
			if (m.Type == "GetScores") {
				// loop over all connected players
				for (int i = 0; i < Users.Length; i++) {
					// send the score to the asking player
					player.Send("score", Users[i].Username, Users[i].ClickCounter);
				}
			}
		}

		// We're not using these methods in this example
		public override void GameStarted() {}
		public override void UserJoined(ClikingPlayer player) {}
		public override void UserLeft(ClikingPlayer player) {}
	}
}

5dyouxi

5dyouxi.com是一个独立的游戏网站,在这里你将可以免费玩到各种好玩的单人和多人游戏。

开发者工具

如果你是一位flash游戏开发者,我们有一些非常强大的工具来帮助你开发更加优秀的游戏。

经典游戏

为什么不试试我们这里的一些最为优秀的在线flash游戏呢?这可是完全免费的!

Copyright ©2007-2012 5dyouxi™ - All rights reserved.15.6ms on SERVER34096
注册 或者