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 ShootInPlayer() { InstanceGenerator.Cleaner(CharacteId1); CreateChar(CharacteId1, lobbyId, "Step1"); CreateChar(CharacteId2, lobbyId, "Step2"); Lobby newlobby = InstanceGenerator.GenerateTestingLobby(lobbyId); _lobbyRepository.Create(newlobby); bot.SComm(CharacteId1, Direction.North); newlobby = _lobbyRepository.Read(lobbyId); Assert.AreEqual(newlobby.Players[1].Health == LobbyRules.Test().PlayerMaxHealth - 1, true); Assert.AreEqual(newlobby.Players[0].Guns == LobbyRules.Test().PlayerMaxGuns - 1, true); }
public void MoveUp() { InstanceGenerator.Cleaner(CharacteId1); CreateChar(CharacteId1, lobbyId, "Step1"); CreateChar(CharacteId2, lobbyId, "Step2"); Lobby newlobby = InstanceGenerator.GenerateTestingLobby(lobbyId); _lobbyRepository.Create(newlobby); bot.StateMachine(_characterRepository.Read(CharacteId1).State, "Вверх", CharacteId1); newlobby = _lobbyRepository.Read(lobbyId); Assert.AreEqual(newlobby.Players[0].UserCoordinate.X == 2, true); Assert.AreEqual(newlobby.Players[0].UserCoordinate.Y == 1, true); }
public static MoveStatus MoveCommand(int userId, Direction direction) { Lobby lobby = LobbyRepository.Read(MemberRepository.ReadLobbyId(userId)); if (LobbyService.CanMakeTurn(lobby, userId) == false) { return(new MoveStatus() { IsOtherTurn = true }); } var currentPlayer = lobby.Players[lobby.CurrentTurn]; var actionList = PlayerLogic.TryMove(lobby, currentPlayer, direction); LobbyService.EndTurn(lobby); //TODO: Вывод для дебага FormatAnswers.ConsoleApp(lobby); if (actionList.Contains(PlayerAction.GameEnd)) { lobby.IsActive = false; MemberRepository.Delete(lobby.GameId); LobbyService.EndTurn(lobby); return(new MoveStatus { IsGameEnd = true, CurrentPlayer = currentPlayer, PlayerActions = actionList }); } MoveStatus status = new MoveStatus { IsOtherTurn = false, IsGameEnd = false, CurrentPlayer = currentPlayer, PlayerActions = actionList }; if (actionList.Contains(PlayerAction.MeetPlayer)) { status.PlayersOnSameCell = MazeLogic.PlayersOnCell(currentPlayer, lobby); } return(status); }
public void CheckLobby() { InstanceGenerator.Cleaner(CharacteId1); bot.StateMachine(CharacterState.NewCharacter, "/start", CharacteId1); bot.StateMachine(_characterRepository.Read(CharacteId1).State, "Step1", CharacteId1); bot.StateMachine(_characterRepository.Read(CharacteId1).State, "/game", CharacteId1); bot.StateMachine(CharacterState.NewCharacter, "/start", CharacteId2); bot.StateMachine(_characterRepository.Read(CharacteId2).State, "Step2", CharacteId2); bot.StateMachine(_characterRepository.Read(CharacteId2).State, "/game", CharacteId2); int lobbyId = _memberRepository.ReadLobbyId(CharacteId1); Lobby lobby = _lobbyRepository.Read(lobbyId); Assert.AreEqual(lobby.Players.Count, 2); Assert.AreEqual(lobby.Players[0].TelegramUserId, CharacteId1); Assert.AreEqual(lobby.Players[1].TelegramUserId, CharacteId2); Assert.AreEqual(lobby.IsActive, true); }
public void ReadTest() { int lobbyId = 1; InstanceGenerator.Cleaner(lobbyId); var lobby = InstanceGenerator.GenerateTestingLobby(lobbyId); LobbyRepository lobbyRepository = new LobbyRepository(); lobbyRepository.Create(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 List <MessageConfig> ShootCommand(int userId, Direction direction) { List <MessageConfig> msg = new List <MessageConfig>(); var status = GameCommandService.ShootCommand(userId, direction); //TODO: вынести в отдебный метод отправку "не ваш ход" if (status.IsOtherTurn) { msg.Add(new MessageConfig { Answer = String.Format(Answers.NoTurn.RandomAnswer()), PlayerId = userId }); return(msg); } var username = status.CurrentPlayer.HeroName; var memberlist = MemberRepository.ReadMemberList(MemberRepository.ReadLobbyId(userId)); var lobby = LobbyRepository.Read(MemberRepository.ReadLobbyId(userId)); var nextPlayer = lobby.Players[lobby.CurrentTurn]; if (status.Result == AttackType.NoAttack) { for (int i = 0; i < memberlist.Count; i++) { if (memberlist[i].UserId == userId) { msg.Add(new MessageConfig { Answer = String.Format(Answers.NotBullet.RandomAnswer(), username), PlayerId = memberlist[i].UserId }); } else { msg.Add(new MessageConfig { Answer = String.Format(AnswersForOther.NotBullet.RandomAnswer(), username), PlayerId = memberlist[i].UserId }); } } msg.Find(e => e.PlayerId == nextPlayer.TelegramUserId).KeyBoardId = GetKeyboardType(nextPlayer); return(msg); } if (status.Result == AttackType.NoTarget) { msg.Add(new MessageConfig { Answer = String.Format(Answers.ShootWall.RandomAnswer(), username, Extensions.DirectionToString(direction)), PlayerId = userId, KeyBoardId = status.KeyboardType }); msg.AddRange(memberlist .Where(m => m.UserId != userId) .Select(m => new MessageConfig { Answer = String.Format(AnswersForOther.ShootWall.RandomAnswer(), username, Extensions.DirectionToString(direction)), PlayerId = m.UserId })); msg.Find(e => e.PlayerId == nextPlayer.TelegramUserId).KeyBoardId = GetKeyboardType(nextPlayer); return(msg); } var config = StatusToMessage.MessageOnShoot(status.Result, username, status.Target.HeroName, direction.DirectionToString()); msg.Add(new MessageConfig { Answer = config.Item1, PlayerId = userId }); msg.AddRange(memberlist .Where(m => m.UserId != userId) .Select(m => new MessageConfig { Answer = config.Item2, PlayerId = m.UserId })); //if (status.ShootCount == false) msg.Find(e => e.PlayerId == userId).KeyBoardId = status.KeyboardType; msg.Find(e => e.PlayerId == nextPlayer.TelegramUserId).KeyBoardId = GetKeyboardType(nextPlayer); msg.Find(e => e.PlayerId == status.Target.TelegramUserId).Answer += "Вы убиты. Для поиска игры воспользуйтесь командой /game"; return(msg); }
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); }