/// <summary> /// Start the system. This method must be called. /// </summary> /// <param name="Loop">The game loop called for each game.</param> public void Run(GameLoop Loop) { try { _Client = new System.Net.Sockets.TcpClient(_Server, _Port); } catch { System.Console.WriteLine("[ERROR] Impossible to join the server (FATAL)"); System.Environment.Exit(1); } JSON.Object connect = new JSON.Object(); connect["login"] = _Username; connect["password"] = _Password; _Write(connect); try { while (true) { JSON.Object newgame = _ReadObject(); Game game = new Game(); game._Parent = this; try { if ((newgame["error"] as JSON.String).Value != "") { Console.WriteLine("[ERROR] Invalid connection check your login and your password"); System.Environment.Exit(1); } } catch { } try { game.You._Name = (newgame["you"] as JSON.String).Value; } catch { game.You._Name = "noname"; } try { game.Challenger._Name = (newgame["challenger"] as JSON.String).Value; } catch { game.Challenger._Name = "noname"; } Loop(game); if (!game._Ended) { System.Console.WriteLine("[ERROR] Game loop has ended before the end of the game (FATAL)"); System.Environment.Exit(1); } JSON.Object ready = new JSON.Object(); ready["type"] = "ready"; _Write(ready); System.Threading.Thread.Sleep(10); } } catch (Exception e) { Console.WriteLine("[INFO] An exception occurs inside the game loop:\n" + e.ToString()); } try { _Client.Close(); } catch { } }
public int GetCount(Game.Startegy Strategy) { switch (Strategy) { case Game.Startegy.E: return _E; case Game.Startegy.G: return _G; case Game.Startegy.M: return _M; case Game.Startegy.N: return _N; case Game.Startegy.S: return _S; case Game.Startegy.T: return _T; case Game.Startegy.W: return _W; } return 0; }