private IAxis GetFreeRotationAxis(IMazeViewData mazeView) { IList <IAxis> allAxis = new List <IAxis>() { fAxisFactory.CreateZAxis(), fAxisFactory.CreateXAxis(), fAxisFactory.CreateYAxis() }; IAxis rotationAxis = fAxisFactory.CreateXAxis(); foreach (IAxis axis in allAxis) { Type axisType = axis.GetType(); Type leftRightAxisType = mazeView.LeftRightRotationAxis.GetType(); Type upDownAxisType = mazeView.UpDownRotationAxis.GetType(); if (leftRightAxisType == axisType || upDownAxisType == axisType) { continue; } return(axis); } return(rotationAxis); }
private void AssignNewDirection(IDirection direction, IUnit player, IMazeViewData mazeView) { player.CurrentMovementDirection = direction; ILocation futureLocation = player.CurrentLocation.GetCopy().Add(mazeView.MovementCube[direction.Value]); player.AssignLocation(futureLocation); }
private void InitializeMaze(IAxisFactory axisFactory, IMazeViewDataFactory mazeViewDataFactory) { IMazeNodeData nodeData = _mazeNodeDataBuilder.GenerateNodeData(12345); IMazeViewData viewData = _mazeNodeDataBuilder.GenerateViewData(nodeData, axisFactory, mazeViewDataFactory); _maze.Initialize(nodeData, viewData); }
public void Draw(INode node, IMazeGraphic graphic, IMazeViewData mazeView, Point topLeft, Point topRight, Point bottomLeft, Point bottomRight) { INode leftNode = node.GetNeigbour(mazeView, new LeftDirection()); INode bottomNode = node.GetNeigbour(mazeView, new DownDirection()); INode rightNode = node.GetNeigbour(mazeView, new RightDirection()); INode topNode = node.GetNeigbour(mazeView, new UpDirection()); var pen = new Pen(Color.Blue); if (!Validator.DoesPathToNodeExist(node, topNode)) { graphic.DrawLine(pen, topLeft, topRight); } if (!Validator.DoesPathToNodeExist(node, rightNode)) { graphic.DrawLine(pen, topRight, bottomRight); } if (!Validator.DoesPathToNodeExist(node, bottomNode)) { graphic.DrawLine(pen, bottomRight, bottomLeft); } if (!Validator.DoesPathToNodeExist(node, leftNode)) { graphic.DrawLine(pen, bottomLeft, topLeft); } }
/// <summary> /// Initializes the Node Location list and the Node Id list /// </summary> /// <param name="gridSize"></param> public void Initialize(IMazeNodeData nodeData, IMazeViewData viewData) { NodeData = nodeData; ViewData = viewData; SpawnUnitAtLocation(UnitType.Player, new Location()); }
public RotateCommand(IRotation rotation, IUnit player, IMazeViewData mazeView, IMazeNodeData nodeData, IAxisFactory factory) { fRotation = rotation; fPlayer = player; fMazeView = mazeView; fNodesByLocation = nodeData.NodesByLocation; fAxisFactory = factory; }
private void DrawNode(int x, int y, INode node, IMazeGraphic graphic, IMazeViewData mazeView, IUnitList unitList) { int indeX = GetNodePoint(x, node.SquareSize, mazeView.ViewStart); int indeY = GetNodePoint(y, node.SquareSize, mazeView.ViewStart); DrawNode(node, graphic, mazeView, indeX, indeY); DrawCollectable(node, graphic, indeX, indeY); DrawPlayer(node, graphic, unitList, indeX, indeY); }
public void RotateView(IRotation rotation, IUnit player, IMazeViewData mazeView, Dictionary <ILocation, INode> nodesByLocation) { player.ViewingAxis = GetFreeRotationAxis(mazeView); DoMoveViewToOrigin(mazeView, nodesByLocation); DoRotate(rotation, mazeView, nodesByLocation); player.ViewingAxis = GetFreeRotationAxis(mazeView); DoMoveViewToPlayer(player, mazeView, nodesByLocation); }
private void DrawNode(INode node, IMazeGraphic graphic, IMazeViewData mazeView, int indeX, int indeY) { int HalfOfNodeSize = _defaultSettings.HalfOfNodeSize; var topLeft = new Point(indeX - HalfOfNodeSize, indeY - HalfOfNodeSize); var topRight = new Point(indeX + HalfOfNodeSize, indeY - HalfOfNodeSize); var bottomLeft = new Point(indeX - HalfOfNodeSize, indeY + HalfOfNodeSize); var bottomRight = new Point(indeX + HalfOfNodeSize, indeY + HalfOfNodeSize); node.Draw(node, graphic, mazeView, topLeft, topRight, bottomLeft, bottomRight); }
private void DoRotate(IRotation rotation, IMazeViewData mazeView, IReadOnlyDictionary <ILocation, INode> nodesByLocation) { IAxis axis = rotation.GetRotationAxis(mazeView); double angle = DegreesToRadial(rotation.GetAngle()); Matrix <double> rotationMatrix = axis.GetRotationMatrix(angle); DoRotateView(rotationMatrix, mazeView, nodesByLocation); ApplyRotation(mazeView.MovementCube, rotationMatrix); rotation.SetRotationAxisForDirection(mazeView, GetFreeRotationAxis(mazeView)); }
private void AssignReverseDirection(IDirection direction, IUnit player, IMazeViewData mazeView) { IDirection reverseDirection = player.CurrentMovementDirection.ReverseDirection; player.CurrentMovementDirection = reverseDirection; player.FutureMovementDirection = reverseDirection; ILocation reverseLocation = player.CurrentLocation .GetCopy() .Add(mazeView.MovementCube[reverseDirection.Value]); player.AssignLocation(reverseLocation); }
private void DoMoveViewToOrigin(IMazeViewData mazeView, IReadOnlyDictionary <ILocation, INode> nodesByLocation) { int middle = (int)Math.Round((double)mazeView.MazeNodes.Count / 2); Vector <double> centerOfView = Vector <double> .Build.Dense(new double[] { mazeView.MazeNodes[middle].Location.PointX , mazeView.MazeNodes[middle].Location.PointY , mazeView.MazeNodes[middle].Location.PointZ }); Vector <double> origin = Vector <double> .Build.Dense(new double[] { 0, 0, 0 }); Vector <double> movement = origin - centerOfView; DoMoveView(movement, mazeView, nodesByLocation); }
public void Draw(IMazeGraphic mazeGraphic, IMazeViewData mazeView, IUnitList unitList) { ValidateGrapic(mazeGraphic); mazeGraphic.Clear(Color.White); int index = 0; for (int y = mazeView.ViewStart; y <= mazeView.ViewEnd; y++) { for (int x = mazeView.ViewStart; x <= mazeView.ViewEnd; x++) { INode node = mazeView.MazeNodes[index]; DrawNode(x, y, node, mazeGraphic, mazeView, unitList); index++; } } }
private void DoMoveView(Vector <double> vectorToMoveBy, IMazeViewData mazeView, IReadOnlyDictionary <ILocation, INode> nodesByLocation) { for (int i = 0; i < mazeView.MazeNodes.Count; i++) { INode item = mazeView.MazeNodes[i]; Vector <double> movedVector = vectorToMoveBy + Vector <double> .Build.Dense(new[] { item.Location.PointX.Value , item.Location.PointY.Value , item.Location.PointZ.Value }); double pointX = Math.Round(movedVector[0], 2); double pointY = Math.Round(movedVector[1], 2); double pointZ = Math.Round(movedVector[2], 2); var temp = new Location(pointX, pointY, pointZ); nodesByLocation.TryGetValue(temp, out INode node); mazeView.MazeNodes[i] = node; } }
public void InitializeTest() { IAxisFactory axisFactory = new AxisFactory(); IMazeViewDataFactory mazeViewDataFactory = new MazeViewDataFactory(); var settings = new DefaultSettings(); var nodeBuilder = new NodeBuilder(settings, new CoinBuilder(settings)); var randomizer = new Randomizer(); var nodeDataBuilder = new MazeNodeDataBuilder(new FakeMazeNodeDataBuilderSettings(3, 3), randomizer, nodeBuilder); IMazeNodeData nodeData = nodeDataBuilder.GenerateNodeData(12345); IMazeViewData viewData = nodeDataBuilder.GenerateViewData(nodeData, axisFactory, mazeViewDataFactory); var maze = new Maze(new UnitList(), new UnitFactory(randomizer)); maze.Initialize(nodeData, viewData); int numberOfNodesTotal = maze.NodeData.Count; int numberOfNodesView = maze.ViewData.MazeNodes.Count; int numberOfUnits = maze.UnitList.Count; Assert.Equal(1, numberOfUnits); Assert.Equal(9, numberOfNodesView); Assert.Equal(27, numberOfNodesTotal); }
public void MovePlayer(IDirection direction, IUnit player, IMazeNodeData nodeData, IMazeViewData mazeView) { Action <IDirection, IUnit, IMazeViewData> movementAction = fMovementLogic.GetMovementToPreform(direction, player, nodeData, mazeView); movementAction?.Invoke(direction, player, mazeView); }
public IAxis GetRotationAxis(IMazeViewData mazeViewData) { return(mazeViewData.UpDownRotationAxis); }
public void SetRotationAxisForDirection(IMazeViewData mazeViewData, IAxis freeAxis) { mazeViewData.LeftRightRotationAxis = freeAxis; }
public IAxis GetRotationAxis(IMazeViewData mazeViewData) { return(mazeViewData.LeftRightRotationAxis); }
public void SetRotationAxisForDirection(IMazeViewData mazeViewData, IAxis freeAxis) { mazeViewData.UpDownRotationAxis = freeAxis; }
private bool TryReverseDirection(IDirection direction, IUnit player, IMazeNodeData nodeData, IMazeViewData mazeView) { IDirection reverseDirection = player.CurrentMovementDirection.ReverseDirection; ILocation futureLocation = player.CurrentLocation.GetCopy().Add(mazeView.MovementCube[reverseDirection.Value]); return(Validator.IsFutureLocationValid(player.CurrentLocation, futureLocation, nodeData)); }
private bool TryNewDirection(IDirection direction, IUnit player, IMazeNodeData nodeData, IMazeViewData mazeView) { ILocation location = player.CurrentLocation.GetCopy().Add(mazeView.MovementCube[direction.Value]); return(Validator.IsFutureLocationValid(player.CurrentLocation, location, nodeData)); }
public INode GetNeigbour(IMazeViewData mazeView, IDirection direction) { ILocation location = Location.Add(mazeView.MovementCube[direction.Value]); return(mazeView.GetNodeAt(location)); }
public Action <IDirection, IUnit, IMazeViewData> GetMovementToPreform(IDirection direction, IUnit player, IMazeNodeData nodeData, IMazeViewData mazeView) { return(fMovementPriorityList.FirstOrDefault(kp => kp.Key(direction, player, nodeData, mazeView)).Value); }
private void DoMoveViewToPlayer(IUnit player, IMazeViewData mazeView, IReadOnlyDictionary <ILocation, INode> nodesByLocation) { Vector <double> movement = player.ViewingAxis.GetVectorToPlayerAxis(player); DoMoveView(movement, mazeView, nodesByLocation); }