/// <summary> /// フィールド内の移動を試みます /// </summary> /// <param name="commandType"></param> /// <returns>移動に成功したら true</returns> public bool TryMove(CommandTypes commandType) { if (!_directionTable.ContainsKey(commandType)) { return(false); } var direction = _directionTable[commandType]; var nextPosition = _map.PlayerPosition + direction; var nextField = _map.GetField(nextPosition); if (nextField == FieldTypes.Wall) { return(false); } if (nextField == FieldTypes.Space) { _commandManager.Do(new Command( () => _map.PlayerPosition += direction, () => _map.PlayerPosition -= direction)); return(true); } if (nextField == FieldTypes.Block) { var nextNextPosition = nextPosition + direction; if (_map.GetField(nextNextPosition) != FieldTypes.Space) { return(false); } _commandManager.Do(new Command( () => { _map.PlayerPosition += direction; _map.SetField(nextPosition, FieldTypes.Space); _map.SetField(nextNextPosition, FieldTypes.Block); }, () => { _map.PlayerPosition -= direction; _map.SetField(nextPosition, FieldTypes.Block); _map.SetField(nextNextPosition, FieldTypes.Space); })); return(true); } return(false); }