Esempio n. 1
0
        public void Create(TicTacToe.TicTacToe game, TableLayoutPanel tLP, EventHandler btnClick)
        {
            tLP.ColumnStyles.Clear();
            tLP.RowStyles.Clear();

            int column = game.Board.Width;
            int row    = game.Board.Height;

            tLP.ColumnCount = column;
            tLP.RowCount    = row;

            for (int i = 0; i <= column; i++)
            {
                tLP.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25F));
            }
            for (int i = 0; i <= row; i++)
            {
                tLP.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
            }

            Button tempBtn;

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < column; j++)
                {
                    tempBtn      = new Button();
                    tempBtn.Dock = DockStyle.Fill;
                    //tempBtn.FlatAppearance.BorderSize = 0;
                    //tempBtn.FlatStyle = FlatStyle.Flat;



                    tempBtn.UseVisualStyleBackColor = true;

                    tempBtn.Click += btnClick;
                    tempBtn.Margin = new Padding(1);
                    tLP.Controls.Add(tempBtn, j, i);
                    list.Add(new Point(i, j), tempBtn);
                }
            }
        }
Esempio n. 2
0
        public void RefereeTest(string boardString, bool isWin)
        {
            var ticTest = new TicTacToe.TicTacToe();

            //To simplify the logic, use int to define the board size, rather than MaxX and MaxY
            var myBoard = new string[3, 3];

            //Substring the string in TestCase, generate my board
            for (var i = 0; i < 3; i++)
            {
                for (var j = 0; j < 3; j++)
                {
                    myBoard[i, j] = boardString.Substring(i * 3 + j, 1);
                }
            }

            //Function test
            var result = ticTest.Referee(myBoard);

            //Result
            Assert.AreEqual(isWin, result);
        }