public static GameObject Construct(Type type, ClientGame game, int id) { object[] constuctorParams = new object[1]; constuctorParams[0] = game; GameObject obj = (GameObject)constructorDictionary[type].Invoke(constuctorParams); obj.ID = id; return obj; }
/// <summary> /// The main entry point for the application. /// </summary> public static void ClientMain() { string serverIP = Microsoft.VisualBasic.Interaction.InputBox("Enter Server IP Address", "Server IP Address", "127.0.0.1"); IPAddress address; try { address = IPAddress.Parse(serverIP); } catch (System.FormatException) { return; } ClientGame game = new ClientGame(address); game.Run(); }
/// <summary> /// The main entry point for the application. /// </summary> public static void ClientMain() { string serverIP = Microsoft.VisualBasic.Interaction.InputBox("Enter Server IP Address", "Server IP Address", "127.0.0.1"); IPAddress address; try { address = IPAddress.Parse(serverIP); } catch (System.FormatException) { return; } ClientGame game = new ClientGame(address); game.Run(); }
public LocalPlayerController(ClientGame game) : base() { this.game = game; forward = new KeyDown(Keys.W); back = new KeyDown(Keys.S); left = new KeyDown(Keys.A); right = new KeyDown(Keys.D); fire = new LeftMouseDown(); space = new KeyDown(Keys.Space); this.game.InputManager.Register(forward, this); this.game.InputManager.Register(back, this); this.game.InputManager.Register(left, this); this.game.InputManager.Register(right, this); this.game.InputManager.Register(fire, this); this.game.InputManager.Register(space, this); }
public void Apply(ClientGame game, GameTime gameTime) { this.ResetReader(); Type typeFromMessage = GameObjectTypes.GetType(this.ReadInt()); int idFromMessage = this.ReadInt(); bool isDesroyedFromMessage = this.ReadBoolean(); GameObjectCollection collection = game.GameObjectCollection; GameObject obj; if (collection.Contains(idFromMessage)) { obj = collection.Get(idFromMessage); if (obj.LastMessageTimeStamp > this.TimeStamp) { return; } } else { if (isDesroyedFromMessage) { return; } obj = GameObjectTypes.Construct(typeFromMessage, game, idFromMessage); collection.Add(obj); } if (!(obj.GetType() == typeFromMessage && obj.ID == idFromMessage)) { throw new Exception("this message does not belong to this object"); } obj.IsDestroyed = isDesroyedFromMessage; foreach (GameObjectField field in obj.Fields) { field.ApplyMessage(this); } this.AssertMessageEnd(); obj.LatencyAdjustment(gameTime, this.TimeStamp); }
public ServerConnection(IPAddress serverAddress, ClientGame game) : base(new UdpTcpPair(serverAddress)) { controller = new LocalPlayerController(game); }