public DiceFront Get() { var map = new DemoMap("map1"); var dice = new DiceDto(); return(new DiceFront(dice.RollDice())); }
public void StartSinglePlayer(DiceDto dice, GameCharacter singleGaChar, MapSection[][] map, List <Character> characters, StringBuilder sb, int roomId, Game game) { bool hasReachedFinalSpot = false; var playerInTurn = 1; while (!hasReachedFinalSpot) { if (singleGaChar.Character == characters[playerInTurn - 1]) { Console.WriteLine($"Type R in order to roll the dice!"); var input = Console.ReadLine(); while (input != "R") { Console.WriteLine("Invalid input, please try again:"); input = Console.ReadLine(); } } var diceResult = dice.RollDice(); var character = characters[playerInTurn - 1]; var chNum = context.GameCharacters.FirstOrDefault(c => c.CharacterId == character.Id && c.GameId == roomId) .MapSectionNumber; var chNewPos = chNum + diceResult; var charMoved = false; for (int i = 0; i < map.Length; i++) { for (int j = 0; j < map[i].Length; j++) { if (map[i][j].Number == chNewPos) { if (i == map.Length - 1 && j == map[i].Length - 1) { sb.AppendLine($"{character.Name} wins the game by reaching the final first!"); //add money, xp and winrate for winner AddWinnerStats(roomId, character.Id, game); AddGamesPlayedForPlayers(roomId); UpdateCharacterPositionInDb(character, map[i][j].X, map[i][j].Y, map[i][j].Number, roomId); hasReachedFinalSpot = true; charMoved = true; break; } var positionNumber = map[i][j].Number; UpdateCharacterPositionInDb(character, map[i][j].X, map[i][j].Y, positionNumber, roomId); Console.WriteLine($"{character.Name} successfully moved to square number {chNewPos}"); //TODO - add clauses to check if it is a special square and what actions should //be taken in that case try { CheckIfSpecialSquare(map, i, j, positionNumber, character, roomId); } catch (Exception ex) { Console.WriteLine(ex.Message); } if (context.GameCharacters.SingleOrDefault(ch => ch.CharacterId == character.Id && ch.GameId == roomId).SpellsId.Any()) { Console.WriteLine("You can make an atack now. If you want to attack press spacebar, if you want to continue without attacking press any key"); var keyboardInput = new KeyboardInput(); if (singleGaChar.Character != character) { AttackACharacter characterAttack = new AttackACharacter(context, map, roomId, character.Id); bool isInGame = true; while (isInGame) { try { characterAttack.SinglePlayerAttack(numberGenerator); isInGame = false; } catch (Exception ex) { if (ex.Message == "Sorry, there ain't any characters in your range...") { Console.WriteLine(ex.Message); break; } Console.WriteLine($"Well, you didn't pay much attention, didn't you? Try again now..."); } } } else { if (keyboardInput.ReadInput()) { AttackACharacter characterAttack = new AttackACharacter(context, map, roomId, character.Id); bool isInGame = true; while (isInGame) { try { characterAttack.Attack(); isInGame = false; } catch (Exception ex) { if (ex.Message == "Sorry, there ain't any characters in your range...") { Console.WriteLine(ex.Message); break; } Console.WriteLine($"Well, you didn't pay much attention, didn't you? Try again now..."); } } } } } charMoved = true; } else if (chNewPos > map[map.Length - 1][map[0].Length - 1].Number) { Console.WriteLine("Better luck next time, you can't go further than the final :)"); charMoved = true; break; } } if (charMoved) { break; } } if (playerInTurn != characters.Count) { playerInTurn++; } else { playerInTurn = 1; } } }