public static GameDto AGameDto(VectorDto movingObjectPosition) { var width = 10; var height = 8; var testCells = new[] { new CellDto("1", new VectorDto { X = 2, Y = 4 }, "color1", "", 0), new CellDto("2", new VectorDto { X = 5, Y = 4 }, "color1", "", 0), new CellDto("3", new VectorDto { X = 3, Y = 1 }, "color2", "", 20), new CellDto("4", new VectorDto { X = 1, Y = 0 }, "color2", "", 20), new CellDto("5", movingObjectPosition, "color4", "☺", 10), }; return(new GameDto( testCells, true, true, width, height, Guid.Empty, movingObjectPosition.X == 0, movingObjectPosition.Y, 4)); }
public IActionResult Moves(Guid gameId, [FromBody] UserInputDto userInput) { var game = gamesRepo.GetGameById(gameId); var playerPosition = GetCellPlayer(game); var deltaMove = new VectorDto(0, 0); if (game.MonitorKeyboard) { deltaMove = GetDeltaMove(userInput.KeyPressed); } else if (game.MonitorMouseClicks && userInput.ClickedPos != null) { foreach (var neighbor in GetNeighborsPoints(playerPosition.Pos)) { if (EqualsVectorsDto(neighbor, userInput.ClickedPos)) { deltaMove = new VectorDto(userInput.ClickedPos.X - playerPosition.Pos.X, userInput.ClickedPos.Y - playerPosition.Pos.Y); break; } } } var newGame = MovePlayer(game, playerPosition.Pos, deltaMove); newGame.Score += game.Score; gamesRepo.AddGame(newGame); var gameDto = mapper.Map <GameDto>(newGame); return(Ok(gameDto)); }
public GameDto MoveStep(GameDto current, VectorDto movement) { // Шаг право if (movement.X == 1 && movement.Y == 0) { for (var y = 0; y < current.Height - 1; y++) { for (var x = 0; x < current.Width; x++) { var rightCell = GetCellAtPosition(current, x + 1, y); var currentCell = GetCellAtPosition(current, x, y); if (String.IsNullOrEmpty(rightCell)) { current.Cells[x + 1].Content = currentCell; continue; } if (rightCell == currentCell) { var newContent = (int.Parse(rightCell) * int.Parse(rightCell)).ToString(); current.Cells[x].Content = newContent; } } } } return(null); }
/// <summary> /// Frontend animate transition of the cell from old to new state. /// </summary> /// <param name="id">Id is used to identificate cell to apply right animation</param> /// <param name="pos">Logical position of the cell in the game grid. Upper left corner is `new Vec(0, 0)`</param> /// <param name="type">Frontend apply images and other styling to the cell according to this type</param> /// <param name="zIndex">Frontend render cells with higher zIndex above cells with lower zIndex</param> public CellDto(string id, VectorDto pos, string type, int zIndex) { Id = id; Pos = pos; Type = type; ZIndex = zIndex; }
/// <summary> /// Frontend animate transition of the cell from old to new state. /// </summary> /// <param name="id">Id is used to identificate cell to apply right animation</param> /// <param name="pos">Logical position of the cell in the game grid. Upper left corner is `new Vec(0, 0)`</param> /// <param name="type">Frontend apply images and other styling to the cell according to this type</param> /// <param name="content">Frontend can put this text in the cell</param> /// <param name="zIndex">Frontend render cells with higher zIndex above cells with lower zIndex</param> public CellDto(string id, VectorDto pos, string type, string content, int zIndex) { Id = id; Pos = pos; Type = type; Content = content; ZIndex = zIndex; }
/// <summary> /// Frontend animate transition of the cell from old to new state. /// </summary> /// <param name="id">Id is used to identificate cell to apply right animation</param> /// <param name="pos">Logical position of the cell in the game grid. Upper left corner is `new Vec(0, 0)`</param> /// <param name="type">Frontend apply images and other styling to the cell according to this type</param> /// <param name="content">Frontend can put this text in the cell</param> public Cell(string id, VectorDto pos, CellType type, string content) { Id = id; Pos = pos; Type = type; Content = content; ZIndex = GetZIndex(type); }
/// <summary> /// Frontend animate transition of the cell from old to new state. /// </summary> /// <param name="id">Id is used to identificate cell to apply right animation</param> /// <param name="pos">Logical position of the cell in the game grid. Upper left corner is `new Vec(0, 0)`</param> /// <param name="type">Frontend apply images and other styling to the cell according to this type</param> /// <param name="content">Frontend can put this text in the cell</param> /// <param name="zIndex">Frontend render cells with higher zIndex above cells with lower zIndex</param> public CellDto(string id, VectorDto pos, string content, int zIndex) { Id = id; Pos = pos; Type = $"tile-{content}"; Content = content; ZIndex = zIndex; }
// TODO: Consolidate with the code in TargetCreaturesInVolume_TargetCreaturesInVolumeRequest and the WhatSide parameter public static CharacterPositions GetAllCreaturesInVolume() { VectorDto volumeCenter = Targeting.TargetPoint.ToVectorDto(); string shapeName = Targeting.ExpectedTargetDetails.Shape.ToString(); CharacterPositions allTargetsInVolume = TaleSpireClient.GetAllCreaturesInVolume(volumeCenter, shapeName, Targeting.ExpectedTargetDetails.DimensionsFeet); return(allTargetsInVolume); }
/// <summary> /// Initializes a new instance of the <see cref="ScenarioAssetAddedEvent" /> class. /// </summary> /// <param name="procedureId">The procedure identifier.</param> /// <param name="scenarioId">The scenario identifier.</param> /// <param name="tag">The tag.</param> /// <param name="position">The position.</param> /// <param name="rotation">The rotation.</param> /// <param name="scale">The scale.</param> public ScenarioAssetAddedEvent(Guid procedureId, Guid scenarioId, string tag, VectorDto position, VectorDto rotation, VectorDto scale) { this.ProcedureId = procedureId; this.ScenarioId = scenarioId; this.Tag = tag; this.Position = position; this.Rotation = rotation; this.Scale = scale; }
public static void TargetPoint(ApiResponse response) { VectorDto vector = response.GetData <VectorDto>(); if (vector == null) { return; } Targeting.SetPoint(new Vector(vector.x, vector.y, vector.z)); }
public List <VectorDto> FilterVectors(List <VectorDto> vectors, VectorDto plainVector, double maxDist) { double n1 = plainVector.xVec; double n2 = plainVector.yVec; double n3 = plainVector.zVec; double px = plainVector.x; double py = plainVector.y; double pz = plainVector.z; double c = n1 * px + n2 * py + n3 * pz; return(vectors.Where((v) => GetDistanceVectorBasePlain(n1, n2, n3, c, v) <= maxDist).ToList()); }
private VectorDto CalculateDirectionVectror(double x, double y, double z) { var defaultVector = new VectorDto() { x = x, y = y, z = z, xVec = 0, yVec = -1, zVec = 0, }; foreach (var gravPoint in gravitationPoints) { defaultVector = CalculateVectorForGravitationalPoint(defaultVector, gravPoint); } return(defaultVector); }
public ActionResult <List <VectorDto> > GetVectorCollectionV2(int limit = 100, int offset = 0, double?n1 = null, double?n2 = null, double?n3 = null, double?x = null, double?y = null, double?z = null, double maxDist = 0.5) { var vectors = _engine.GetAllVectors(); if (n1.HasValue || n2.HasValue || n3.HasValue || x.HasValue || y.HasValue || z.HasValue) { //makes sure that all variables are set if at least one is set if (!n1.HasValue || !n2.HasValue || !n3.HasValue || !x.HasValue || !y.HasValue || !z.HasValue) { return(BadRequest("Please specify n1, n2, n3, x, y and z")); } VectorDto plainVector = new VectorDto() { x = x.Value, y = y.Value, z = z.Value, xVec = n1.Value, yVec = n2.Value, zVec = n3.Value }; vectors = _engine.FilterVectors(vectors, plainVector, 0.5); } if (offset > 0) { //this prevents the following RemoveRange to throw an ArgumentOutOfRangeExcenption when user provides an invalid/to big offset if (offset >= vectors.Count) { return(Ok(new List <VectorDto>())); } vectors.RemoveRange(0, offset); } if (vectors.Count > limit) { vectors.RemoveRange(limit, vectors.Count - limit); } return(Ok(vectors)); }
private VectorDto CalculateVectorForGravitationalPoint(VectorDto vector, GravitationPointDto gravitationPoint) { var vectorCpy = new VectorDto(vector); double dx = gravitationPoint.x - vector.x; double dy = gravitationPoint.y - vector.y; double dz = gravitationPoint.z - vector.z; double distance = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2) + Math.Pow(dz, 2)); double xForce = (gravitationPoint.force / (distance + 1)) * dx; double yForce = (gravitationPoint.force / (distance + 1)) * dy; double zForce = (gravitationPoint.force / (distance + 1)) * dz; vectorCpy.xVec = vector.xVec + xForce; vectorCpy.yVec = vector.yVec + yForce; vectorCpy.zVec = vector.zVec + zForce; return(vectorCpy); }
public GameState MoveStep(GameState current, VectorDto movement) { if (movement.X == 1 && movement.Y == 0) { return(MoveRight(current)); } else if (movement.X == -1 && movement.Y == 0) { return(MoveLeft(current)); } else if (movement.X == 0 && movement.Y == 1) { return(MoveUp(current)); } else if (movement.X == 0 && movement.Y == -1) { return(MoveDown(current)); } return(current); }
public IActionResult Moves(Guid gameId, [FromBody] UserInputDto userInput) { var gameState = gamesRepository.Get(gameId); if (gameState == null) { return(NotFound()); } var vector = new VectorDto(0, 0); switch (userInput.KeyPressed) { case 87: vector.Y = 1; break; case 83: vector.Y = -1; break; case 65: vector.X = -1; break; case 68: vector.X = 1; break; } var gameLogic = new Game2048(); var nextGameState = gameLogic.MoveStep(gameState, vector); var randomHelper = new RandomHelper(); nextGameState.AddCell(randomHelper.GetRandomPos(nextGameState), randomHelper.Random2Or4()); gamesRepository.Update(gameId, nextGameState, out var isUpdated); var updatedGameDto = nextGameState.ToDto(gameId); return(Ok(updatedGameDto)); }
private static bool CanMoveFromTo(Game game, VectorDto from, VectorDto delta) { var nextCell = GetCell(game, new VectorDto(from.X + delta.X, from.Y + delta.Y)); if (nextCell == null) { return(true); } switch (nextCell.Type) { case CellType.Wall or CellType.BoxOnTarget: return(false); case CellType.Box: { var doubleNextCell = GetCell(game, new VectorDto(@from.X + delta.X * 2, @from.Y + delta.Y * 2)); if (doubleNextCell is { Type : CellType.Wall or CellType.Box }) { return(false); } break; }
public static DndCore.Vector ToVector(this VectorDto vector) { return(new DndCore.Vector(vector.x, vector.y, vector.z)); }
private double GetDistanceVectorBasePlain(double n1, double n2, double n3, double c, VectorDto vector) { return(Math.Abs(n1 * vector.x + n2 * vector.y + n3 * vector.z - c) / Math.Sqrt(Math.Pow(n1, 2) + Math.Pow(n2, 2) + Math.Pow(n3, 2))); }
public UserInputDto(char keyPressed, VectorDto clickedPos) { KeyPressed = keyPressed; ClickedPos = clickedPos; }
private static ICell GetCell(Game game, VectorDto position) { return(game.Cells.FirstOrDefault(cell => EqualsVectorsDto(cell.Pos, position))); }