static void HandlePlayer(Type type, Game.PlayerClass player) { Game game = null; foreach (Game item in games) { if (item.GetType() == type) { if (item.PlayerCount < item.MaxPlayers || item.MaxPlayers == -1 || player.playerType == Game.PlayerType.Spectator) { game = item; break; } } } if (game == null) { game = (Game)Activator.CreateInstance(type); game.GameKilled += OnGameKilled; game.PlayerLeft += OnPlayerLeft; game.PlayerHandoff += OnPlayerHandoff; games.Add(game); Console.WriteLine("Game created."); } game.AddPlayer(player); Console.WriteLine("Player assigned."); }
public override void AddPlayer(Game.PlayerClass player) { player.vt.SetCursorVisiblity(false); player.vt.Bell(); players.Add(new PlayerClass(player)); if (player.playerType == PlayerType.Player) { playerCount++; } if (player.playerType == PlayerType.Player) { if (gameState == GameState.NotStarted) { players[players.Count - 1].playerEnum = PlayerEnum.Player1; gameState = GameState.Training; ResetPositions(); } else if (gameState == GameState.Training) { players[players.Count - 1].playerEnum = PlayerEnum.Player2; FindPlayerEnum(PlayerEnum.Player1).points = 0; FindPlayerEnum(PlayerEnum.Player2).points = 0; gameState = GameState.Normal; ResetPositions(); } } UpdateInfo(); player.vt.Flush(); }
public PlayerClass(Game.PlayerClass gamePlayer) { playerType = gamePlayer.playerType; vt = gamePlayer.vt; supportAixtermColors = gamePlayer.supportAixtermColors; UpdatePalette(); }
public override void AddPlayer(Game.PlayerClass player) { currentPlayer = new PlayerClass(player); players.Add(currentPlayer); currentPlayer.vt.Bell(); currentPlayer.vt.SetCursorVisiblity(false); Flush(); gameState = GameState.Game; }
public override void AddPlayer(Game.PlayerClass player) { currentPlayer = new PlayerClass(player); players.Add(currentPlayer); currentPlayer.vt.Bell(); currentPlayer.vt.SetCursorVisiblity(true); currentPlayer.vt.SetBackgroundColor(currentPlayer.colorPalette.Background); currentPlayer.vt.SetForegroundColor(currentPlayer.colorPalette.Text); currentPlayer.vt.ClearScreen(); Flush(); gameState = GameState.Game; }
public PlayerClass(Game.PlayerClass gamePlayer) { playerType = gamePlayer.playerType; vt = gamePlayer.vt; supportAixtermColors = gamePlayer.supportAixtermColors; if (supportAixtermColors) { colorPalette = new BrightColorPalette(); } else { colorPalette = new ClassicColorPalette(); } }
static void Main(string[] args) { GameThread = new Thread(new ThreadStart(GameThreadMethod)); GameThread.Start(); IPAddress ipAddress = IPAddress.IPv6Any; IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 23); TcpListener listener = new TcpListener(ipEndPoint); listener.Server.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false); listener.Start(); while (true) { try { TcpClient tcpClient = listener.AcceptTcpClient(); VT100 vt = new VT100(tcpClient); vt.Bell(); if (vt.Flush() != VT100.FlushReturnState.Success) { continue; } Game.PlayerClass player = new Game.PlayerClass() { vt = vt }; HandlePlayer(typeof(Lobby), player); Console.WriteLine("Client connected."); } catch (SocketException) { Console.WriteLine("Failed to accept client!"); } catch (Exception e) { Console.WriteLine("Failed to accept client! (THIS SHOULD NOT HAPPEN!)"); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } } }
static void OnPlayerLeft(Game game, Game.PlayerClass player, bool connectionKilled) { if (connectionKilled) { Console.WriteLine("Client disconnected. (connection killed)"); player.vt.Close(); } else { if (game.GetType() == typeof(Lobby)) { Console.WriteLine("Client disconnected. (leaved)"); player.vt.ClearScreen(); player.vt.Reset(); player.vt.Flush(); player.vt.Close(); } else { HandlePlayer(typeof(Lobby), player); } } }
static void OnPlayerHandoff(Game game, Type destination, Game.PlayerClass player) { HandlePlayer(destination, player); }
public override void AddPlayer(Game.PlayerClass player) { players.Add(new PlayerClass(player)); playerCount++; }
public PlayerClass(Game.PlayerClass player) { playerType = player.playerType; vt = player.vt; supportAixtermColors = player.supportAixtermColors; }