public static gameConnection Create(IPAddress ip, long hostId, IGameHostCreation theGameHost) { var Connection = theGameHost.CreateConnection(); Connection.HostId = hostId; Connection.HostAddress = new IPEndPoint(ip, myPort); return(Connection); }
public static GameHost HostGame(IGameHostCreation Creator) { if (IsHosting) { throw new InvalidOperationException("Shut down other host first!"); } var host = Creator.Create(); theInstance = host; host.State = GameState.Starting; host.State = GameState.WaitingForPlayers; return(host); }
public static GameLobby CreateGame(string thePlayerName, IGameHostCreation theGameHost) { if (GameHost.IsHosting) { throw new InvalidOperationException("Cannot create another game while already hosting one!"); } var host = GameHost.HostGame(theGameHost); var lobby = TryToJoin(IPAddress.None, host.ID, thePlayerName, theGameHost); if (!GameHost.IsHosting) { return(null); } if (lobby == null) { GameHost.ShutDown(); } return(lobby); }
public static GameLobby TryToJoin(IPAddress IP, long hostID, string playerName, IGameHostCreation theGameHost) { var lobby = new GameLobby(); var Connection = gameConnection.Create(IP, hostID, theGameHost); lobby.Connection = Connection; lobby.InitializeComponent(); Connection.Initialize(playerName); return(lobby); }