public async Task CreateTranslator_WhenSourceIsNull_ShouldGetEmptyPlan() { var translator = new CoordinateTranslator(); var result = translator.Translate(null); result.Should().BeEmpty(); }
public void GeneratePowerUps(GameMap map) { var powerUpOrder = PlanPowerUpOrder(); var powerUpDistances = PlanPowerUpDistribution(map, powerUpOrder); const int quadrants = 4; var translator = new CoordinateTranslator(map.MapWidth + 1, map.MapHeight + 1); GameBlock block; for (var quadrant = 0; quadrant < quadrants; quadrant++) { for (var powerUpCount = 0; powerUpCount < powerUpOrder.Count; powerUpCount++) { block = GetRandomBlockFromQuadrantAtDistance(map, quadrant, translator, powerUpDistances[powerUpCount]); _logger.LogDebug("Quadrant : " + quadrant + "; Distance: " + powerUpDistances[powerUpCount] + "; Block: " + (block == null ? "NULL" : block.Location.ToString())); var powerUp = powerUpOrder[powerUpCount]; if (powerUp == '&') { block.SetPowerUpEntity((IPowerUpEntity)_entityFactory.ConstructEntity(EntityFactory.EntityType.BombBagPowerUp)); } else if (powerUp == '!') { block.SetPowerUpEntity((IPowerUpEntity)_entityFactory.ConstructEntity(EntityFactory.EntityType.BombRaduisPowerUp)); } } } block = map.GetBlockAtLocation(map.MapWidth / 2 + 1, map.MapHeight / 2 + 1); block.SetEntity(null); block.SetPowerUpEntity((IPowerUpEntity)_entityFactory.ConstructEntity(EntityFactory.EntityType.SuperPowerUp)); }
public void XYTranslation_OffCenter(float sx, float sy, float dx, float dy) { CoordinateTranslator translator = new CoordinateTranslator(5f, 5f, 2.5f, 1.5f, 10f, 10f); translator.Transform(sx, sy, out float x, out float y); x.Should().BeApproximately(dx, 1e-5f); y.Should().BeApproximately(dy, 1e-5f); }
public void GeneratePowerUps(GameMap gameMap) { var bombagRandom = Rand; var bombRadiiRandom = Rand; var quadrantWidth = (gameMap.MapWidth) / 2 + 1; var quadrantHeight = (gameMap.MapWidth) / 2 + 1; const int quadrants = 4; var translator = new CoordinateTranslator(gameMap.MapWidth + 1, gameMap.MapHeight + 1); for (var i = 0; i < quadrants; i++) { var bomBags = (Settings.Default.BombBagPowerUpMultiplier * gameMap.RegisteredPlayerEntities.Count) / quadrants; var bomRadii = (Settings.Default.BombRaduisPowerUpMultiplier * gameMap.RegisteredPlayerEntities.Count) / quadrants; while (bomBags > 0) { var x = bombagRandom.Next(1, quadrantWidth); var y = bombagRandom.Next(1, quadrantHeight); x = x == 0 ? 1 : x; y = y == 0 ? 1 : y; var location = ToQuadrantLocation(translator, 4 - i, x, y); var gameBlock = gameMap.GetBlockAtLocation(location.X, location.Y); if (gameBlock.PowerUpEntity == null && gameBlock.Entity != null && gameBlock.Entity.GetType() == typeof(DestructibleWallEntity)) { gameBlock.SetPowerUpEntity((IPowerUpEntity)_entityFactory.ConstructEntity(EntityFactory.EntityType.BombBagPowerUp)); bomBags--; } } while (bomRadii > 0) { var x = bombRadiiRandom.Next(1, quadrantWidth); var y = bombRadiiRandom.Next(1, quadrantHeight); var location = ToQuadrantLocation(translator, i, x, y); var gameBlock = gameMap.GetBlockAtLocation(location.X, location.Y); if (gameBlock.PowerUpEntity == null && gameBlock.Entity != null && gameBlock.Entity.GetType() == typeof(DestructibleWallEntity)) { gameBlock.SetPowerUpEntity((IPowerUpEntity)_entityFactory.ConstructEntity(EntityFactory.EntityType.BombRaduisPowerUp)); bomRadii--; } } } var block = gameMap.GetBlockAtLocation(gameMap.MapWidth / 2 + 1, gameMap.MapHeight / 2 + 1); block.SetEntity(null); block.SetPowerUpEntity((IPowerUpEntity)_entityFactory.ConstructEntity(EntityFactory.EntityType.SuperPowerUp)); }
public ShotResult Shoot(string coordinates) { if (!Active) { throw new InvalidOperationException("Game is not active"); } var shootPoint = CoordinateTranslator.GetBoardCoordsFrom(coordinates); return(Board.Shoot(shootPoint)); }
static Game CreateGame() { var board = new Board(); var coordinateTranslator = new CoordinateTranslator(); var shipGenerator = new ShipGenerator(); var randomDataProvider = new RandomDataProvider(); var fleetDeployer = new FleetDeployer(shipGenerator, randomDataProvider); return(new Game(board, coordinateTranslator, fleetDeployer)); }
public override void execute(BoardSoupEngine.Kernel.IEventListener module) { CoordinateTranslator.setBoardSize(surface.Size); if (module is Renderer) { ((Renderer)module).setSurface(surface); } if (module is InputManager) { ((InputManager)module).setInputSurface(surface); } }
private Location ToQuadrantLocation(CoordinateTranslator translator, int quadrant, int x, int y) { switch (quadrant) { case 1: return(new Location(translator.TranslateX(x), y)); case 2: return(new Location(x, translator.TranslateY(y))); case 3: return(new Location(translator.TranslateX(x), translator.TranslateY(y))); default: return(new Location(x, y)); } }
public void drawImage(Image argImage, Point location, int rotation) { // make sure rotation is in the range 0...359 rotation = normalizeRotation(rotation); Size imageSize = CoordinateTranslator.sceneToScreenSize(argImage.Size, renderSurface.Size); Rectangle imageRect = new Rectangle(new Point(-(imageSize.Width / 2), -(imageSize.Height / 2)), imageSize); int x = location.X + (imageSize.Width / 2); int y = location.Y + (imageSize.Height / 2); // move and rotate canvas prepareCanvasOrientation(rotation, x, y); // draw myBuffer.Graphics.DrawImage(argImage, imageRect); // reset canvas resetCanvasOrientation(rotation, x, y); }
private void PlaceShip(Board whichBoard, ShipType ship) { ShipPlacement placeShip; do { Console.WriteLine(); DrawShipsFromBoard(whichBoard); Console.WriteLine("Please place your ships {0}", WorkFlow.CurrentPlayer.PlayerName); Console.WriteLine("Enter a coordinate to place your ship: {0}", ship); PlaceShipRequest shipPlacement = new PlaceShipRequest(); shipPlacement.Coordinate = CoordinateTranslator.Translate(GetValidInput()); shipPlacement.ShipType = ship; shipPlacement.Direction = ShipDirectionPlacement(); placeShip = whichBoard.PlaceShip(shipPlacement); Console.Clear(); } while (ValidShipPlacement(placeShip)); }
private FireShotResponse FireShot(Board whichBoard) { DrawBoardWithHitOrMiss(whichBoard); Console.WriteLine("Take a shot at victory {0}! Enter a coordinate:", WorkFlow.OtherPlayer.PlayerName); FireShotResponse fireShotResponse; do { fireShotResponse = whichBoard.FireShot(CoordinateTranslator.Translate(GetValidInput())); Console.Clear(); DrawBoardWithHitOrMiss(whichBoard); } while (DisplayFireShotResponse(fireShotResponse.ShotStatus, fireShotResponse) == false); Console.ReadKey(); Console.Clear(); return(fireShotResponse); }
public string GetValidInput() { string coordinateInput = null; do { coordinateInput = Console.ReadLine(); if (CoordinateTranslator.CoordinateLengthValidation(coordinateInput) == false) { Console.WriteLine("Your coordinate must be between 2 and 3 characters"); } else if (CoordinateTranslator.CheckForCoorLetter(coordinateInput) == false) { Console.WriteLine("You need to choose a letter between a and j"); } else if (CoordinateTranslator.NumberCheck(coordinateInput) == false) { Console.WriteLine("You need to provide a number between 1 and 10"); } } while (!CoordinateTranslator.CoordinateLengthValidation(coordinateInput) || !CoordinateTranslator.CheckForCoorLetter(coordinateInput) || !CoordinateTranslator.NumberCheck(coordinateInput)); return(coordinateInput); }
public void setPosition(Point argPosition) { position = CoordinateTranslator.screenToSceneLocation(argPosition, inputPaneSize); List <BoardActor> deleteList = new List <BoardActor>(); foreach (BoardActor ba in collidingActors) { if (!this.isCollidingWithActor(ba)) { deleteList.Add(ba); } } foreach (BoardActor ba in deleteList) { removeCollidingActor(ba); } deleteList.Clear(); InputCursorMoveEvent e = new InputCursorMoveEvent(position, this); dispatcher.submitEvent(e); }
public void click(int argClicks, Point location) { InputCursorClickEvent e = new InputCursorClickEvent(CoordinateTranslator.screenToSceneLocation(location, inputPaneSize)); dispatcher.submitEvent(e); }
public async Task CreateTranslator_WhenSourceHasAnElement_ShouldGetOneDeliveryPlan() { var source = new string[] { "AID", "DIA", "AAI" }; var translator = new CoordinateTranslator(); var result = translator.Translate(source); result.Should().NotBeEmpty(); result.Count().Should().Be(3); result.ElementAt(0).Address.Should().Be("St 1"); result.ElementAt(0).Coordinates.Count().Should().Be(4); result.ElementAt(0).Coordinates.ElementAt(0).X.Should().Be(0); result.ElementAt(0).Coordinates.ElementAt(0).Y.Should().Be(0); result.ElementAt(0).Coordinates.ElementAt(0).Direction.Should().Be(Directions.N); result.ElementAt(0).Coordinates.ElementAt(1).X.Should().Be(0); result.ElementAt(0).Coordinates.ElementAt(1).Y.Should().Be(1); result.ElementAt(0).Coordinates.ElementAt(1).Direction.Should().Be(Directions.N); result.ElementAt(0).Coordinates.ElementAt(2).X.Should().Be(-1); result.ElementAt(0).Coordinates.ElementAt(2).Y.Should().Be(1); result.ElementAt(0).Coordinates.ElementAt(2).Direction.Should().Be(Directions.W); result.ElementAt(0).Coordinates.ElementAt(3).X.Should().Be(-1); result.ElementAt(0).Coordinates.ElementAt(3).Y.Should().Be(2); result.ElementAt(0).Coordinates.ElementAt(3).Direction.Should().Be(Directions.N); result.ElementAt(1).Address.Should().Be("St 2"); result.ElementAt(1).Coordinates.Count().Should().Be(4); result.ElementAt(1).Coordinates.ElementAt(0).X.Should().Be(0); result.ElementAt(1).Coordinates.ElementAt(0).Y.Should().Be(0); result.ElementAt(1).Coordinates.ElementAt(0).Direction.Should().Be(Directions.N); result.ElementAt(1).Coordinates.ElementAt(1).X.Should().Be(1); result.ElementAt(1).Coordinates.ElementAt(1).Y.Should().Be(0); result.ElementAt(1).Coordinates.ElementAt(1).Direction.Should().Be(Directions.E); result.ElementAt(1).Coordinates.ElementAt(2).X.Should().Be(1); result.ElementAt(1).Coordinates.ElementAt(2).Y.Should().Be(1); result.ElementAt(1).Coordinates.ElementAt(2).Direction.Should().Be(Directions.N); result.ElementAt(1).Coordinates.ElementAt(3).X.Should().Be(1); result.ElementAt(1).Coordinates.ElementAt(3).Y.Should().Be(2); result.ElementAt(1).Coordinates.ElementAt(3).Direction.Should().Be(Directions.N); result.ElementAt(2).Address.Should().Be("St 3"); result.ElementAt(2).Coordinates.Count().Should().Be(4); result.ElementAt(2).Coordinates.ElementAt(0).X.Should().Be(0); result.ElementAt(2).Coordinates.ElementAt(0).Y.Should().Be(0); result.ElementAt(2).Coordinates.ElementAt(0).Direction.Should().Be(Directions.N); result.ElementAt(2).Coordinates.ElementAt(1).X.Should().Be(0); result.ElementAt(2).Coordinates.ElementAt(1).Y.Should().Be(1); result.ElementAt(2).Coordinates.ElementAt(1).Direction.Should().Be(Directions.N); result.ElementAt(2).Coordinates.ElementAt(2).X.Should().Be(0); result.ElementAt(2).Coordinates.ElementAt(2).Y.Should().Be(2); result.ElementAt(2).Coordinates.ElementAt(2).Direction.Should().Be(Directions.N); result.ElementAt(2).Coordinates.ElementAt(3).X.Should().Be(-1); result.ElementAt(2).Coordinates.ElementAt(3).Y.Should().Be(2); result.ElementAt(2).Coordinates.ElementAt(3).Direction.Should().Be(Directions.W); }
public int sceneToScreenAmount(int amount) { return(CoordinateTranslator.sceneToScreenAmount(amount, renderSurface.Size.Height)); }
public void LetterTest(string coor, int expected) { var actual = CoordinateTranslator.LetterTranslator(coor); Assert.AreEqual(expected, actual); }
public void LengthCheck(string input, bool expected) { var actual = CoordinateTranslator.CoordinateLengthValidation(input); Assert.AreEqual(expected, actual); }
public void LetterCheck(string input, bool expected) { var actual = CoordinateTranslator.CheckForCoorLetter(input); Assert.AreEqual(expected, actual); }
public void ActualNumberCheck(string input, bool expected) { var actual = CoordinateTranslator.NumberCheck(input); Assert.AreEqual(expected, actual); }
public Size translateSizeToResolution(Size size) { return(CoordinateTranslator.sceneToScreenSize(size, renderSurface.Size)); }
private GameBlock GetRandomBlockFromQuadrantAtDistance(GameMap gameMap, int quadrant, CoordinateTranslator translator, int distance) { var quadrantWidth = (gameMap.MapWidth) / 2; var quadrantHeight = (gameMap.MapWidth) / 2; var playerLocation = ToQuadrantLocation(translator, quadrant, 1, 1); _logger.LogDebug("Quadrant: " + quadrant + "; PlayerLocation: " + playerLocation.ToString()); var blocks = new List <GameBlock>(); for (var x = 1; x < quadrantWidth; x++) { for (var y = 1; y < quadrantHeight; y++) { int radius = (int)Math.Floor(DetermineRadius(1, 1, x, y)); if (radius != distance) { continue; } var location = ToQuadrantLocation(translator, quadrant, x, y); GameBlock block = gameMap.GetBlockAtLocation(location.X, location.Y); if (block.Entity != null && block.Entity.GetType() == typeof(DestructibleWallEntity)) { blocks.Add(block); _logger.LogDebug("X: " + location.X + "; Y: " + location.Y + "; radius: " + radius); } } } if (blocks.Count == 0) { return(null); } var result = blocks[Rand.Next(blocks.Count)]; blocks.Clear(); return(result); }
public Point translateLocationToResolution(Point location) { return(CoordinateTranslator.sceneToScreenLocation(location, renderSurface.Size)); }