示例#1
0
		public void TestExtenderMethods ()
		{
			TableLayoutPanel p = new TableLayoutPanel ();
			Control c = new Button ();

			Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetCellPosition (c), "A1");
			Assert.AreEqual (-1, p.GetColumn (c), "A2");
			Assert.AreEqual (1, p.GetColumnSpan (c), "A3");
			Assert.AreEqual (-1, p.GetRow (c), "A4");
			Assert.AreEqual (1, p.GetRowSpan (c), "A5");

			p.SetCellPosition (c, new TableLayoutPanelCellPosition (1, 1));
			Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetCellPosition (c), "A6");

			p.SetColumn (c, 2);
			Assert.AreEqual (2, p.GetColumn (c), "A7");
			p.SetRow (c, 2);
			Assert.AreEqual (2, p.GetRow (c), "A9");

			p.SetColumnSpan (c, 2);
			Assert.AreEqual (2, p.GetColumnSpan (c), "A8");


			p.SetRowSpan (c, 2);
			Assert.AreEqual (2, p.GetRowSpan (c), "A10");

			Assert.AreEqual (new TableLayoutPanelCellPosition (2, 2), p.GetCellPosition (c), "A11");

			// ???????
			//Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetPositionFromControl (c), "A12");
			//Assert.AreEqual (c, p.GetControlFromPosition(0, 0), "A13");
		}
示例#2
0
        /// <summary>
        /// Gets a control from a position in a TableLayoutPanel.
        /// Note: when no control was found, each control is checked on it's own because of bugs in the layout engine from Microsoft.
        /// </summary>
        /// <param name="This">This TableLayoutPanel.</param>
        /// <param name="column">The column.</param>
        /// <param name="row">The row.</param>
        /// <returns>The control or <c>null</c>.</returns>
        public static Control GetControlFromPositionFixed(this TableLayoutPanel This, int column, int row)
        {
#if NET35
            Debug.Assert(This != null);
#else
            Contract.Requires(This != null);
#endif
            var result = This.GetControlFromPosition(column, row);
            if (result != null)
            {
                return(result);
            }

#if DEBUG
            // This one's for debugging only
            var allControls = This.Controls.Cast <Control>().Where(c => c != null).ToDictionary(control => control, control => Tuple.Create(This.GetColumn(control), This.GetRow(control)));
#endif

            return((
                       from control in This.Controls.Cast <Control>().Where(c => c != null)
                       where This.GetColumn(control) == column && This.GetRow(control) == row
                       select(control)
                       ).FirstOrDefault());
        }
 /// <summary>
 /// Method that detects the click on the form and delegates this action to the game. There is no game logic here.
 /// </summary>
 public void ClickOnPlace(object sender, MouseEventArgs e)
 {
     Engine.environment.TryAddFood(tableLayoutPanel1.GetColumn((PictureBox)sender));
 }
示例#4
0
文件: game.cs 项目: mapplet/Chess
        private void killedPieces_MouseClick(object sender, MouseEventArgs e)
        {
            if (pawnChangable)
            {
                Control c = (Control)sender;
                TableLayoutPanel teamBox = new TableLayoutPanel();
                if (currentState.getMyTeam() == (int)team.black)
                    teamBox = this.blackTeamPanel;
                else if (currentState.getMyTeam() == (int)team.white)
                    teamBox = this.whiteTeamPanel;

                int index = (teamBox.GetRow(c) * 2) + teamBox.GetColumn(c);
                if (gameboard.getDead(currentState.getMyTeam()).Count() > index)
                {
                    Piece currentPiece = gameboard.getDead(currentState.getMyTeam())[index];
                    if (gameboard.tradePawn(previousPiece, currentPiece))
                    {
                        if (gameboard.checkChessMate(currentState.getMyTeam()) == (int)moveResult.chessMate)
                        {
                            DialogResult result = MessageBox.Show("Chessmate! You win.\n\nPlay again?", "Chess - Message", MessageBoxButtons.YesNo);
                            promptNewGame(result);
                            return;
                        }
                        pawnChangable = false;
                        previousPiece = null;
                        AIOpponent.Move(gameboard, currentState);
                        updateBoard();
                        if (gameboard.checkChessMate(currentState.getOpponentTeam()) == (int)moveResult.chessMate)
                        {
                            DialogResult result = MessageBox.Show("Chessmate! You loose.\n\nPlay again?", "Chess - Message", MessageBoxButtons.YesNo);
                            promptNewGame(result);
                            return;
                        }
                    }
                }
            }
        }