Exemple #1
0
        public GameForm(IUIGame game)
        {
            InitializeComponent();
            Initialize(game);

            UpdateBoard();
        }
Exemple #2
0
        /// <summary>
        /// Serializes the game state and saves it to filePath
        /// </summary>
        /// <param name="game">game object to serialize</param>
        /// <param name="filePath">where to save</param>
        public static void Serialize(IUIGame game, string filePath)
        {
            GameState state = new GameState(game);

            IFormatter formatter = new BinaryFormatter();
            Stream     stream    = new FileStream(filePath, FileMode.Create, FileAccess.Write);

            formatter.Serialize(stream, state);
            stream.Close();
        }
Exemple #3
0
        /// <summary>
        /// Deserializes the game from a file.
        /// </summary>
        /// <param name="filePath">file to deserialize</param>
        /// <returns>Game that is ready to run</returns>
        public static IUIGame Deserialize(string filePath)
        {
            IFormatter formatter = new BinaryFormatter();
            Stream     stream    = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            GameState  gameState = (GameState)formatter.Deserialize(stream);
            IUIGame    game      = gameState.game;

            GameSettings.LoadSerializedData(gameState.settings);
            Time.Configure(game.Players.Count);
            return(game);
        }
Exemple #4
0
        /// <summary>
        /// Called from constructor ot initialize the form
        /// </summary>
        /// <param name="game"></param>
        private void Initialize(IUIGame game)
        {
            this.SuspendLayout();
            this.game      = game;
            playerDisplays = new List <PlayerDisplay>();

            layout = ThebesUI.Layout.ParseLayout("layout.json");

            // player displays
            foreach (IPlayer player in game.Players)
            {
                PlayerDisplay pd = new PlayerDisplay();
                pd.Width  = 368;
                pd.Height = 152;
                pd.Initialize(player, layout, game.Colors[player]);
                playerDisplays.Add(pd);
                flpPlayerDisplay.Controls.Add(pd);
            }

            // background
            pBoard.BackgroundImage = Image.FromFile(UIConfig.IMG_FOLDER + "board.jpg");
            Controls.Add(pBoard);

            // display cards
            Rectangle pbDims;

            for (int i = 0; i < displayCards.Length; i++)
            {
                pbDims          = layout.DisplayedCards[i];
                displayCards[i] = new PictureBox()
                {
                    Location  = pbDims.topLeft,
                    Width     = pbDims.Width,
                    Height    = pbDims.Height,
                    Visible   = true,
                    SizeMode  = PictureBoxSizeMode.StretchImage,
                    BackColor = Color.Transparent
                };
                displayCards[i].Click += pbCard_Click;
                pBoard.Controls.Add(displayCards[i]);
            }

            // exhibitions
            for (int i = 0; i < exhibitions.Length; i++)
            {
                pbDims         = layout.DisplayedExhibitions[i];
                exhibitions[i] = new PictureBox()
                {
                    Location  = pbDims.topLeft,
                    Width     = pbDims.Width,
                    Height    = pbDims.Height,
                    Visible   = true,
                    SizeMode  = PictureBoxSizeMode.StretchImage,
                    BackColor = Color.Transparent
                };
                exhibitions[i].Click += pbExhibition_Click;
                pBoard.Controls.Add(exhibitions[i]);
            }

            //tooltips
            for (int i = 0; i < cardToolTips.Length; i++)
            {
                cardToolTips[i] = new ToolTip();
            }
            for (int i = 0; i < exhibitionToolTips.Length; i++)
            {
                exhibitionToolTips[i] = new ToolTip();
            }

            // week counter
            smallPieces = new Dictionary <IPlayer, TransparentPictureBox>();
            foreach (IPlayer player in game.Players)
            {
                pbDims = layout.WeekCounter[0];
                smallPieces.Add(player, new TransparentPictureBox()
                {
                    Location  = pbDims.RectanglePositionCenter(34, 30),
                    Width     = 34,
                    Height    = 30,
                    Visible   = true,
                    SizeMode  = PictureBoxSizeMode.StretchImage,
                    BackColor = Color.Transparent,
                    Image     = Image.FromFile(UIConfig.IMG_FOLDER + $"p_small_{game.Colors[player]}.png")
                });
                pBoard.Controls.Add(smallPieces[player]);
            }

            // player pieces
            bigPieces = new Dictionary <IPlayer, TransparentPictureBox>();
            foreach (IPlayer player in game.Players)
            {
                pbDims = layout.Places[player.CurrentPlace.Name];
                bigPieces.Add(player, new TransparentPictureBox()
                {
                    Location  = pbDims.RectanglePositionCenter(35, 71),
                    Width     = 35,
                    Height    = 71,
                    Visible   = true,
                    SizeMode  = PictureBoxSizeMode.StretchImage,
                    BackColor = Color.Transparent,
                    Image     = Image.FromFile(UIConfig.IMG_FOLDER + $"p_big_{game.Colors[player]}.png")
                });
                bigPieces[player].Click += new EventHandler(pBoard_Click); // to enable click through
                pBoard.Controls.Add(bigPieces[player]);
            }

            // bonus tokens
            bonusTokens = new Dictionary <IDigSite, TransparentPictureBox>();
            foreach (KeyValuePair <IDigSite, IToken> kvp  in game.BonusTokens)
            {
                if (kvp.Value != null)
                {
                    ITokenView tokenView = UIGame.ToView(kvp.Value);

                    pbDims = layout.Places[kvp.Key.Name];
                    bonusTokens.Add(kvp.Key, new TransparentPictureBox()
                    {
                        Location  = pbDims.RectanglePositionCenter(45, 45),
                        Width     = 45,
                        Height    = 45,
                        Visible   = true,
                        SizeMode  = PictureBoxSizeMode.StretchImage,
                        BackColor = Color.Transparent,
                        Image     = Image.FromFile(UIConfig.IMG_FOLDER + tokenView.FileName)
                    });
                    bonusTokens[kvp.Key].Click += new EventHandler(pBoard_Click); // to enable click through
                    pBoard.Controls.Add(bonusTokens[kvp.Key]);
                }
            }

            // year counter
            pbDims      = layout.YearCounter[(game.ActivePlayer.Time.CurrentYear % 10) - 1];
            yearCounter = new TransparentPictureBox()
            {
                Location  = pbDims.RectanglePositionCenter(34, 30),
                Width     = 34,
                Height    = 30,
                Visible   = true,
                SizeMode  = PictureBoxSizeMode.StretchImage,
                BackColor = Color.Transparent,
                Image     = Image.FromFile(UIConfig.IMG_FOLDER + $"p_small_black.png")
            };
            pBoard.Controls.Add(yearCounter);

            UpdateBoard();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ResumeLayout(false);
        }
Exemple #5
0
 public GameState(IUIGame game)
 {
     this.game = game;
     settings  = new GameSettingsSerializable();
 }