Beispiel #1
0
 public void DrawMessage(GameMessage message, params string[] args)
 {
     var sb = new StringBuilder();
     sb.AppendLine();
     sb.AppendMessage(message.Type, message.Args);
     Console.Write(sb);
 }
Beispiel #2
0
        private ProcessResult ProcessAction(GameAction action)
        {
            var result = ProcessResult.None;

            switch (action)
            {
                case GameAction.None:
                    break;
                case GameAction.StartGame:
                    Message = new GameMessage(MessageType.StartGame);
                    result = ProcessResult.RequestAction;
                    break;
                case GameAction.MoveN:
                case GameAction.MoveNE:
                case GameAction.MoveNW:
                case GameAction.MoveE:
                case GameAction.MoveS:
                case GameAction.MoveSE:
                case GameAction.MoveSW:
                case GameAction.MoveW:
                    result = MoveCharacter(action);
                    break;
                case GameAction.ShowHelp:
                    Message = new GameMessage(MessageType.ShowHelp);
                    break;
                case GameAction.ShowMenu:
                    Message = new GameMessage(MessageType.ShowMenu);
                    break;
                case GameAction.EndGame:
                    painter.DrawEndGameScreen();
                    Message = new GameMessage(MessageType.EndGame);
                    break;
                default:
                    throw new NotSupportedException(
                        "Action is not supported: " + action);
            }

            return result;
        }
Beispiel #3
0
        private ProcessResult MoveCharacter(GameAction action)
        {
            var character = Dungeon.Character;
            var newLocation = character.Location;

            switch (action)
            {
                case GameAction.MoveN:
                    newLocation = DirHelper.MoveInDir(
                        character.Location, Dir.N);
                    break;
                case GameAction.MoveNE:
                    newLocation = DirHelper.MoveInDir(
                        character.Location, Dir.NE);
                    break;
                case GameAction.MoveNW:
                    newLocation = DirHelper.MoveInDir(
                        character.Location, Dir.NW);
                    break;
                case GameAction.MoveE:
                    newLocation = DirHelper.MoveInDir(
                        character.Location, Dir.E);
                    break;
                case GameAction.MoveS:
                    newLocation = DirHelper.MoveInDir(
                        character.Location, Dir.S);
                    break;
                case GameAction.MoveSE:
                    newLocation = DirHelper.MoveInDir(
                        character.Location, Dir.SE);
                    break;
                case GameAction.MoveSW:
                    newLocation = DirHelper.MoveInDir(
                        character.Location, Dir.SW);
                    break;
                case GameAction.MoveW:
                    newLocation = DirHelper.MoveInDir(
                        character.Location, Dir.W);
                    break;
                default:
                    throw new ArgumentOutOfRangeException(
                        "Action is not a move: " + action);
            }

            if (Dungeon[newLocation].Type == XType.Empty)
            {
                character.Location = newLocation;
            }
            else
            {
                Message = new GameMessage(
                    MessageType.CannotMoveThere,
                    Dungeon[newLocation].Type.ToString());
            }

            return ProcessResult.None;
        }