示例#1
0
        public Form1()
        {
            InitializeComponent();

            var settings = new Settings();


            int total   = 20;
            int columns = (int)Math.Ceiling(Math.Sqrt(total));

            int xOffset = 165;
            int yOffset = 165;

            for (int i = 0; i < total; i++)
            {
                var y       = yOffset * (i / columns) + 20;
                var x       = xOffset * (i % columns) + 20;
                var control = new MemoryCardControl(new GameBoardForm(new StartForm()));
                control.Location = new System.Drawing.Point(x, y);
                this.Controls.Add(control);
            }

            this.Size = new Size(columns * xOffset + 50, (total + columns - 1) / columns * yOffset + 70);
            Shuffle();
        }
示例#2
0
        public GameBoardForm(StartForm startForm)
        {
            this.startForm = startForm;
            var settings = startForm.settings;

            this.Game = new Game(settings);
            this.Text = Game.CurrentPlayer.Name;

            InitializeComponent();


            thinkTimer.Interval = settings.PlayersTurnTimer * 1000;
            cardTimer.Interval  = settings.ShowCardTimer * 1000;


            int total   = settings.CardNumber;
            int columns = (int)Math.Ceiling(Math.Sqrt(total));


            int xOffset = 85;
            int yOffset = 85;

            for (int i = 0; i < total; i++)
            {
                var y       = yOffset * (i / columns) + 30;
                var x       = xOffset * (i % columns) + 20;
                var control = new MemoryCardControl(this);

                thinkTimer.Tick += new EventHandler(control.HandleThinkTimer);
                cardTimer.Tick  += new EventHandler(control.HandleCardtimer);
                control.Location = new System.Drawing.Point(x, y);
                this.Controls.Add(control);
            }
            closedCardList = this.Controls.OfType <MemoryCardControl>().ToList();

            var px = xOffset * columns + 30;
            var py = 40;

            for (int i = 0; i < settings.Playerlist.Length; i++)
            {
                var player      = Game.Players[i];
                var playerlabel = new Label();
                playerlabel.Text      = player.Name + " :  " + player.Score.ToString();
                playerlabel.Location  = new System.Drawing.Point(px, py);
                playerlabel.Name      = player.Name;
                playerlabel.ForeColor = player.Color;
                this.Controls.Add(playerlabel);

                py += 22;
            }

            this.Size = new Size(columns * xOffset + 150, (total + columns - 1) / columns * yOffset + 90);

            Shuffle();
        }