void ToggleSetting(GameSetting setting)
        {
            if (!setting.CanBeChangedInGame && IsInGame)
            {
                Dynamic.PlayErrorSound();
                return;
            }

            setting.ToggleValue();

            if (IsInGame)
            {
                save.SetSettings(settings);
            }
            else
            {
                GameSettingsLoader.WriteSettingsToFile(settings);
            }

            var selectedMenu = ((object)Dynamic._selectedMenuCollection).AsDynamic();
            var menuEntry    = new MenuEntry(((IList)selectedMenu.Entries)[selectedMenu.SelectedIndex]);

            if (!setting.CanBeChangedInGame && IsInGame)
            {
                menuEntry.BaseDrawColor = MenuEntry.UnAvailableColor;
            }

            setting.UpdateMenuEntry(menuEntry);
        }
Exemplo n.º 2
0
        internal static SettingCollection GetSettings(this GameSave gameSave)
        {
            var json = gameSave.GetSaveString(SaveFileSettingKey);

            return(string.IsNullOrEmpty(json)
                                ? new SettingCollection()
                                : GameSettingsLoader.FromJson(json));
        }
Exemplo n.º 3
0
        public Log(GCM gcm)
        {
            this.gcm = gcm;

            SetSettings(GameSettingsLoader.LoadSettingsFromFile());

            Add(this);
        }
Exemplo n.º 4
0
        public void ShouldReturnBottomHorizontalLine()
        {
            var board = GameSettingsLoader.Load(
                @" .▲. 
 XXX ");
            var type = WallAnalyzer.GetWallType(board.Walls, (1, 1), board.Width, board.Height);

            type.Should().Be(WallType.HorizontalLine);
        }
Exemplo n.º 5
0
        public void TheBoardCanBeLoadedFromATextFile()
        {
            var filename = "SimpleTestBoard.txt";

            var gameBoard = GameSettingsLoader.LoadFromFile(filename);

            gameBoard.Should().BeEquivalentTo(new
            {
                Walls   = new CellLocation[] { (0, 0), (1, 0), (2, 0), (0, 1), (2, 1), (0, 2), (1, 2) },
Exemplo n.º 6
0
        public void ShouldReturnRightVerticalLine()
        {
            var board = GameSettingsLoader.Load(
                @" ..X 
 ..X 
 .▲X ");
            var type = WallAnalyzer.GetWallType(board.Walls, (2, 1), board.Width, board.Height);

            type.Should().Be(WallType.VerticalLine);
        }
Exemplo n.º 7
0
        public void ShouldAnalyzeTopRightCornerAsTopRightArc()
        {
            var board = GameSettingsLoader.Load(
                @" XX 
 ▲X ");
            var type = WallAnalyzer.GetWallType(board.Walls, (1, 0), board.Width, board.Height);


            type.Should().Be(WallType.TopRightArc);
        }
Exemplo n.º 8
0
        public void ShouldAnalyzeTopLeftEdgeAsTopLeftArc()
        {
            var board = GameSettingsLoader.Load(
                @" ... 
 .XX 
 ▲X ");
            var type = WallAnalyzer.GetWallType(board.Walls, (1, 1), board.Width, board.Height);


            type.Should().Be(WallType.TopLeftArc);
        }
Exemplo n.º 9
0
        public void ShouldAnalyzeRightHorizontalLineEdgeAsHorizontalLine()
        {
            var board = GameSettingsLoader.Load(
                @"    
   XX
   ▲ ");
            var type = WallAnalyzer.GetWallType(board.Walls, (1, 1), board.Width, board.Height);


            type.Should().Be(WallType.HorizontalLine);
        }
Exemplo n.º 10
0
        public void ShouldAnalyzeVerticalLine4AsVerticalLine()
        {
            var board = GameSettingsLoader.Load(
                @" XX.
 XX.
 XX▲");
            var type = WallAnalyzer.GetWallType(board.Walls, (1, 1), board.Width, board.Height);


            type.Should().Be(WallType.VerticalLine);
        }
Exemplo n.º 11
0
        public void ShouldAnalyzeBottomRightCorner1AsBottomRightArc()
        {
            var board = GameSettingsLoader.Load(
                @" ▲XX 
 XXX 
 XXX ");
            var type = WallAnalyzer.GetWallType(board.Walls, (1, 1), board.Width, board.Height);


            type.Should().Be(WallType.BottomRightArc);
        }
Exemplo n.º 12
0
        public void ShouldAnalyzeBottomLeftEdgeAsBottomLeftArc()
        {
            var board = GameSettingsLoader.Load(
                @" .X  
 .XX 
 .▲.");
            var type = WallAnalyzer.GetWallType(board.Walls, (1, 1), board.Width, board.Height);


            type.Should().Be(WallType.BottomLeftArc);
        }
        void OnOkayEntrySelected(PlayerIndex playerIndex)
        {
            var hexString = GetHexString();

            if (!Seed.TryParse(hexString, out var seed))
            {
                ShowErrorDescription("Invalid seed id, it is not a valid hexidecimal value.");
                return;
            }

            if (!forceSeed && !Randomizer.IsBeatable(seed, FillingMethod.Random))
            {
                ShowErrorDescription("Invalid seed id, it cannot be beaten.");
                return;
            }

            difficultyMenu.SetSeedAndFillingMethod(seed, FillingMethod.Random, GameSettingsLoader.LoadSettingsFromFile());

            Dynamic.OnCancel(playerIndex);
        }
Exemplo n.º 14
0
        public override void Initialize(ItemLocationMap itemLocationMap, GCM gameContentManager)
        {
            gcm = gameContentManager;

            if (!IsUsedAsGameSettingsMenu)
            {
                return;
            }

            Dynamic._menuTitle = "Game Settings";

            var gameplayScreen = ScreenManager.FirstOrDefault <GameplayScreen>();

            save = gameplayScreen?.Save;

            settings = IsInGame
                                ? gameplayScreen.Settings
                                : GameSettingsLoader.LoadSettingsFromFile();

            ResetMenu();
        }
Exemplo n.º 15
0
        void OnDefaultsSelected(GameSettingCategoryInfo[] menusToClear, bool isSubmenu)
        {
            // Clear the root menu
            if (!IsInGame && !isSubmenu)
            {
                settings = new SettingCollection();
            }
            else
            {
                foreach (var category in menusToClear)
                {
                    foreach (var settingsFunc in category.SettingsPerCategory)
                    {
                        var setting = settingsFunc(settings);

                        if (IsInGame && !setting.CanBeChangedInGame)
                        {
                            continue;
                        }

                        setting.SetDefault();
                    }
                }
            }

            if (IsInGame)
            {
                save.SetSettings(settings);
            }
            else
            {
                GameSettingsLoader.WriteSettingsToFile(settings);
            }

            ResetMenu();
            if (isSubmenu)
            {
                Dynamic.GoToPreviousMenuCollection();
            }
        }
Exemplo n.º 16
0
        static async Task Main(string[] args)
        {
            var game = new Game.Game(new GameClock(), GameSettingsLoader.LoadFromFile("board.txt"));

            _allCoins = game.Coins;
            while (true)
            {
                var keys = GetAllKeysPressed();

                if (keys.Contains(ConsoleKey.Escape))
                {
                    break;
                }

                var directions = keys.Select(x => x switch
                {
                    ConsoleKey.UpArrow => Direction.Up,
                    ConsoleKey.DownArrow => Direction.Down,
                    ConsoleKey.LeftArrow => Direction.Left,
                    ConsoleKey.RightArrow => Direction.Right,
                    _ => (Direction?)null
                }).Where(x => x != null).ToList();
Exemplo n.º 17
0
        public static void LogException(Exception exception)
        {
            using (var file = new StreamWriter(GetFileName()))
            {
                try
                {
                    file.WriteLine("Context:");
                    file.WriteLine(
                        $"Timespinner Version: {TimeSpinnerGame.Constants.GameVersion}, TsRandomizer Version: {Assembly.GetExecutingAssembly().GetName().Version}");
                    file.WriteLine($"Level: {LevelId}, Room: {RoomId}, Seed: {Seed}");
                    file.WriteLine();

                    WriteException(exception, file);

                    file.WriteLine("Settings:");
                    if (Settings != null)
                    {
                        file.WriteLine($"{GameSettingsLoader.ToJson(Settings, true)}");
                    }
                    else
                    {
                        file.WriteLine($"{Settings}");
                    }
                }
                catch (Exception e)
                {
                    try
                    {
                        file.WriteLine("Writing ExceptionLog Failure:");
                        WriteException(e, file);
                    }
                    catch
                    {
                    }
                }
            }
        }
Exemplo n.º 18
0
 public SettingCollection GetSettings() =>
 GameSettingsLoader.LoadSettingsFromSlotData(slotData);
Exemplo n.º 19
0
 internal static void SetSettings(this GameSave gameSave, SettingCollection settings)
 {
     ExceptionLogger.SetSettingsContext(settings);
     gameSave.SetValue(SaveFileSettingKey, GameSettingsLoader.ToJson(settings, false));
 }