public static MoveStatus MovCommand(int userId, Direction direction) { Lobby lobby = LobbyRepository.Read(0); var currentPlayer = lobby.Players.Find(e => e.TelegramUserId == userId); var actionList = PlayerLogic.TryMove(lobby, currentPlayer, direction); LobbyRepository.Update(lobby); FormatAnswers.ConsoleApp(lobby); if (actionList.Contains(PlayerAction.GameEnd)) { return(new MoveStatus { IsGameEnd = true, CurrentPlayer = currentPlayer, PlayerActions = actionList }); } MoveStatus status = new MoveStatus { IsOtherTurn = false, IsGameEnd = false, CurrentPlayer = currentPlayer, PlayerActions = actionList }; return(status); }
public void UpdateTest() { int lobbyId = 1; InstanceGenerator.Cleaner(lobbyId); var lobby = InstanceGenerator.GenerateTestingLobby(lobbyId); LobbyRepository lobbyRepository = new LobbyRepository(); lobbyRepository.Create(lobby); lobby.Maze[0, 3] = 0; lobbyRepository.Update(lobby); var newLobby = lobbyRepository.Read(lobbyId); Assert.AreEqual(lobby.GameId, newLobby.GameId); Assert.AreEqual(lobby.Maze[0, 3], newLobby.Maze[0, 3]); Assert.AreEqual(lobby.Players.Count, newLobby.Players.Count); }
public static void EndTurn(Lobby lobby) { lobby.CurrentTurn = (lobby.CurrentTurn + 1) % lobby.Players.Count; lobby.TimeLastMsg = DateTime.Now; _lobbyRepository.Update(lobby); }
public List <MessageConfig> StateMachine(CharacterState state, string command, int playerId) { //TODO: Вынести сюда создание репозиториев switch (state) { case CharacterState.ChangeName: return(BotService.TryChangeName(command, playerId)); case CharacterState.ChangeGameMode: switch (command) { case "/game": return(BotService.FindGameCommand(playerId)); case "/tutorial": var character = _characterRepository.Read(playerId); LobbyRepository lobbyRepository = new LobbyRepository(); MemberRepository memberRepository = new MemberRepository(); memberRepository.Create(0, playerId); var lobby = lobbyRepository.Read(0); lobby.Players.Add(new Player { Health = 3, HeroName = character.CharacterName, Rotate = Direction.North, TelegramUserId = playerId, UserCoordinate = new Coordinate(3, 3) }); lobbyRepository.Update(lobby); character.State = CharacterState.Tutorial; _characterRepository.Update(character); return(new List <MessageConfig> { new MessageConfig() { Answer = "Обучение", PlayerId = playerId } }); default: return(new List <MessageConfig> { new MessageConfig() { Answer = "неверная команда", PlayerId = playerId } }); } case CharacterState.Tutorial: switch (command) { case "Вверх": return(TutorialService.MoveCommand(playerId, Direction.North)); case "Вниз": return(TutorialService.MoveCommand(playerId, Direction.South)); case "Вправо": return(TutorialService.MoveCommand(playerId, Direction.East)); case "Влево": return(TutorialService.MoveCommand(playerId, Direction.West)); case "Взрыв стены": var inlineKeyboard = KeybordConfiguration.ChooseDirectionKeyboard(); BotClient.SendTextMessageAsync(playerId, "Выбирай направление", replyMarkup: inlineKeyboard); BotClient.OnCallbackQuery += BotClient_OnCallbackQueryBomb; return(null); case "/skip": var character = _characterRepository.Read(playerId); LobbyRepository lobbyRepository = new LobbyRepository(); MemberRepository memberRepository = new MemberRepository(); memberRepository.DeleteOne(playerId); var lobby = lobbyRepository.Read(0); lobby.Players.Remove(lobby.Players.Find(e => e.TelegramUserId == playerId)); lobbyRepository.Update(lobby); character.State = CharacterState.ChangeGameMode; _characterRepository.Update(character); return(new List <MessageConfig> { new MessageConfig() { Answer = "Обучение пропущено", PlayerId = playerId } }); default: return(new List <MessageConfig> { new MessageConfig() { Answer = "Неверная команда", PlayerId = playerId } }); } case CharacterState.FindGame: switch (command) { case "/help": return(new List <MessageConfig> { new MessageConfig() { Answer = Answers.Help.RandomAnswer(), PlayerId = playerId } }); case "/stop": _characterRepository.Read(playerId); MemberRepository repo = new MemberRepository(); var character = _characterRepository.Read(playerId); character.State = CharacterState.ChangeGameMode; _characterRepository.Update(character); repo.DeleteOne(playerId); return(new List <MessageConfig> { new MessageConfig() { Answer = "Вы удалены из очереди", PlayerId = playerId } }); default: return(new List <MessageConfig> { new MessageConfig() { Answer = "Неверная команда", PlayerId = playerId } }); } case CharacterState.InGame: switch (command) { case "Вперед": return(BotService.MoveCommand(playerId, Direction.North)); case "Назад": return(BotService.MoveCommand(playerId, Direction.South)); case "Вправо": return(BotService.MoveCommand(playerId, Direction.East)); case "Влево": return(BotService.MoveCommand(playerId, Direction.West)); case "Удар кинжалом": return(BotService.StabCommand(playerId)); case "Пропуск хода": return(BotService.SkipTurn(playerId)); case "Выстрел": { var inlineKeyboard = KeybordConfiguration.ChooseDirectionKeyboard(); BotClient.SendTextMessageAsync(playerId, "Выбирай направление", replyMarkup: inlineKeyboard); BotClient.OnCallbackQuery += BotClient_OnCallbackQueryShoot; return(null); } case "Взрыв стены": { var inlineKeyboard = KeybordConfiguration.ChooseDirectionKeyboard(); BotClient.SendTextMessageAsync(playerId, "Выбирай направление", replyMarkup: inlineKeyboard); BotClient.OnCallbackQuery += BotClient_OnCallbackQueryBomb; return(null); } case "/afk": return(BotService.AfkCommand(playerId)); case "/leave": return(BotService.TryLeaveCommand(playerId)); } return(new List <MessageConfig> { new MessageConfig() { Answer = Answers.UndefinedCommand.RandomAnswer(), PlayerId = playerId } }); case CharacterState.NewCharacter: if (command == "/start") { if (_characterRepository.Read(playerId) == null) { _characterRepository.Create(playerId); return(new List <MessageConfig> { new MessageConfig() { Answer = "Напишите имя персонажа", PlayerId = playerId } }); } } return(new List <MessageConfig> { new MessageConfig() { Answer = "Неверная команда", PlayerId = playerId } }); case CharacterState.AcceptLeave: if (command == "Подтверждаю") { return(BotService.LeaveCommand(playerId)); } else { return(new List <MessageConfig> { new MessageConfig { Answer = "Не подтверждено", PlayerId = playerId } }); } case CharacterState.Ban: //TODO:REBAN return(new List <MessageConfig> { new MessageConfig() { Answer = "В бане", PlayerId = playerId } }); default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } throw new ArgumentOutOfRangeException(nameof(state), state, null); }