Esempio n. 1
0
        DelegateMove dto;                                     //델리게이트 초기화
        private void btnnew_Click(object sender, EventArgs e) //객체생성 버튼을 눌렀을 때 발생하는 이벤트 설정
        {
            int   x = Convert.ToInt32(txtX.Text);             //txtX창으로 입력받은 값을 정수형으로 변환하여 x좌표변수에 저장
            int   y = Convert.ToInt32(txtY.Text);             //txtY창으로 입력받은 값을 정수형으로 변환하여 y좌표변수에 저장
            Point p = new Point(x, y);                        //델리게이트 객체 생성, 객체를 매개변수로 받는 포인트 객체 선언 및 설정

            pArr[PointArray.count++] = p;                     //인덱서를 이용하여 count번째에 객체로 초기화 후 인덱스 증가
            dto += new DelegateMove(p.MoveTo);                //델리게이트에 객체 p의 MoveTo메서드연결
        }
Esempio n. 2
0
        public GamePlayViewModel(string name, string typoOfGame)
        {
            _serverWorker = ServerWorker.NewInstance();
            TypeOfGame    = typoOfGame;
            Condition     = "Visible";
            Name          = name;

            if (TypeOfGame == "With user")
            {
                IsVisibleGame    = false;
                IsVisibleSpinner = true;
                _delegateMove    = MoveForGameWithUserAsync;
            }
            else
            {
                IsVisibleGame     = true;
                IsVisibleSpinner  = false;
                OpponentName      = "Компьютер";
                _gameLogic        = new GameLogic(this);
                FirstGamerSymbol  = _gameLogic.GamerSymbol;
                SecondGamerSymbol = _gameLogic.ComputerSymbol;
                TextNotification  = $"Вы играете за {FirstGamerSymbol}";
                ShowNotificationAsync();
                if (FirstGamerSymbol == "X")
                {
                    GameInformation = FIRST_PLAYER_TURN;
                    IsEnable        = true;
                }
                else
                {
                    GameInformation = "Ожидание хода от компьютера";
                }
                _delegateMove = MoveForGameWithComputer;
            }
            IsVisibleCancel = false;

            OneOneSquare     = "";
            OneTwoSquare     = "";
            OneThreeSquare   = "";
            TwoOneSquare     = "";
            TwoTwoSquare     = "";
            TwoThreeSquare   = "";
            ThreeOneSquare   = "";
            ThreeTwoSquare   = "";
            ThreeThreeSquare = "";

            OneOneBack     = (Brush) new BrushConverter().ConvertFromString("Transparent");
            OneTwoBack     = (Brush) new BrushConverter().ConvertFromString("Transparent");
            OneThreeBack   = (Brush) new BrushConverter().ConvertFromString("Transparent");
            TwoOneBack     = (Brush) new BrushConverter().ConvertFromString("Transparent");
            TwoTwoBack     = (Brush) new BrushConverter().ConvertFromString("Transparent");
            TwoThreeBack   = (Brush) new BrushConverter().ConvertFromString("Transparent");
            ThreeOneBack   = (Brush) new BrushConverter().ConvertFromString("Transparent");
            ThreeTwoBack   = (Brush) new BrushConverter().ConvertFromString("Transparent");
            ThreeThreeBack = (Brush) new BrushConverter().ConvertFromString("Transparent");
        }
Esempio n. 3
0
        public bool Move(Square[,] massSquare, DelegateMove SetNewPos)
        {
            bool move = false;

            for (int y = 0; y < 4; y++)
            {
                for (int x = 1; x < 4; x++)
                {
                    if (massSquare[x, y] != null)
                    {
                        int pos = x;
                        while (pos > 1 && massSquare[pos - 1, y] == null)
                        {
                            pos--;
                        }

                        if (massSquare[pos - 1, y] != null) //Если есть по соседству квадрат
                        {
                            SetNewPos(massSquare[x, y], new Position(pos, y));
                            if (pos != x)
                            {
                                massSquare[x, y] = null;
                                move             = true;
                            }


                            if (massSquare[pos - 1, y].AddNow)
                            {
                                continue;
                            }
                            if (massSquare[pos - 1, y].AddSquare(massSquare[pos, y]))
                            {
                                move = true;
                            }
                            continue;
                        }
                        else
                        {
                            SetNewPos(massSquare[x, y], new Position(pos - 1, y));
                            massSquare[x, y] = null;
                            move             = true;
                        }
                    }
                }
            }
            return(move);
        }
Esempio n. 4
0
        public bool Move(Square[,] massSquare, DelegateMove SetNewPos)
        {
            bool move = false;

            for (int x = 0; x < 4; x++)
            {
                for (int y = 2; y >= 0; y--)
                {
                    if (massSquare[x, y] != null)
                    {
                        int pos = y;
                        while (pos < 2 && massSquare[x, pos + 1] == null)
                        {
                            pos++;
                        }

                        if (massSquare[x, pos + 1] != null) //Если есть по соседству квадрат
                        {
                            SetNewPos(massSquare[x, y], new Position(x, pos));
                            if (pos != y)
                            {
                                massSquare[x, y] = null;
                                move             = true;
                            }
                            if (massSquare[x, pos + 1].AddNow)
                            {
                                continue;
                            }
                            if (massSquare[x, pos + 1].AddSquare(massSquare[x, pos]))
                            {
                                move = true;
                            }
                            continue;
                        }
                        else
                        {
                            SetNewPos(massSquare[x, y], new Position(x, pos + 1));
                            massSquare[x, y] = null;
                            move             = true;
                        }
                    }
                }
            }
            return(move);
        }
Esempio n. 5
0
 internal void RegisterMoveEnd(DelegateMove OnMoveEnd)
 {
     this.OnMoveEnd = OnMoveEnd;
 }
Esempio n. 6
0
        public void Notification(BinaryReader binaryReader)
        {
            string code = binaryReader.ReadString();

            if (code == "1-11")
            {
                IsVisibleGame    = true;
                IsVisibleSpinner = false;
                OpponentName     = binaryReader.ReadString();
                FirstGamerSymbol = binaryReader.ReadString();
                if (FirstGamerSymbol == "X")
                {
                    IsEnable          = true;
                    SecondGamerSymbol = "0";
                    GameInformation   = FIRST_PLAYER_TURN;
                }
                else
                {
                    IsEnable          = false;
                    SecondGamerSymbol = "X";
                    GameInformation   = SECOND_PLAYER_TURN + OpponentName;
                }
                TextNotification = $"Вы играете за {FirstGamerSymbol}";
                ShowNotificationAsync();
            }
            else if (code == "2-11")
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    IsVisibleSpinner        = false;
                    var gameDialogViewModel = new GameDialogViewModel("Соперник не найден! Хотите сыгарть с компьютером?");
                    var gameDialogView      = new GameDialogView(gameDialogViewModel);
                    gameDialogView.ShowDialog();
                    if (gameDialogViewModel.UserResponse == "Да")
                    {
                        IsVisibleGame     = true;
                        OpponentName      = "Компьютер";
                        _delegateMove     = MoveForGameWithComputer;
                        _gameLogic        = new GameLogic(this);
                        FirstGamerSymbol  = _gameLogic.GamerSymbol;
                        SecondGamerSymbol = _gameLogic.ComputerSymbol;
                        TextNotification  = $"Вы играете за {FirstGamerSymbol}";
                        ShowNotificationAsync();
                        if (FirstGamerSymbol == "X")
                        {
                            IsEnable        = true;
                            GameInformation = FIRST_PLAYER_TURN;
                        }
                        else
                        {
                            GameInformation = "Ожидание хода от компьютера";
                        }
                        _delegateMove = MoveForGameWithComputer;
                    }
                    else
                    {
                        Condition = "Collapsed";
                    }
                }, DispatcherPriority.Background);
            }
            else if (code == "11-0")
            {
                SetSymbolInPlayingField(SecondGamerSymbol, binaryReader.ReadString(), false);
                IsEnable        = true;
                GameInformation = FIRST_PLAYER_TURN;
            }
            else if (code == "11-1")
            {
                Application.Current.Dispatcher.Invoke(async() =>
                {
                    GameInformation    = FIRST_PLAYER_WIN;
                    string[] positions = binaryReader.ReadString().Split('-');
                    SetSymbolInPlayingField(FirstGamerSymbol, positions[0], true, "#00FF7F");
                    await Task.Delay(528);
                    SetSymbolInPlayingField(FirstGamerSymbol, positions[1], true, "#00FF7F");
                    await Task.Delay(528);
                    SetSymbolInPlayingField(FirstGamerSymbol, positions[2], true, "#00FF7F");
                    IsVisibleCancel = true;
                }, DispatcherPriority.Background);
            }
            else if (code == "11-2")
            {
                Application.Current.Dispatcher.Invoke(async() =>
                {
                    GameInformation    = SECOND_PLAYER_WIN;
                    string[] positions = binaryReader.ReadString().Split('-');
                    SetSymbolInPlayingField(SecondGamerSymbol, positions[0], true, "#FA8072");
                    await Task.Delay(528);
                    SetSymbolInPlayingField(SecondGamerSymbol, positions[1], true, "#FA8072");
                    await Task.Delay(528);
                    SetSymbolInPlayingField(SecondGamerSymbol, positions[2], true, "#FA8072");
                    IsVisibleCancel = true;
                }, DispatcherPriority.Background);
            }
            else if (code == "11-3")
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    GameInformation = DRAW;
                    SetSymbolInPlayingField(SecondGamerSymbol, binaryReader.ReadString(), false);
                    IsVisibleCancel = true;
                }, DispatcherPriority.Background);
            }
            else if (code == "11-4")
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    GameInformation = OpponentName + SECOND_PLAYER_GIVE_UP;
                    IsVisibleCancel = true;
                }, DispatcherPriority.Background);
            }
            else if (code == "29")
            {
                NotificationTranslator.GetEnteringUserNotification(binaryReader.ReadString(), "Information");
            }
            else if (code == "30")
            {
                NotificationTranslator.PlaySoundNotificationAsync();
                NotificationTranslator.GetNewMessageNotification(binaryReader.ReadString());
            }
            else if (code == "40")
            {
                NotificationTranslator.RewriteDataNotification("Имя пользователя изменено!", "Success");
                Name = binaryReader.ReadString();
            }
            else if (code == "41")
            {
                NotificationTranslator.RewriteDataNotification("Имя пользователя не изменено! Пользователь с таким именем уже зарегистрирован!", "Error");
            }
            else if (code == "42")
            {
                NotificationTranslator.RewriteDataNotification("Логин пользователя изменён!", "Success");
                UserContainer.Login = binaryReader.ReadString();
            }
            else if (code == "43")
            {
                NotificationTranslator.RewriteDataNotification("Логин пользователя не изменён! Пользователь с таким логином уже зарегистрирован!", "Error");
            }
        }