// *** CONSTRUCTION *** // #region Constructor public GameForm(Game game) { Game = game; Theme = ThemeFactory.CreateTheme(game); moveDescriptions = new List <string>(); currentMoveNumber = 0; gameStarted = false; currentEval = null; ReviewMode = false; InitializeComponent(); boardControl.Initialize(game, game.Board, Theme, this); mbControl.Initialize(game, game.Board, Theme); ehControl.Initialize(game, Theme); menuitem_ComputerPlays0.Text = "Computer Plays " + game.PlayerNames[0]; menuitem_ComputerPlays1.Text = "Computer Plays " + game.PlayerNames[1]; updateTheme(); game.MovePlayed += MovePlayed; game.ThinkingCallback += updateThinking; if (game.Match != null) { game.Match.HumanEnabled += HumanEnabled; if (game.Match.GetPlayer(0) != null) { game.Match.GetPlayer(0).StartedThinking += ThinkingStartedPlayer0; game.Match.GetPlayer(0).StoppedThinking += ThinkingStopped; } if (game.Match.GetPlayer(1) != null) { game.Match.GetPlayer(1).StartedThinking += ThinkingStartedPlayer1; game.Match.GetPlayer(1).StoppedThinking += ThinkingStopped; } } debugForm = new DebugForm(Game.MessageLog, this); debugForm.Visible = false; }
public static BoardPresentation CreatePresentation(Game game, bool smallPreview = false) { return(CreatePresentation(game, ThemeFactory.CreateTheme(game), smallPreview)); }
private void GameVariablesForm_Load(object sender, EventArgs e) { // Determine background color - this is typically the // first square color (light square color) but if that // color isn't light enough, we will scale it up to make // it lighter. Things look bad if the backgrounds for // all the tool windows aren't fairly light Theme theme = ThemeFactory.CreateTheme(game); Color WindowBackgroundColor = theme.ColorScheme.SquareColors[0]; int brightness = (WindowBackgroundColor.R + WindowBackgroundColor.G + WindowBackgroundColor.B) / 3; if (brightness < 250) { double scaleFactor = 250.0 / (double)brightness; WindowBackgroundColor = Color.FromArgb( (int)(WindowBackgroundColor.R + ((255 - WindowBackgroundColor.R) * (scaleFactor - 1.0))), (int)(WindowBackgroundColor.G + ((255 - WindowBackgroundColor.G) * (scaleFactor - 1.0))), (int)(WindowBackgroundColor.B + ((255 - WindowBackgroundColor.B) * (scaleFactor - 1.0)))); } BackColor = WindowBackgroundColor; int unassignedCount = 0; PropertyInfo[] properties = game.GetType().GetProperties(); foreach (PropertyInfo property in properties) { object[] attributes = property.GetCustomAttributes(typeof(GameVariableAttribute), false); if (attributes.Length > 0) { if (property.PropertyType == typeof(ChoiceVariable)) { ChoiceVariable choice = (ChoiceVariable)property.GetValue(game, null); if (choice.Choices.Count > 0 && choice.Value == null) { // this property is unassigned if (unassignedCount == 0) { choiceProperty1 = property; lblGameVariable1.Visible = true; lblGameVariable1.Text = ConvertVariableNameToDisplay(property.Name); pickVariable1.Visible = true; foreach (string choicename in choice.Choices) { pickVariable1.Items.Add(choicename); } if (choice.DefaultValue != null) { pickVariable1.SelectedItem = choice.DefaultValue; } else { pickVariable1.SelectedIndex = Program.Random.Next(pickVariable1.Items.Count); } } else if (unassignedCount == 1) { choiceProperty2 = property; lblGameVariable2.Visible = true; lblGameVariable2.Text = ConvertVariableNameToDisplay(property.Name); pickVariable2.Visible = true; foreach (string choicename in choice.Choices) { pickVariable2.Items.Add(choicename); } if (choice.DefaultValue != null) { pickVariable2.SelectedItem = choice.DefaultValue; } else { pickVariable2.SelectedIndex = Program.Random.Next(pickVariable2.Items.Count); } } else { throw new Exception("Not supported - too many unassigned variables"); } unassignedCount++; } } else if (property.PropertyType == typeof(IntRangeVariable)) { IntRangeVariable val = (IntRangeVariable)property.GetValue(game, null); if (val.Value == null) { // this property is unassigned if (unassignedCount == 0) { intProperty1 = property; lblGameVariable1.Visible = true; lblGameVariable1.Text = ConvertVariableNameToDisplay(property.Name); txtVariable1.Visible = true; val.Value = Program.Random.Next((int)val.MaxValue - (int)val.MinValue + 1) + (int)val.MinValue; txtVariable1.Text = val.Value.ToString(); unassignedCount++; } } } } } if (unassignedCount == 1) { lblGameVariable1.Location = new Point(lblGameVariable1.Location.X, lblGameVariable1.Location.Y + 18); txtVariable1.Location = new Point(txtVariable1.Location.X, txtVariable1.Location.Y + 18); pickVariable1.Location = new Point(pickVariable1.Location.X, pickVariable1.Location.Y + 18); } finishedLoading = true; UpdatePreviewImage(); }