Exemplo n.º 1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            NoughtsAndCrossesBoard board = new NoughtsAndCrossesBoard();
            board.Text = "Noughts and Crosses";
            board.Width = Settings.mainFormWidth;
            board.Height = Settings.mainFormHeight;

            int x = 0, y = 0;

            for (int i = 1; i <= Settings.noOfButtons; i++)
            {
                NoughtsAndCrossesButton button = new NoughtsAndCrossesButton();
                button.Id = i;
                button.Value = null;
                button.Width = Settings.buttonWidth;
                button.Height = Settings.buttonHeight;
                button.Left = x;
                button.Top = y;
                x = (i % Settings.noOfRowsAndColumns) == 0 ? 0 : x + Settings.buttonWidth;
                y = (i % Settings.noOfRowsAndColumns) == 0 ? (y + Settings.buttonHeight) : y;
                board.NoughtsAndCrossesButtons.Add(button);
                board.Controls.Add(button);
                NoughtsAndCrossesButtonListener Buttonlistener = new NoughtsAndCrossesButtonListener();
                Buttonlistener.Subscribe(button);
            }

            //create the board listener
            NoughtsAndCrossesBoardListener BoardListener = new NoughtsAndCrossesBoardListener();
            BoardListener.Subscribe(board);

            Application.Run(board);
        }
 public void Subscribe(NoughtsAndCrossesButton noughtsAndCrossesButton)
 {
     noughtsAndCrossesButton.Click += new System.EventHandler(ClickedIt);
 }
 public NoughtsAndCrossesButtonService(NoughtsAndCrossesButton noughtsAndCrossesButton)
 {
     _noughtsAndCrossesButton = noughtsAndCrossesButton;
 }