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(""); } }
public void StartDoubleChance(DemolitionFalconsDbContext context, int roomId, Character character, int positionNumber, MapSection[][] map, int i, int j, bool isSingle) { var demoMatrixRows = 3; var demoMatrixCols = 3; var firstNumTyped = 0; char[][] demoMatrix = new char[3][]; var isSecondChance = false; int num; var playGame = new PlayGame(context, numberGenerator); var counter = 1; for (int row = 0; row < demoMatrixRows; row++) { demoMatrix[row] = new char[demoMatrixCols]; for (int col = 0; col < demoMatrixCols; col++) { demoMatrix[row][col] = counter.ToString()[0]; counter++; } } //play double chance Console.WriteLine("Welcome to the Double Chance game! You have 9 hidden sayings. Choose one!"); var doubleChanceGame = new DoubleChance(); var matrix = doubleChanceGame.LoadDoubleChance(); Start: int numTyped; if (isSingle) { numTyped = numberGenerator.GenerateNumber(1, 10); while (numTyped == firstNumTyped) { numTyped = numberGenerator.GenerateNumber(1, 10); } goto SinglePlayer; } var isNumeric = int.TryParse(Console.ReadLine(), out numTyped); while (numTyped < 1 || numTyped > 9 || numTyped == firstNumTyped || !isNumeric) { if (firstNumTyped != 0) { Console.WriteLine($"Type a number from 1 to 9 which is different from {firstNumTyped}."); } Console.WriteLine("Type a number from 1 to 9"); isNumeric = int.TryParse(Console.ReadLine(), out numTyped); } SinglePlayer: char letter; if (numTyped >= 1 && numTyped <= 3) { letter = matrix[0][numTyped - 1]; demoMatrix[0][numTyped - 1] = letter; } else if (numTyped <= 6) { letter = matrix[1][numTyped - 4]; demoMatrix[1][numTyped - 4] = letter; } else { letter = matrix[2][numTyped - 7]; demoMatrix[2][numTyped - 7] = letter; } foreach (var row in demoMatrix) { Console.WriteLine(string.Join("{0}", $"[{string.Join(" | ", row)}]")); } if (letter == 'S') { if (!isSecondChance) { firstNumTyped = numTyped; BonusSquareAction bsa = new BonusSquareAction(context, roomId, character); //Gets a random spell drawn with a special algorythm that allow the character to atack another character var spell = bsa.RandomSpell(); Console.WriteLine($"Congrats you have received a new spell -> {spell.Name}. If you want to keep it type 'Y' and if you want a second chance type 'N'"); string response; if (isSingle) { response = TakeOrNot(); } else { response = Console.ReadLine(); while (response != "Y" && response != "N") { Console.WriteLine("Type 'Y' or 'N'"); response = Console.ReadLine(); } } if (response == "N") { isSecondChance = true; foreach (var row in demoMatrix) { Console.WriteLine(string.Join("{0}", $"[{string.Join(" | ", row)}]")); } goto Start; } else { bsa.GetSpell(spell.Name); } } else { Console.WriteLine("This was your second shot! Congrats you win a spell!"); BonusSquareAction bsa = new BonusSquareAction(context, roomId, character); bsa.GetSpell(""); } } else if (letter == 'F') { if (!isSecondChance) { num = numberGenerator.GenerateNumber(2, 6); var toMoveForwardWith = num; Console.WriteLine($"Congrats you can move {toMoveForwardWith} spaces forward if you wish. If so type 'Y' and if you want a second chance type 'N'"); string response; if (isSingle) { response = TakeOrNot(); } else { response = Console.ReadLine(); while (response != "Y" && response != "N") { Console.WriteLine("Type 'Y' or 'N'"); response = Console.ReadLine(); } } if (response == "N") { isSecondChance = true; foreach (var row in demoMatrix) { Console.WriteLine(string.Join("{0}", $"[{string.Join(" | ", row)}]")); } goto Start; } else { playGame.MoveForwardWith(toMoveForwardWith, positionNumber, map, i, j, roomId, character); } } else// is secondChance { num = numberGenerator.GenerateNumber(2, 6); var toMoveForwardWith = num; Console.WriteLine($"Congrats, this was your second shot. You can now move forward with {toMoveForwardWith} places if possible"); playGame.MoveForwardWith(toMoveForwardWith, positionNumber, map, i, j, roomId, character); } } else if (letter == 'B') { var toGoBackWith = numberGenerator.GenerateNumber(3, 8); if (!isSecondChance) { Console.WriteLine($"Sadly you have to move {toGoBackWith} places backwards if possible. You still have a second chance. If you want to go back type 'Y' or type 'N' for a second shot."); string response; if (isSingle) { response = TakeOrNot(); } else { response = Console.ReadLine(); while (response != "Y" && response != "N") { Console.WriteLine("Type 'Y' if you want to go back and 'N' for a second try."); response = Console.ReadLine(); } } if (response == "Y") { playGame.GoBackWith(toGoBackWith, positionNumber, map, i, j, roomId, character); } else { isSecondChance = true; foreach (var row in demoMatrix) { Console.WriteLine(string.Join("{0}", $"[{string.Join(" | ", row)}]")); } goto Start; } } else { num = numberGenerator.GenerateNumber(2, 6); var toMoveBackWith = num; Console.WriteLine($"Sorry this was your second shot. You will move with {toMoveBackWith} places backwards if possible."); playGame.GoBackWith(toMoveBackWith, positionNumber, map, i, j, roomId, character); } } }