public ConsoleLogger(FeudalGameEngine game)
 {
     game.PeasantAdded   += AddPeasantEventHandler;
     game.PeasantRemoved += RemovePeasantEventHandler;
     game.LostGame       += LostTheGameEventHandler;
     game.WinGame        += WonTheGameEventHandler;
     game.MoneyEarned    += MoneyBalanceChangedEventHandler;
     game.MoneySpend     += MoneyBalanceChangedEventHandler;
 }
コード例 #2
0
        private static void StartGame(FeudalGameEngine gameObject)
        {
            while (gameObject.IsGameOn)
            {
                var actions = GetActionsAtStep();
                if (actions.Count == 0)
                {
                    continue;
                }
                gameObject.MakeStep(actions);
                SaveGame(gameObject);
            }

            Process.GetCurrentProcess().CloseMainWindow();
        }
コード例 #3
0
        private static void SaveGame(FeudalGameEngine game)
        {
            var dto = new DTOGameSave()
            {
                Money         = game.Money,
                PeasantsCount = game.PeasantsCount,
                Settings      = new DTOGameSettingsSave()
                {
                    MaxPeasantCount     = game.Settings.MaxPeasantCount,
                    PeasantsTargetCount = game.Settings.PeasantsTargetCount,
                    PeasantSpawnChance  = game.Settings.PeasantSpawnChance
                }
            };
            var serializer = new DataContractJsonSerializer(typeof(DTOGameSave));

            using var fileStream = new FileStream($"{Directory.GetCurrentDirectory()}\\save.json", FileMode.Truncate);
            serializer.WriteObject(fileStream, dto);
        }