public void Subscribe(NoughtsAndCrossesBoard noughtsAndCrossesBoard)
 {
     foreach (NoughtsAndCrossesButton button in noughtsAndCrossesBoard.NoughtsAndCrossesButtons)
     {
         button.Click += (sender, eventArgs) => { ButtonClicked(noughtsAndCrossesBoard); };
     }
 }
Пример #2
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 NoughtsAndCrossesBoardService(NoughtsAndCrossesBoard noughtsAndCrossesBoard)
 {
     _noughtsAndCrossesBoard = noughtsAndCrossesBoard;
 }
 private void ButtonClicked(NoughtsAndCrossesBoard noughtsAndCrossesBoard)
 {
     NoughtsAndCrossesBoardService noughtsAndCrossesBoardService = new NoughtsAndCrossesBoardService(noughtsAndCrossesBoard);
     noughtsAndCrossesBoardService.HasWon();
 }