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 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();
        }