Пример #1
0
        public static GameRunner New(string apiKey, string map, ILoggerFactory loggerFactory)
        {
            var runner = new GameRunner(loggerFactory)
            {
                GameLayer = new GameLayer(apiKey),
            };

            runner._logger.LogInformation($"New game: {map}");
            var gameId = runner.GameLayer.NewGame(map);

            runner._logger.LogInformation($"Starting game: {gameId}");
            runner.GameLayer.StartGame(gameId);
            return(runner);
        }
Пример #2
0
        public static GameRunner Resume(string apiKey, string gameId, ILoggerFactory loggerFactory)
        {
            var runner = new GameRunner(loggerFactory)
            {
                GameLayer = new GameLayer(apiKey),
            };;

            runner.GameLayer.GetNewGameInfo(gameId);

            runner.GameLayer.GetNewGameState(runner.GameLayer.GetState().GameId);

            var state = runner.GameLayer.GetState();

            if (!string.IsNullOrWhiteSpace(gameId))
            {
                runner._logger.LogInformation($"Resuming game specified game: {gameId} on turn {state.Turn}");
            }
            else
            {
                runner._logger.LogInformation($"Resuming previous game: {state.GameId} on turn {state.Turn}");
            }
            return(runner);
        }
Пример #3
0
        public static void Main(string[] args)
        {
            var loggerFactory = LoggerFactory.Create(c => c
                                                     .AddConsole()
                                                     .AddDebug()
                                                     .SetMinimumLevel(LogLevel.Debug));

            // Init GameLayer
            var apiKey = args.ElementAtOrDefault(0) ?? ApiKey;

            while (string.IsNullOrWhiteSpace(apiKey))
            {
                Console.Write("ApiKey: ");
                apiKey = Console.ReadLine();
            }
            GameLayer = new GameLayer(apiKey);

            // Init Game
            GameRunner runner;
            var        gameId = args.ElementAtOrDefault(1);

            if (gameId?.ToLower() == "new")
            {
                runner = GameRunner.New(apiKey, Map, loggerFactory);
            }
            else
            {
                runner = GameRunner.Resume(apiKey, gameId, loggerFactory);
            }

            var score = runner.Run();
            //Console.WriteLine($"Final score: {score.FinalScore}");
            //Console.WriteLine($"Co2: {score.TotalCo2}");
            //Console.WriteLine($"Pop: {score.FinalPopulation}");
            //Console.WriteLine($"Pop: {score.TotalHappiness}");
        }