public InputHandler Launch(Game game, Player player, Screen screen) { ConsoleKeyInfo keyInfo = Console.ReadKey(true); if (keyInfo.Key == ConsoleKey.Escape) { return(new CmdHandler(this)); } else if (keyInfo.Key == ConsoleKey.DownArrow) { HandHandler rtn = new HandHandler(player.GetHandDescription(), focus); focus = -1; UpdateScreen(game, player, screen); return(rtn); } else if (keyInfo.Key == ConsoleKey.UpArrow) { Player.PublicInfo info = game.GetOppositeInfo(player.ID); if (info.board.Count > 0) { OppBoardHandler rtn = new OppBoardHandler(info, focus); focus = -1; UpdateScreen(game, player, screen); return(rtn); } } else if (keyInfo.Key == ConsoleKey.RightArrow) { if (focus < selfInfo.board.Count - 1) { ++focus; } } else if (keyInfo.Key == ConsoleKey.LeftArrow) { if (focus > 0) { --focus; } } else if (keyInfo.Key == ConsoleKey.Enter) { Monster monster = selfInfo.board[focus] as Monster; if (monster != null && monster.CanAttack()) { AttackTargetAction attackAction = new AttackTargetAction(Action.SELF | Action.BOARD | (focus & Action.INDEX_MASK), monster); Player.PublicInfo[] info = new Player.PublicInfo[] { player.GetPublicInfo(), game.GetOppositeInfo(player.ID) }; return(new ChooseTargetHandler(info, attackAction, new ActionChainHandler(attackAction, new RefreshHandler(focus), null), this)); } } return(this); }
public void DoTurn(Game game) { InitiateATurn(); Player.PublicInfo[] info = new Player.PublicInfo[] { GetPublicInfo(), game.GetOppositeInfo(ID) }; screen.RefreshOpp(game.turnCount, info[1], false); screen.RefreshSelf(info[0], false); InputHandler handler = new HandHandler(GetHandDescription()); while (handler != null && !game.IsEnd()) { if (handler is ScreenUpdater) { (handler as ScreenUpdater).UpdateScreen(game, this, screen); } screen.Repaint(); handler = handler.Launch(game, this, screen); } if (game.IsEnd()) { Player.PublicInfo winnerInfo = game.GetWinner(); info[0] = GetPublicInfo(); info[1] = game.GetOppositeInfo(ID); screen.RefreshOpp(game.turnCount, info[1], false); screen.RefreshSelf(info[0], false); screen.ShowPopup(new string[] { "Game set!!", String.Format("The winner is {0}", winnerInfo.face.name), (winnerInfo.ID == this.ID) ? "You win!!" : "You lose...." }); screen.Repaint(); } EndATurn(); }