Exemplo n.º 1
0
        private void CheckIfSpecialSquare(MapSection[][] map, int i, int j, int positionNumber, Character character, int roomId)
        {
            //Character moves back by 3 positions if he is on GoBackSquare
            if (map[i][j].isGoBackSquare)
            {
                Console.WriteLine("Oops, it seems you stopped on a special square...");
                positionNumber -= 3;
                if (j >= 3)
                {
                    if (j == 3)
                    {
                        j = 0;
                    }
                    else
                    {
                        j -= 3;
                    }
                }
                else
                {
                    var toTakeDown = 3 - j;
                    if (i == 0)
                    {
                        throw new ArgumentException($"Cannot move back from {i}{j}");
                    }
                    else

                    {
                        i -= 1;
                        j  = map[i].Length - 1;
                        toTakeDown--;
                        j -= toTakeDown;
                    }
                }
                positionNumber = map[i][j].Number;
                UpdateCharacterPositionInDb(character, map[i][j].X, map[i][j].Y, positionNumber, roomId);
                Console.WriteLine($"{character.Name} moves back by 3 positions to square number {positionNumber} :)");
                CheckIfSpecialSquare(map, i, j, positionNumber, character, roomId);
            }
            //Character goes forward by 3 positions if he is on GoBackSquare
            else if (map[i][j].isGoForwardSquare)
            {
                Console.WriteLine("Oops, it seems you stopped on a special square...");
                positionNumber += 3;
                if (j <= 6)
                {
                    j += 3;
                }
                else //if(j != 9)
                {
                    var thisRowAdd = 9 - j;
                    var nextRowAdd = 3 - thisRowAdd;
                    if (i == map.Length - 1)
                    {
                        throw new ArgumentException($"Cannot move forward from {i}{j}");
                    }
                    else
                    {
                        i += 1;
                        j  = 0;
                        if (j == 0)
                        {
                            nextRowAdd--;
                        }
                        j += nextRowAdd;
                    }
                }
                positionNumber = map[i][j].Number;
                UpdateCharacterPositionInDb(character, map[i][j].X, map[i][j].Y, positionNumber, roomId);
                Console.WriteLine($"{character.Name} moves forward with 3 positions to square number {positionNumber} ^.^");
                CheckIfSpecialSquare(map, i, j, positionNumber, character, roomId);
            }
            //ToDo
            else if (map[i][j].isMysterySquare)
            {
                Console.WriteLine("Oops, it seems you stopped on a special square...");

                var num = numberGenerator.GenerateNumber(1, 3);
                if (num == 1)
                {
                    //play mini game
                    //Can be found in Miscellaneous/SpecialSquares/MysterySquare/MiniGameAction.cs
                    MiniGameAction msa = new MiniGameAction();
                    msa.PlayMiniGame(isSingle);
                    if (msa.DemolitionFalcons)
                    {
                        //All characters return to the first square
                        var characters = context.GameCharacters.Where(g => g.GameId == roomId).ToList();
                        foreach (var charche in characters)
                        {
                            context.GameCharacters.FirstOrDefault(c => c.CharacterId == charche.CharacterId).CharacterPositionX = map[0][0].X;
                            context.GameCharacters.FirstOrDefault(c => c.CharacterId == charche.CharacterId).CharacterPositionY = map[0][0].Y;
                            context.GameCharacters.FirstOrDefault(c => c.CharacterId == charche.CharacterId).MapSectionNumber   = map[0][0].Number;
                            context.SaveChanges();
                        }
                    }
                    else if (msa.GoBack)
                    {
                        var toGoBackWith = msa.GoBackWith;
                        positionNumber -= toGoBackWith;
                        if (j >= toGoBackWith)
                        {
                            if (j == toGoBackWith)
                            {
                                j = 0;
                            }
                            else
                            {
                                j -= toGoBackWith;
                            }
                        }
                        else
                        {
                            var toTakeDown = toGoBackWith - j;
                            if (i == 0)
                            {
                                throw new ArgumentException($"Cannot move back from {i}{j}");
                            }
                            else

                            {
                                i -= 1;
                                j  = map[i].Length - 1;
                                toTakeDown--;
                                j -= toTakeDown;
                            }
                        }
                        positionNumber = map[i][j].Number;
                        UpdateCharacterPositionInDb(character, map[i][j].X, map[i][j].Y, positionNumber, roomId);
                        Console.WriteLine($"{character.Name} moves back by {toGoBackWith} positions to square number {positionNumber} :)");
                        CheckIfSpecialSquare(map, i, j, positionNumber, character, roomId);
                    }
                    else if (msa.MoveForward)
                    {
                        var toMoveForwardWith = msa.MoveForwardWith;

                        positionNumber += toMoveForwardWith;
                        if (j < map[i].Length - toMoveForwardWith)
                        {
                            j += toMoveForwardWith;
                        }
                        else //if(j != 9)
                        {
                            var thisRowAdd = 9 - j;
                            var nextRowAdd = toMoveForwardWith - thisRowAdd;
                            if (i == map.Length - 1)
                            {
                                throw new ArgumentException($"Cannot move forward from {i}{j}");
                            }
                            else
                            {
                                i += 1;
                                j  = 0;
                                if (j == 0)
                                {
                                    nextRowAdd--;
                                }
                                j += nextRowAdd;
                            }
                        }
                        positionNumber = map[i][j].Number;
                        UpdateCharacterPositionInDb(character, map[i][j].X, map[i][j].Y, positionNumber, roomId);
                        Console.WriteLine($"{character.Name} moves forward with {toMoveForwardWith} positions to square number {positionNumber} ^.^");
                        CheckIfSpecialSquare(map, i, j, positionNumber, character, roomId);
                    }
                }
                else
                {
                    var doubleChance = new DoubleChance();
                    var isSingle     = true;
                    doubleChance.StartDoubleChance(context, roomId, character, positionNumber, map, i, j, isSingle);
                }
            }
            //ToDo
            else if (map[i][j].isBonusSquare)
            {
                Console.WriteLine("Oops, it seems you stopped on a special square...");
                Console.WriteLine($"{character.Name} is on a bonus square :)");
                BonusSquareAction bsa = new BonusSquareAction(context, roomId, character);
                //Gets a random spell drawn with a special algorythm that allow the character to atack another character
                bsa.GetSpell("");
            }
        }