public void ShouldCopyAllMainFieldSquareStateProperties() { var squareState = new MainFieldSquareState(true, 2, Direction.Left); var clonedObj = squareState; ReferenceEqualsForItemProperties(squareState, clonedObj); }
public void SetSquareState(uint x, uint y, Color color, Direction direction) { if (color == Color.None) { throw new GameException($"it is prohibited to set none as value for color"); } if (direction == Direction.None) { throw new GameException($"it is prohibited to set none as value for direction"); } var item = this[x, y]; var nextValue = item.Next(direction); if (nextValue == null) { throw new GameException($"state ({color}, {direction}) cannot be set for the indicated square ({x}, {y})"); } if (!nextValue.Value.State.IsActive) { throw new GameException($"state ({color}, {direction}) cannot be set for the indicated square ({x}, {y}) as it doesn't adjacent to anything."); } var state = new MainFieldSquareState(true, nextValue.Value.State.Obstacle, direction); ApplyStateToItem(item.Value, state, color); }
public void Reset() { ForEach(item => ResetItem(item.Value)); foreach (var valuePair in _initialObstacles) { var initialSquare = valuePair.Value; var item = Matrix[initialSquare.X, initialSquare.Y]; var state = new MainFieldSquareState(true, valuePair.Key, Direction.None); ApplyStateToItem(item, state, initialSquare.Color); } }
protected MainField(Matrix <IMainFieldSquare> matrix, List <InitialSquare> initialObstacles, int maxSavedStatesCount) : base(matrix) { StateManager = new MatrixStateManager <MainFieldSquare>(MatrixUpcast(), maxSavedStatesCount); _initialObstacles = new Dictionary <uint, InitialSquare>(); uint index = 0; initialObstacles.ForEach(square => { _initialObstacles[++index] = square; var item = Matrix[square.X, square.Y]; var state = new MainFieldSquareState(true, index, Direction.None); ApplyStateToItem(item, state, square.Color); }); }
protected void ApplyStateToItem(IMainFieldSquare item, MainFieldSquareState state, Color color) { var square = item as MainFieldSquare; square.SetState(state, color); }
// color is base state! public void SetState(MainFieldSquareState state, Color color) { State = state; Color = color; OnStateChanged(); }
public TestMainFieldSquare(uint x, uint y, MainFieldSquareState state, Color color) { X = x; Y = y; State = state; Color = color; }