Exemple #1
0
        public static void InitializeTheme()
        {
#if DEBUG
            Stopwatch sw = new Stopwatch();
            sw.Start();
#endif

            SystemTheme = (Visibility)Resources["PhoneDarkThemeVisibility"] == Visibility.Visible
                ? Themes.Dark
                : Themes.Light;
            CurrentTheme = Themes.GetTheme(ThemeFileName, SystemTheme);

            // ResourceDictionary
            Uri sourceUri = CurrentTheme.ResourcesPath;
            ResourceDictionary appTheme = Resources.MergedDictionaries[0];
            ResourceDictionary theme    = new ResourceDictionary
            {
                Source = sourceUri
            };

            // Čísla
            foreach (var ck in theme.Where(x => x.Value is double))
            {
                ReplaceDouble(appTheme, (string)ck.Key, (double)ck.Value);
            }

            // Barvy
            foreach (var ck in theme.Where(x => x.Value is Color))
            {
                ReplaceColor(appTheme, (string)ck.Key, (Color)ck.Value);
            }

            // Brushe
            foreach (var ck in theme.Where(x => x.Value is SolidColorBrush))
            {
                ReplaceBrush(appTheme, (string)ck.Key, (SolidColorBrush)ck.Value);
            }

            // Accent barva
            if (ThemeColor != Theme.EmptyColor)
            {
                SetAccentColor(appTheme, ThemeColor);
            }
            else
            {
                SetAccentColor(appTheme, CurrentTheme.DefaultColor);
            }

            // RootFrame
            if (App.RootFrame != null && Resources.Contains("BackgroundBrush"))
            {
                SolidColorBrush rootFrameBackground = Resources["BackgroundBrush"] as SolidColorBrush;
                if (rootFrameBackground != null)
                {
                    App.RootFrame.Background = rootFrameBackground;
                }
            }

            // AppBar
            if (Resources.Contains("SystemTrayBackgroundColor") && Resources.Contains("SystemTrayForegroundColor"))
            {
                _appBarBackground = (Color)Resources["SystemTrayBackgroundColor"];
                _appBarForeground = (Color)Resources["SystemTrayForegroundColor"];
            }

            // Speciální
            if (Resources.Contains("DarkerAccentBrush"))
            {
                Color color = (Color)Resources["AccentColor"];
                ((SolidColorBrush)Resources["DarkerAccentBrush"]).Color = color.Lerp(Colors.Black, 0.12f);
            }
            if (Resources.Contains("DarkerTasksListHeaderBackgroundBrush"))
            {
                Color color = (Color)Resources["TasksListHeaderBackgroundColor"];
                ((SolidColorBrush)Resources["DarkerTasksListHeaderBackgroundBrush"]).Color = color.Lerp(Colors.Black, 0.1f);
            }

#if DEBUG
            sw.Stop();
            Debug.WriteLine("## CHANGE THEME RESOURCE: ELAPSED TOTAL = {0}", sw.Elapsed);
#endif
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            if (!log4net.LogManager.GetRepository().Configured)
            {
                log4net.Config.BasicConfigurator.Configure();
            }

            log4net.ILog logger = log4net.LogManager.GetLogger("Flatland.Program");

            logger.Info("Starting up Flatland");

            var settings = new FlatlandSettings()
            {
                IsDebugMode       = false,
                ScreenWidth       = DisplayDevice.Default.Width,
                ScreenHeight      = DisplayDevice.Default.Height,
                Fullscreen        = false,
                Tiles             = 0, Players = 0, Port = 0, PlayerSort = PlayerSort.Random,
                CollisionBehavior = CollisionBehavior.Allow,
                GameType          = FlatlandGameType.Normal
            };

            logger.Debug("Parsing command-line options");

            // Parse command-line options
            bool showHelp = false;

            var options = new OptionSet()
            {
                { "h|?|help", "Show this help message",
                  v => showHelp = !string.IsNullOrEmpty(v) },

                { "debug", "Enable debug mode (random commands can be issued with 'R')",
                  v => settings.IsDebugMode = !string.IsNullOrEmpty(v) },

                { "screen-width=", "Screen width in pixels (default: current)",
                  v => settings.ScreenWidth = Convert.ToInt32(v) },

                { "screen-height=", "Screen heigh in pixels (default: current)",
                  v => settings.ScreenHeight = Convert.ToInt32(v) },

                { "full-screen", "Enables full-screen mode",
                  v => settings.Fullscreen = !string.IsNullOrEmpty(v) },

                { "tiles=", "Number of tiles in a row or column (default: maximum)",
                  v => settings.Tiles = Convert.ToInt32(v) },

                { "players=", "Number of players (required)",
                  v => settings.Players = Convert.ToInt32(v) },

                { "port=", "Network port of input server",
                  v => settings.Port = Convert.ToInt32(v) },

                { "data-file=", "Path to the output data file",
                  v => settings.DataFilePath = v },

                { "player-sort=", "Initial arrangement of players (Random, SpreadOut, Clustered)",
                  v => settings.PlayerSort = (PlayerSort)Enum.Parse(typeof(PlayerSort), v) },

                { "collision-behavior=", "Behavior for when players collide (Block, Allow)",
                  v => settings.CollisionBehavior = (CollisionBehavior)Enum.Parse(typeof(CollisionBehavior), v) },

                { "team-info=", "Information about a team in the format [Index,Theme,MoveSeconds,Kind,Wrap] (Kind = Normal, Predator, Prey)",
                  v => settings.Teams.AddRange(CLIObject.FromString <FlatlandTeamInfo>(v, "TeamIndex", "ThemeName", "MoveSeconds", "Kind", "WrappedMovement", "ScoringSystem")) },

                { "fixed-tiles=", "List of fixed tiles in the format [X1,Y1][X2,Y2]...",
                  v => settings.FixedTiles.UnionWith(CLIObject.FromString <FixedTile>(v, "X", "Y")) },

                { "description=", "Text to display at the top of the screen during gameplay",
                  v => settings.GameDescription = v },

                { "game-type=", "Type of Flatland game to play (Normal, NQueens)",
                  v => settings.GameType = (FlatlandGameType)Enum.Parse(typeof(FlatlandGameType), v) }
            };

            options.Parse(args);

            if (showHelp)
            {
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            if (settings.Players < 1)
            {
                logger.Fatal("players option is required");
                return;
            }

            if (settings.Teams.Count < 1)
            {
                logger.Fatal("at least team one is required");
                return;
            }
            else
            {
                // Set team names based on index
                foreach (var team in settings.Teams)
                {
                    team.TeamName = ((char)(((int)'A') + team.TeamIndex)).ToString();
                    team.Theme    = Themes.GetTheme((ThemeColor)Enum.Parse(typeof(ThemeColor), team.ThemeName));
                }
            }

            // Calculate number of pixels
            var requestedPixels = settings.Tiles * settings.Tiles;

            if (requestedPixels < settings.Players)
            {
                settings.Tiles = (int)Math.Ceiling(Math.Sqrt(settings.Players));
                logger.WarnFormat("Setting number of tiles to {0}x{0} to accomodate players", settings.Tiles);
            }

            // Make sure there are enough tiles for all players
            if ((settings.CollisionBehavior == CollisionBehavior.Block) &&
                (((settings.Tiles * settings.Tiles) - settings.FixedTiles.Count) < settings.Players))
            {
                logger.Fatal("Not enough tiles for players!");
                return;
            }

            if (settings.IsDebugMode)
            {
                logger.Info("Debug mode is enabled");
            }

            using (var game = new FlatlandWindow(settings))
            {
                // Start game
                logger.Debug("Running game loop");
                game.Run(0, 0);
            }
        }