public bool DoNextMove(CreatureStatesTypes move) { _hero.Move(move); bool inside = _hero.CheckIfInsideOfTheWalls(maxWidth, maxHeight); return(inside); }
/// <summary>Next move for the Hero.</summary> /// <param name="input">This variable is the input you type(if the input is registered in the game) when playing the game.</param> /// <returns>It returns the next move for the Hero</returns> public CreatureStatesTypes NextMove(InputType input) { //Locating next move from the current state and input CreatureStatesTypes nextMove = _sm[(int)_currentState, (int)input].Action; //Locating next state from the current state and input _currentState = _sm[(int)_currentState, (int)input].State; return(nextMove); }
public void Start() { #region Instance bool game = true; ts.TraceEvent(TraceEventType.Information, 444, "\r\n\r\n\r\n\r\nWelcome to Hell"); ts.Close(); #endregion #region Game while (game) { world.PrintPlayground(); InputType input = ReadNextEvent(); CreatureStatesTypes nextMove = sm.NextMove(input); if (world._loot.Horse == true) { game = world.DoNextMove(nextMove); world.DoNextMove(nextMove); } else { game = world.DoNextMove(nextMove); } //world.EnemyInfo(); if (world._hero.Dead) { game = false; Console.WriteLine("\r\nTHE EMPEROR IS DEAD"); if (world.Point == 1) { Console.WriteLine("YOU CONQUEROR 0 LAND, PATHETIC"); } else if (world.Point == 2) { Console.WriteLine("YOU CONQUEROR {0} COUNTRY ", world.Point - 1); } else { Console.WriteLine("YOU CONQUEROR {0} COUNTRIES ", world.Point - 1); } } } Console.WriteLine(); #endregion }
/// <summary> /// Move er en metode der bestemmer hvilket retning Hero skal gå mod. /// </summary> /// <param name="direction"> Man skal indsætte en CreatureStatesTypes før Move metoden virker.</param> public void Move(CreatureStatesTypes direction) { switch (direction) { case CreatureStatesTypes.North: Position.X--; break; case CreatureStatesTypes.South: Position.X++; break; case CreatureStatesTypes.East: Position.Y++; break; case CreatureStatesTypes.West: Position.Y--; break; } }
/// <summary>Initializes a new instance of the <see cref="T:Mandatory_Assignment.StateTable.StateMachineTable" /> class. /// The creator of all State and Actions for CreatureStatesTypes (Situation for our Hero). /// </summary> public StateMachineTable() { _currentState = CreatureStatesTypes.North; _sm = new StateMachineEntry[6, 6]; _sm[(int)CreatureStatesTypes.North, (int)InputType.Up] = new StateMachineEntry() { State = CreatureStatesTypes.West, Action = CreatureStatesTypes.West }; _sm[(int)CreatureStatesTypes.North, (int)InputType.Down] = new StateMachineEntry() { State = CreatureStatesTypes.East, Action = CreatureStatesTypes.East }; _sm[(int)CreatureStatesTypes.North, (int)InputType.Left] = new StateMachineEntry() { State = CreatureStatesTypes.North, Action = CreatureStatesTypes.North }; _sm[(int)CreatureStatesTypes.North, (int)InputType.Right] = new StateMachineEntry() { State = CreatureStatesTypes.South, Action = CreatureStatesTypes.South }; _sm[(int)CreatureStatesTypes.North, (int)InputType.Attack] = new StateMachineEntry() { State = CreatureStatesTypes.North, Action = CreatureStatesTypes.North }; _sm[(int)CreatureStatesTypes.North, (int)InputType.Loot] = new StateMachineEntry() { State = CreatureStatesTypes.North, Action = CreatureStatesTypes.North }; _sm[(int)CreatureStatesTypes.West, (int)InputType.Up] = new StateMachineEntry() { State = CreatureStatesTypes.West, Action = CreatureStatesTypes.West }; _sm[(int)CreatureStatesTypes.West, (int)InputType.Down] = new StateMachineEntry() { State = CreatureStatesTypes.East, Action = CreatureStatesTypes.East }; _sm[(int)CreatureStatesTypes.West, (int)InputType.Left] = new StateMachineEntry() { State = CreatureStatesTypes.North, Action = CreatureStatesTypes.North }; _sm[(int)CreatureStatesTypes.West, (int)InputType.Right] = new StateMachineEntry() { State = CreatureStatesTypes.South, Action = CreatureStatesTypes.South }; _sm[(int)CreatureStatesTypes.West, (int)InputType.Attack] = new StateMachineEntry() { State = CreatureStatesTypes.West, Action = CreatureStatesTypes.West }; _sm[(int)CreatureStatesTypes.West, (int)InputType.Loot] = new StateMachineEntry() { State = CreatureStatesTypes.West, Action = CreatureStatesTypes.West }; _sm[(int)CreatureStatesTypes.East, (int)InputType.Up] = new StateMachineEntry() { State = CreatureStatesTypes.West, Action = CreatureStatesTypes.West }; _sm[(int)CreatureStatesTypes.East, (int)InputType.Down] = new StateMachineEntry() { State = CreatureStatesTypes.East, Action = CreatureStatesTypes.East }; _sm[(int)CreatureStatesTypes.East, (int)InputType.Left] = new StateMachineEntry() { State = CreatureStatesTypes.North, Action = CreatureStatesTypes.North }; _sm[(int)CreatureStatesTypes.East, (int)InputType.Right] = new StateMachineEntry() { State = CreatureStatesTypes.South, Action = CreatureStatesTypes.South }; _sm[(int)CreatureStatesTypes.East, (int)InputType.Attack] = new StateMachineEntry() { State = CreatureStatesTypes.East, Action = CreatureStatesTypes.East }; _sm[(int)CreatureStatesTypes.East, (int)InputType.Loot] = new StateMachineEntry() { State = CreatureStatesTypes.East, Action = CreatureStatesTypes.East }; _sm[(int)CreatureStatesTypes.South, (int)InputType.Up] = new StateMachineEntry() { State = CreatureStatesTypes.West, Action = CreatureStatesTypes.West }; _sm[(int)CreatureStatesTypes.South, (int)InputType.Down] = new StateMachineEntry() { State = CreatureStatesTypes.East, Action = CreatureStatesTypes.East }; _sm[(int)CreatureStatesTypes.South, (int)InputType.Left] = new StateMachineEntry() { State = CreatureStatesTypes.North, Action = CreatureStatesTypes.North }; _sm[(int)CreatureStatesTypes.South, (int)InputType.Right] = new StateMachineEntry() { State = CreatureStatesTypes.South, Action = CreatureStatesTypes.South }; _sm[(int)CreatureStatesTypes.South, (int)InputType.Attack] = new StateMachineEntry() { State = CreatureStatesTypes.South, Action = CreatureStatesTypes.South }; _sm[(int)CreatureStatesTypes.South, (int)InputType.Loot] = new StateMachineEntry() { State = CreatureStatesTypes.South, Action = CreatureStatesTypes.South }; }