private Direction GetMoveDirection(ActionType actionType)
		{
			Direction direction = 0;

			switch (actionType.Name)
			{
				case DefaultActionTypes.Up:
					direction = Direction.Up;
					break;

				case DefaultActionTypes.Down:
					direction = Direction.Down;
					break;

				case DefaultActionTypes.Left:
					direction = Direction.Left;
					break;

				case DefaultActionTypes.Right:
					direction = Direction.Right;
					break;
			}

			return direction;
		}
		protected override ActionType GetUndoActionType(ActionType actionType)
		{
			ActionType undoActionType;

			switch (actionType.Name)
			{
				case DefaultActionTypes.Up:
					undoActionType = ActionType.Get(DefaultActionTypes.Down);
					break;

				case DefaultActionTypes.Down:
					undoActionType = ActionType.Get(DefaultActionTypes.Up);
					break;

				case DefaultActionTypes.Left:
					undoActionType = ActionType.Get(DefaultActionTypes.Right);
					break;

				case DefaultActionTypes.Right:
					undoActionType = ActionType.Get(DefaultActionTypes.Left);
					break;

				default:
					undoActionType = ActionType.Get(DefaultActionTypes.Unmapped);
					break;
			}

			return undoActionType;
		}
		public void Execute(ActionType actionType)
		{
			this._gameEngine.FieldInvalidate();

			switch (actionType.Name)
			{
				case DefaultActionTypes.Up:
				case DefaultActionTypes.Down:
				case DefaultActionTypes.Left:
				case DefaultActionTypes.Right:
					var direction = this.GetMoveDirection(actionType);

					if (this._gameEngine.Move(direction))
					{
						this._gameEngine.FieldInvalidate();
					}
					else
					{
						this._gameEngine.IllegalMove();
					}

					this._gameEngine.Player.Score++;
					break;

				case DefaultActionTypes.Exit:
					this._gameEngine.Exit();
					break;

				case DefaultActionTypes.Reset:
					this._gameEngine.StartGame();
					break;

				case DefaultActionTypes.Scores:
					this._gameEngine.ShowScore();
					break;

				case DefaultActionTypes.Unmapped:
				default:
					this._gameEngine.IllegalCommand();
					break;
			}
		}
Пример #4
0
		/// <summary>
		/// Indicates whether this instance and a specified object are equal.
		/// </summary>
		/// <param name="other">The action type to compare to this object.</param>
		/// <returns>
		/// true if <paramref name="obj" /> and this instance are the same type and represent the same
		/// value; otherwise, false.
		/// </returns>
		public bool Equals(ActionType other)
		{
			return string.Equals(this.Name, other.Name);
		}
Пример #5
0
		public GameAction(ActionType actionType, IActionReceiver actionReceiver)
		{
			this.ActionReceiver = actionReceiver;
			this.ActionType = actionType;
		}
Пример #6
0
		protected virtual ActionType GetUndoActionType(ActionType actionType)
		{
			return ActionType.Get("Unmapped");
		}
		public virtual IGameAction GetAction(ActionType actionType, IActionReceiver actionReceiver)
		{
			var action = new KeyValuePair<ActionType, IActionReceiver>(actionType, actionReceiver);
			return _ActionsCache.GetOrAdd(action, this.CreateAction);
		}
		public DefaultGameAction(ActionType actionType, IActionReceiver actionReceiver)
			: base(actionType, actionReceiver)
		{
		}