public bool SetFocusFigure(IFigureEntity figure) { if (IsBlockFocused) { return(false); } if (figure.Team != GameModel.CurTeamTurn) { return(false); } if (HasFocusFigure) { if (_focusFigure.Equals(figure)) { return(false); } ResetCellStatusToEmpty(_focusFigure.PlacedCell); } figure.PlacedCell.Status = BoardCellStatus.HasFocusFigure; _focusFigure = figure; return(true); }
public override ICollection <IGameMoveTurnData> CalculateMoveTurnData(IFigureEntity movableFigure) { var placedCell = movableFigure.PlacedCell; var team = movableFigure.Team; var delta = 0; var moveTurnData = new List <IGameMoveTurnData>(); void CreateNextMoveTurnData() { delta += team == GameTeam.White ? -1 : 1; var data = CreateMoveTurnData(placedCell.IndexX + delta, placedCell.IndexY); if (!data.IsEmpty) { moveTurnData.Add(data); } } CreateNextMoveTurnData(); if (IsFigurePlacedOnRow(movableFigure)) { CreateNextMoveTurnData(); } return(moveTurnData); }
public override bool ActivatePostTurnLogic(IFigureEntity figure) { //сначала проверяем была срублена фигура на прошлом ходу var prevRemovedFigure = GameMoveTurnManager.GetRemovedFigure(figure.PlacedCell); if (prevRemovedFigure == null) { return(false); } //расчитываем возможные ходы по новой var moveTurnData = GameMoveTurnManager.CalculateMovesTurn(figure); foreach (var data in moveTurnData) { if (!data.HasRemovedFigure) { data.MoveToCell.Status = BoardCellStatus.Empty; continue; } GameMaster.SetFocusFigure(figure); GameMaster.IsBlockFocused = true; SwitchTurn(false, false); return(true); } return(false); }
private void OnRemovedFigureHandler(object sender, IFigureEntity figure) { var figureView = FigureViewModel.GetView(figure); FigureViewFactory.Despawn(figureView); FigureViewModel.RemoveView(figure); }
public void MoveFigure(IFigureEntity figure, IBoardCell cell) { figure.PlacedCell?.Clear(); figure.PlacedCell = cell; cell.Figure = figure; OnMovedFigure?.Invoke(this, new MovedFigureEventArgs(figure, cell)); }
public override ICollection <IGameMoveTurnData> CalculateMoveTurnData(IFigureEntity movableFigure) { var placedCell = movableFigure.PlacedCell; var moveTurnData = new List <IGameMoveTurnData>(); moveTurnData.AddRange(CreateMoveTurnData(placedCell, DeltaIndexes1, DeltaIndexes2)); moveTurnData.AddRange(CreateMoveTurnData(placedCell, DeltaIndexes2, DeltaIndexes1)); return(moveTurnData); }
public override ICollection <IGameMoveTurnData> CalculateMoveTurnData(IFigureEntity movableFigure) { var moveTurnData = CreateMoveTurnData(movableFigure.PlacedCell); if (CheckNeededClearForMoveTurnData(moveTurnData)) { ClearMoveTurnData(moveTurnData); } return(moveTurnData); }
private void TransformFigure(IFigureEntity figure, IFigureDef figureDef) { var cell = figure.PlacedCell; var team = figure.Team; FigureController.RemoveFigure(figure); var newTransformFigure = FigureCreator.Create(figureDef, team); FigureController.MoveFigure(newTransformFigure, cell); }
private IFigureViewPool GetPool(IFigureEntity entity) { var def = entity.Def; var storagePools = GetStorageFigureViewPools(entity.Team); storagePools.TryGetValue(def, out var pool); if (pool == null) { Debug.LogError($"Can't find pool for figureDef:{def}"); return(default);
public override ICollection <IGameMoveTurnData> CalculateMoveTurnData(IFigureEntity movableFigure) { var placedCell = movableFigure.PlacedCell; var moveTurnData = new List <IGameMoveTurnData>(); moveTurnData.AddRange(GetMoveTurnData(placedCell, DeltaIndexesRightTop)); moveTurnData.AddRange(GetMoveTurnData(placedCell, DeltaIndexesRightDown)); moveTurnData.AddRange(GetMoveTurnData(placedCell, DeltaIndexesLeftTop)); moveTurnData.AddRange(GetMoveTurnData(placedCell, DeltaIndexesLeftDown)); return(moveTurnData); }
public bool SetAndActivateFocusFigure(IFigureEntity figure) { if (!SetFocusFigure(figure)) { return(false); } ResetAvailableCellsToEmpty(); GameMoveTurnManager.CalculateMovesTurn(figure); return(true); }
public void ActivateFigurePostTurnLogic(IFigureEntity figureEntity) { foreach (var figurePostTurnLogic in figureEntity.Def.FigurePostTurnLogics) { var isActivated = figurePostTurnLogic.ActivatePostTurnLogic(figureEntity); if (isActivated) { return; } } SwitcherTurn.SwitchTurn(true, true); }
public override bool ActivatePostTurnLogic(IFigureEntity figure) { if (!IsFigurePlacedOnRow(figure)) { return(false); } var rndFigureDef = _figureDefsToTransform.GetRandom(); TransformFigure(figure, rndFigureDef); SwitchTurn(true, true); return(true); }
public IEnumerable <IGameMoveTurnData> CalculateMovesTurn(IFigureEntity movableFigure) { Clear(); foreach (var figureMoveTurnRules in movableFigure.Def.FigureMoveTurnRules) { var moveTurnData = figureMoveTurnRules.CalculateMoveTurnData(movableFigure); foreach (var data in moveTurnData) { MoveTurnData.Add(data.MoveToCell, data); } } return(MoveTurnData.Values); }
public void SetUp() { BoardModel = new BoardModel(); var boardCreator = new BoardCreator(); boardCreator.CreateCells(BoardModel); GameModel = Substitute.For <IGameModel>(); GameModel.CurTeamTurn.Returns(Team); //create figure and cell _mainFigure = Substitute.For <IFigureEntity>(); _mainFigure.Team.Returns(Team); _mainCell = BoardModel.GetCell(CellCol, CellRow); _mainFigure.PlacedCell.Returns(_mainCell); }
public override ICollection <IGameMoveTurnData> CalculateMoveTurnData(IFigureEntity movableFigure) { var placedCell = movableFigure.PlacedCell; var curIndexX = placedCell.IndexX; var curIndexY = placedCell.IndexY; var moveTurnData = new List <IGameMoveTurnData>(); for (var i = 0; i < 2; i++) { foreach (var deltaIndex in DeltaIndexes) { var newIndexX = curIndexX; var newIndexY = curIndexY; IGameMoveTurnData lastMoveTurnData; do { if (i == 0) { newIndexX += deltaIndex; } else { newIndexY += deltaIndex; } lastMoveTurnData = CreateMoveTurnData(newIndexX, newIndexY); if (lastMoveTurnData.IsEmpty) { continue; } moveTurnData.Add(lastMoveTurnData); if (lastMoveTurnData.HasRemovedFigure) { break; } } while (!lastMoveTurnData.IsEmpty); } } return(moveTurnData); }
public void SetUp() { var boardModel = Substitute.For <IBoardModel>(); GameModel = Substitute.For <IGameModel>(); var figureModel = Substitute.For <IFigureModel>(); var figurePostTurnLogicManager = Substitute.For <IFigurePostTurnLogicManager>(); var gameMoveTurnManager = Substitute.For <IGameMoveTurnManager>(); var figureController = new FigureController(figureModel); GameMaster = new GameMaster(figureController, boardModel, GameModel, figurePostTurnLogicManager, gameMoveTurnManager); _figure = new FigureEntity(Substitute.For <IFigureDef>(), GameTeam.White); _cell = new BoardCell(BoardCellCol.ColA, BoardCellRow.Row1, 0, 0) { Figure = _figure }; _moveToCell = new BoardCell(BoardCellCol.ColA, BoardCellRow.Row2, 0, 0) { Status = BoardCellStatus.AvailableForMove }; }
public MovedFigureEventArgs(IFigureEntity figureEntity, IBoardCell boardCell) { Figure = figureEntity.CheckNull(); Cell = boardCell.CheckNull(); }
public void Init(IFigureEntity entity) { Entity = entity; }
public bool Equals(IFigureEntity figureEntity) => figureEntity == this;
private bool IsFigurePlacedOnRow(IFigureEntity figure) { var friendlyRow = figure.Team == GameTeam.White ? _whiteLastRow : _blackLastRow; return(figure.PlacedCell.Row == friendlyRow); }
public abstract ICollection <IGameMoveTurnData> CalculateMoveTurnData(IFigureEntity movableFigure);
public abstract bool ActivatePostTurnLogic(IFigureEntity figure);
private void Reset() { _focusFigure = null; IsBlockFocused = false; }
public void AddFigure(IFigureEntity figure) { FiguresList.Add(figure); }
public void RemoveFigure(IFigureEntity figure) { figure.Clear(); FiguresList.Remove(figure); }
public override ICollection <IGameMoveTurnData> CalculateMoveTurnData(IFigureEntity movableFigure) { var moveTurnData = CreateMoveTurnData(movableFigure.PlacedCell, DeltaIndexes, DeltaIndexes); return(new List <IGameMoveTurnData>(moveTurnData)); }
public GameMoveTurnData(IBoardCell moveToCell, IFigureEntity removedFigure) { MoveToCell = moveToCell; RemovedFigure = removedFigure; }
public void RemoveFigure(IFigureEntity figure) { FigureModel.RemoveFigure(figure); OnRemovedFigure?.Invoke(this, figure); }