Esempio n. 1
0
        private void ChatService_CoordinatesMessageReceived(BoardCoordinates coordinates)
        {
            if (!gameHasEnded)
            {
                if (coordinates.messageType == MessageType.playerMovement)
                {
                    if (StepsCount == 0)
                    {
                        board.State = new Darken();
                    }
                    else if (StepsCount == SpawnRates.StepsCount / 2)
                    {
                        board.State = new Lighten();
                    }

                    board.Request();
                    if (StepsCount >= SpawnRates.StepsCount)
                    {
                        StepsCount = -1;
                    }

                    //currByte -= 1;
                    //BackgroundColor = Color.FromRgb(255, currByte, currByte).ToString();
                    //OnPropertyChanged(nameof(BackgroundColor));

                    if (coordinates.id == UniqueID)
                    {
                        MainPlayer.Score++;
                    }

                    if (BonusCount > SpawnRates.BonusCount)
                    {
                        //var a = new BonusFactory();
                        Random randNum     = new Random();
                        int    BonusNumber = randNum.Next(1, 4);
                        //a.CreateBonus(BonusNumber, _chatService).SendBonus();
                        facade.CreateBonus(BonusNumber);
                        BonusCount = 0;
                        //MainPlayer.SetMemento(memento.Memento);
                    }

                    if (FreezeYourselfStepCount >= SpawnRates.FreezeYourselfStepCount)
                    {
                        facade.CreateDeBuff(TileType.DebuffFreezeYourself);
                        FreezeYourselfStepCount = 0;
                    }

                    if (FreezeOthersStepCount >= SpawnRates.FreezeOthersStepCount)
                    {
                        facade.CreateBuff(TileType.BuffFreezeOthers);
                        FreezeOthersStepCount = 0;
                    }

                    if (BlackSplashCount >= SpawnRates.BlackSplashCount)
                    {
                        facade.CreateDeBuff(TileType.DebuffBlackSplash);
                        BlackSplashCount = 0;
                    }
                    if (ColorSplashCount >= SpawnRates.ColorSplashCount)
                    {
                        facade.CreateBuff(TileType.BuffColorSplash);
                        ColorSplashCount = 0;
                    }

                    if (EnemyCount >= SpawnRates.EnemyCount)
                    {
                        MainEnemy.ChangePossition();
                        dazeEnemy.Operation(MainEnemy.PosX, MainEnemy.PosY, _connectionProxy);
                        EnemyCount = 0;
                    }

                    if (MagicianCount > SpawnRates.MagicianCount)
                    {
                        Thief newThief = new Magician();
                        newThief.Run(_connectionProxy);
                        MagicianCount = 0;
                    }

                    if (MasterThiefCount > SpawnRates.MasterThiefCount)
                    {
                        Thief newThief2 = new MasterThief();
                        newThief2.Run(_connectionProxy);
                        MasterThiefCount = 0;
                    }

                    StepsCount++;
                    BonusCount++;
                    FreezeYourselfStepCount++;
                    FreezeOthersStepCount++;
                    EnemyCount++;
                    BlackSplashCount++;
                    ColorSplashCount++;
                    MasterThiefCount++;
                    MagicianCount++;

                    //jei turi str count bet nedaro

                    if (coordinates.id == UniqueID)
                    {
                        _message = coordinates.message;
                        _x       = coordinates.x;
                        _y       = coordinates.y;


                        if (TilesSet.GetTile(_x, _y).TileType == TileType.BonusJackPot)
                        {
                            root.AddPoint(ComponentType.JackPot);
                            MainPlayer.PlayerCalculateScore(Score.AddPoints(new BonusFactory().CreateBonus(1, _connectionProxy)));
                            MessageBox.Show(TilesSet.GetTile(_x, _y).TileType.ToString() + MainPlayer.Score);
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.BonusNormal)
                        {
                            root.AddPoint(ComponentType.Normal);
                            MainPlayer.PlayerCalculateScore(Score.AddPoints(new BonusFactory().CreateBonus(3, _connectionProxy)));
                            MessageBox.Show(TilesSet.GetTile(_x, _y).TileType.ToString() + MainPlayer.Score);
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.BonusJoke)
                        {
                            root.AddPoint(ComponentType.Joke);
                            MainPlayer.PlayerCalculateScore(Score.ReducePoints(new BonusFactory().CreateBonus(2, _connectionProxy)));
                            MessageBox.Show(TilesSet.GetTile(_x, _y).TileType.ToString() + MainPlayer.Score);
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.DebuffFreezeYourself)
                        {
                            IceDamageDealer.ProcessRequest(DamageDealerType.IceDamage, MainPlayer);
                            root.AddPoint(ComponentType.FreezeYourself);
                            MainPlayer.RequestStrategy(StrategyType.Frozen);
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.BuffFreezeOthers)
                        {
                            root.AddPoint(ComponentType.FreezeOthers);
                            MainPlayer.RequestStrategy(StrategyType.Frozen);
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.BuffColorSplash)
                        {
                            root.AddPoint(ComponentType.ColorSplash);
                            MainPlayer.SendSteppedOnColorSplash(_connectionProxy, _x, _y);
                            MessageBox.Show(TilesSet.GetTile(_x, _y).TileType.ToString());
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.DebuffBlackSplash)
                        {
                            root.AddPoint(ComponentType.BlackSplash);
                            MainPlayer.SendSteppedOnBlackSplash(_connectionProxy, _x, _y);
                            MessageBox.Show(TilesSet.GetTile(_x, _y).TileType.ToString());
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.DarkHole)
                        {
                            MainPlayer.Score -= 3;
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.LightHole)
                        {
                            MainPlayer.Score -= 2;
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.Magician)
                        {
                            Random randNum = new Random();
                            int    number  = randNum.Next(1, 1000);
                            string roman   = ToRoman(number);

                            ContextRoman context = new ContextRoman(roman);
                            foreach (ExpressionRoman exp in tree)
                            {
                                exp.Interpret(context);
                            }

                            string message = "Does " + roman + " = " + context.Output + " ?";
                            string title   = "Answer the question";

                            MessageBoxResult result = MessageBox.Show(message, title, MessageBoxButton.YesNo);
                            if (result == MessageBoxResult.No)
                            {
                                IceDamageDealer.ProcessRequest(DamageDealerType.MagitianDamage, MainPlayer);
                            }
                        }
                        if (TilesSet.GetTile(_x, _y).TileType == TileType.MasterThief)
                        {
                            IceDamageDealer.ProcessRequest(DamageDealerType.ThiefDamage, MainPlayer);
                        }

                        if (TilesSet.GetTile(_x, _y).TileType == TileType.Enemy)
                        {
                            IceDamageDealer.ProcessRequest(DamageDealerType.EnemyDamage, MainPlayer);
                            MainPlayer.RequestStrategy(StrategyType.Confused);
                        }

                        TilesSet.AddTile(_x, _y, new Tile(true, true, TileType.Neutral, _x, _y));

                        OnPropertyChanged(nameof(Message));
                        OnPropertyChanged(nameof(x));
                        MainPlayer.PosX = x;
                        MainPlayer.PosY = y;
                        OnPropertyChanged(nameof(y));
                        OnPropertyChanged(nameof(CurrentPlayerScore));
                    }
                }

                if (coordinates.messageType == MessageType.gamePause || coordinates.messageType == MessageType.gamePauseUndo)
                {
                    SetGamePause();
                }

                if (MainPlayer.Score >= 100)
                {
                    MessageBox.Show(root.Display(1));
                    MainPlayer.SendGameOverMessage(_connectionProxy, UniqueID);
                    MainPlayer.Score = 0;
                }

                if (coordinates.messageType == MessageType.gameOver)
                {
                    gameHasEnded = true;
                }

                if (coordinates.messageType == MessageType.reset)
                {
                    MainPlayer.SetMemento(memento.Memento);
                    x = MainPlayer.PosX;
                    y = MainPlayer.PosY;
                    OnPropertyChanged(nameof(x));
                    OnPropertyChanged(nameof(y));
                    OnPropertyChanged(nameof(CurrentPlayerScore));
                }
            }
        }