Esempio n. 1
0
        public GroupSumWindow(GroupSumSettings settings)
            : base(settings.ScreenWidth,
			settings.ScreenHeight, GraphicsMode.Default, "Group Sum",
			settings.Fullscreen ? GameWindowFlags.Fullscreen : 0)
        {
            logger.Info("Initializing Group Sum game window");
            this.Settings = settings;

            Keyboard.KeyDown += Keyboard_KeyDown;

            plotSurface = new GroupSumPlotSurface(Settings.TargetNumber);

            maximumPossibleSum = Settings.Players * (GroupSumSettings.PlayerButtonCount - 1);
            plotSurface.SetPlotAxes(0, 1, 0, maximumPossibleSum + 1);

            CalculateSizesAndLoadFonts();
            SetStatusText(string.Format("Waiting for guesses ({0})", Settings.FirstRoundSeconds));

            // Open data file
            if (!string.IsNullOrEmpty(Settings.DataFilePath))
            {
                logger.DebugFormat("Opening data file at {0}", Settings.DataFilePath);
                dataWriter = new YAMLOutputStream(Settings.DataFilePath);
            }

            // Validate number of players
            var textureBasePath = Path.Combine(basePath, Path.Combine("etc", "player_images"));
            var playerImageCount = Directory.GetFiles(textureBasePath, "*.png").Length;

            if (Settings.Players > playerImageCount)
            {
                logger.WarnFormat("Too few player images are present, only allowing {0} players", playerImageCount);
                Settings.Players = playerImageCount;
            }

            players = Enumerable.Range(0, Settings.Players).Select(i => new Player(i)).ToArray();

            // Load textures
            logger.DebugFormat("Loading textures from {0}", textureBasePath);

            playerTextureIds = Textures.LoadPlayers(textureBasePath, Settings.Players).ToArray();

            // Output settings and initial player positions
            if (dataWriter != null)
            {
                dataWriter.WriteStartDocument();
                dataWriter.WriteHashSingle("Version", GroupSumSettings.FileVersion);

                dataWriter.WriteLine();
                dataWriter.WriteStartList("Settings");
                dataWriter.WriteHashSingle("Description", Settings.GameDescription);
                dataWriter.WriteHashSingle("Players", Settings.Players);
                dataWriter.WriteHashSingle("First Round Duration", Settings.FirstRoundSeconds);
                dataWriter.WriteHashSingle("Round Duration", Settings.RoundSeconds);
                dataWriter.WriteHashSingle("Target Number", Settings.TargetNumber);
                dataWriter.WriteHashSingle("Range", string.Format("{0} - {1}",
                    settings.MinNumber, settings.MaxNumber));

                dataWriter.WriteHashSingle("Show Numeric Feedback", Settings.ShowNumericFeedback);
                dataWriter.WriteHashSingle("Use Previous Input", Settings.UsePreviousRoundInput);

                dataWriter.WriteEndList();

                dataWriter.WriteLine();
                dataWriter.WriteStartList("Rounds");
                dataWriter.WriteComment("round, player, guess");
            }

            // Connect to input server
            if (Settings.Port > 0)
            {
                try
                {
                    inputClient.Connect(IPAddress.Loopback, Settings.Port);
                    inputClient.Client.BeginReceive(inputBuffer, 0, 2, SocketFlags.None,
                        inputClient_DataReceived, null);
                }
                catch (Exception ex)
                {
                    logger.Error("Failed to connect to input server", ex);
                }
            }

            secondsLeftInRound = Settings.FirstRoundSeconds;
            roundTimer = new System.Timers.Timer(1000);
            roundTimer.Elapsed += roundTimer_Elapsed;
            roundTimer.Start();
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            if (!log4net.LogManager.GetRepository().Configured)
            {
                log4net.Config.BasicConfigurator.Configure();
            }

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

            logger.Info("Starting up Group Sum");

            var settings = new GroupSumSettings()
            {
                IsDebugMode         = false,
                ScreenWidth         = DisplayDevice.Default.Width,
                ScreenHeight        = DisplayDevice.Default.Height,
                Fullscreen          = false,
                Players             = 0, Port = 0,
                FirstRoundSeconds   = 0, RoundSeconds = 10,
                ShowNumericFeedback = false, UsePreviousRoundInput = false
            };

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

            // Parse command-line options
            bool showHelp = false;
            int  rangeStart = 0, rangeEnd = 9;

            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) },

                { "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 },

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

                { "target-number=", "The number the group is attempting to guess (default: random)",
                  v => settings.TargetNumber = Convert.ToInt32(v) },

                { "first-round-seconds=", "Length of the first round in seconds (default: round-seconds)",
                  v => settings.FirstRoundSeconds = Convert.ToInt32(v) },

                { "round-seconds=", "Length of each round in seconds (default: 10)",
                  v => settings.RoundSeconds = Convert.ToInt32(v) },

                { "range-start=", "Start of number range, multiplied by player count (default: 0)",
                  v => rangeStart = Convert.ToInt32(v) },

                { "range-end=", "End of number range, multiplied by player count (default: 9)",
                  v => rangeEnd = Convert.ToInt32(v) },

                { "numeric-feedback", "If set, players are show how far they were from the answer (default: false)",
                  v => settings.ShowNumericFeedback = !string.IsNullOrEmpty(v) },

                { "previous-input", "If not set, player answers are reset each round (default: false)",
                  v => settings.UsePreviousRoundInput = !string.IsNullOrEmpty(v) }
            };

            options.Parse(args);

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

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

            // Flip range if necessary
            if (rangeStart > rangeEnd)
            {
                int rangeTemp = rangeStart;
                rangeStart = rangeEnd;
                rangeEnd   = rangeTemp;
            }

            settings.MinNumber = settings.Players * rangeStart;
            settings.MaxNumber = settings.Players * rangeEnd;

            if (settings.TargetNumber < 1)
            {
                settings.TargetNumber = new Random().Next(settings.MinNumber - 1, settings.MaxNumber) + 1;
            }

            if (settings.FirstRoundSeconds <= 0)
            {
                settings.FirstRoundSeconds = settings.RoundSeconds;
            }

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

            using (var game = new GroupSumWindow(settings))
            {
                // Start game
                logger.Debug("Running game loop");
                game.Run(0, 0);
            }
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            if (!log4net.LogManager.GetRepository().Configured)
            {
                log4net.Config.BasicConfigurator.Configure();
            }

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

            logger.Info("Starting up Group Sum");

            var settings = new GroupSumSettings()
            {
                IsDebugMode = false,
                ScreenWidth = DisplayDevice.Default.Width,
                ScreenHeight = DisplayDevice.Default.Height,
                Fullscreen = false,
                Players = 0, Port = 0,
                FirstRoundSeconds = 0, RoundSeconds = 10,
                ShowNumericFeedback = false, UsePreviousRoundInput = false
            };

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

            // Parse command-line options
            bool showHelp = false;
            int rangeStart = 0, rangeEnd = 9;

            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) },

                { "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 },

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

                { "target-number=", "The number the group is attempting to guess (default: random)",
                    v => settings.TargetNumber = Convert.ToInt32(v) },

                { "first-round-seconds=", "Length of the first round in seconds (default: round-seconds)",
                    v => settings.FirstRoundSeconds = Convert.ToInt32(v) },

                { "round-seconds=", "Length of each round in seconds (default: 10)",
                    v => settings.RoundSeconds = Convert.ToInt32(v) },

                { "range-start=", "Start of number range, multiplied by player count (default: 0)",
                    v => rangeStart = Convert.ToInt32(v) },

                { "range-end=", "End of number range, multiplied by player count (default: 9)",
                    v => rangeEnd = Convert.ToInt32(v) },

                { "numeric-feedback", "If set, players are show how far they were from the answer (default: false)",
                    v => settings.ShowNumericFeedback = !string.IsNullOrEmpty(v) },

                { "previous-input", "If not set, player answers are reset each round (default: false)",
                    v => settings.UsePreviousRoundInput = !string.IsNullOrEmpty(v) }
            };

            options.Parse(args);

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

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

            // Flip range if necessary
            if (rangeStart > rangeEnd)
            {
                int rangeTemp = rangeStart;
                rangeStart = rangeEnd;
                rangeEnd = rangeTemp;
            }

            settings.MinNumber = settings.Players * rangeStart;
            settings.MaxNumber = settings.Players * rangeEnd;

            if (settings.TargetNumber < 1)
            {
                settings.TargetNumber = new Random().Next(settings.MinNumber - 1, settings.MaxNumber) + 1;
            }

            if (settings.FirstRoundSeconds <= 0)
            {
                settings.FirstRoundSeconds = settings.RoundSeconds;
            }

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

            using (var game = new GroupSumWindow(settings))
            {
                // Start game
                logger.Debug("Running game loop");
                game.Run(0, 0);
            }
        }
Esempio n. 4
0
        public GroupSumWindow(GroupSumSettings settings) : base(settings.ScreenWidth,
                                                                settings.ScreenHeight, GraphicsMode.Default, "Group Sum",
                                                                settings.Fullscreen ? GameWindowFlags.Fullscreen : 0)
        {
            logger.Info("Initializing Group Sum game window");
            this.Settings = settings;

            Keyboard.KeyDown += Keyboard_KeyDown;

            plotSurface = new GroupSumPlotSurface(Settings.TargetNumber);

            maximumPossibleSum = Settings.Players * (GroupSumSettings.PlayerButtonCount - 1);
            plotSurface.SetPlotAxes(0, 1, 0, maximumPossibleSum + 1);

            CalculateSizesAndLoadFonts();
            SetStatusText(string.Format("Waiting for guesses ({0})", Settings.FirstRoundSeconds));

            // Open data file
            if (!string.IsNullOrEmpty(Settings.DataFilePath))
            {
                logger.DebugFormat("Opening data file at {0}", Settings.DataFilePath);
                dataWriter = new YAMLOutputStream(Settings.DataFilePath);
            }

            // Validate number of players
            var textureBasePath  = Path.Combine(basePath, Path.Combine("etc", "player_images"));
            var playerImageCount = Directory.GetFiles(textureBasePath, "*.png").Length;

            if (Settings.Players > playerImageCount)
            {
                logger.WarnFormat("Too few player images are present, only allowing {0} players", playerImageCount);
                Settings.Players = playerImageCount;
            }

            players = Enumerable.Range(0, Settings.Players).Select(i => new Player(i)).ToArray();

            // Load textures
            logger.DebugFormat("Loading textures from {0}", textureBasePath);

            playerTextureIds = Textures.LoadPlayers(textureBasePath, Settings.Players).ToArray();

            // Output settings and initial player positions
            if (dataWriter != null)
            {
                dataWriter.WriteStartDocument();
                dataWriter.WriteHashSingle("Version", GroupSumSettings.FileVersion);

                dataWriter.WriteLine();
                dataWriter.WriteStartList("Settings");
                dataWriter.WriteHashSingle("Description", Settings.GameDescription);
                dataWriter.WriteHashSingle("Players", Settings.Players);
                dataWriter.WriteHashSingle("First Round Duration", Settings.FirstRoundSeconds);
                dataWriter.WriteHashSingle("Round Duration", Settings.RoundSeconds);
                dataWriter.WriteHashSingle("Target Number", Settings.TargetNumber);
                dataWriter.WriteHashSingle("Range", string.Format("{0} - {1}",
                                                                  settings.MinNumber, settings.MaxNumber));

                dataWriter.WriteHashSingle("Show Numeric Feedback", Settings.ShowNumericFeedback);
                dataWriter.WriteHashSingle("Use Previous Input", Settings.UsePreviousRoundInput);

                dataWriter.WriteEndList();

                dataWriter.WriteLine();
                dataWriter.WriteStartList("Rounds");
                dataWriter.WriteComment("round, player, guess");
            }

            // Connect to input server
            if (Settings.Port > 0)
            {
                try
                {
                    inputClient.Connect(IPAddress.Loopback, Settings.Port);
                    inputClient.Client.BeginReceive(inputBuffer, 0, 2, SocketFlags.None,
                                                    inputClient_DataReceived, null);
                }
                catch (Exception ex)
                {
                    logger.Error("Failed to connect to input server", ex);
                }
            }

            secondsLeftInRound  = Settings.FirstRoundSeconds;
            roundTimer          = new System.Timers.Timer(1000);
            roundTimer.Elapsed += roundTimer_Elapsed;
            roundTimer.Start();
        }