Пример #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            NoughtsAndCrossesGame     noughtsAndCrossesGame     = new NoughtsAndCrossesGame();
            NoughtsAndCrossesForm     noughtsAndCrossesForm     = new NoughtsAndCrossesForm(noughtsAndCrossesGame);
            NoughtsAndCrossesFormData noughtsAndCrossesFormData = new NoughtsAndCrossesFormData();

            noughtsAndCrossesForm.SetNotifyPropertyChanged(noughtsAndCrossesFormData);
            noughtsAndCrossesGame.SetFormData(noughtsAndCrossesFormData);

            Application.Run(noughtsAndCrossesForm);
        }
        public NoughtsAndCrossesForm(NoughtsAndCrossesGame noughtsAndCrossesGame)
        {
            InitializeComponent();
            _noughtsAndCrossesGame = noughtsAndCrossesGame;

            InitGameEventHandler();

            buttonApply.Click += (o, e) => {
                _noughtsAndCrossesGame.Apply();
            };

            checkMyFirstMove.CheckedChanged += (o, e) => {
                _noughtsAndCrossesGame.SetMyFirstMove(checkMyFirstMove.Checked);
            };

#if !FOR_JAVA
            buttonStartServer.Click += (o, e) => {
                _noughtsAndCrossesGame.StartServer();
            };
#endif

            buttonStopServer.Click += (o, e) => {
                _noughtsAndCrossesGame.StopServer();
            };

            buttonConnect.Click += (o, e) => {
                _noughtsAndCrossesGame.Apply();
                _noughtsAndCrossesGame.Connect(true, "");
            };

#if FOR_JAVA
            buttonCreateGame.Click += (o, e) => {
                _noughtsAndCrossesGame.Apply();
                _noughtsAndCrossesGame.Connect(true, "");
            };
            buttonJoinToGame.Click += (o, e) => {
                _noughtsAndCrossesGame.Connect(false, textBoxGameToken.Text);
            };
            comboBoxProtocols.SelectionChangeCommitted += (o, e) => {
                _noughtsAndCrossesGame.Protocol = (string)comboBoxProtocols.SelectedItem;
                if (_noughtsAndCrossesGame.Protocol == Connector.Protocols[0])
                {
                    buttonConnect.Visible    = true;
                    buttonCreateGame.Visible = false;
                    buttonJoinToGame.Visible = false;
                    textBoxGameToken.Visible = false;
                }
                else if (_noughtsAndCrossesGame.Protocol == Connector.Protocols[1])
                {
                    buttonConnect.Visible    = false;
                    buttonCreateGame.Visible = true;
                    buttonJoinToGame.Visible = true;
                    textBoxGameToken.Visible = true;
                }
            };
            comboBoxProtocols.SelectedItem = Connector.Protocols[1];
            buttonConnect.Visible          = false;
            buttonCreateGame.Visible       = true;
            buttonJoinToGame.Visible       = true;
            textBoxGameToken.Visible       = true;
#endif

            buttonDisConnect.Click += (o, e) => {
                _noughtsAndCrossesGame.DisConnect();
            };

            numericNumberToWin.Maximum = numericRowCellsCount.Value;
#if FOR_JAVA
            textBoxUserName.TextChanged += (o, e) => {
                _noughtsAndCrossesGame.SetUserName(textBoxUserName.Text);
            };
#endif

            TimeLimitedOperationsServiceSingleton.Create();
            TimeLimitedOperationsServiceSingleton.Start();
            timer.Tick += (o, e) => TimeLimitedOperationsServiceSingleton.Run();
            timer.Start();

            FormClosing += (o, e) => {
                _noughtsAndCrossesGame.Close();
            };

            FormClosed += (o, e) => {
                TimeLimitedOperationsServiceSingleton.Stop();
                TimeLimitedOperationsServiceSingleton.Delete();
            };
        }