//Descobre a linha vertical que cruza por menos Bricks em uma BrickWall Ordenada public int FindOptimizedPath(BrickWall wall) { int maxNumberOfBricks = wall.Rows.Count; int maxSumOfOpen = 0; int sumOfOpen = 0; for (int i = 1; i < maxNumberOfBricks; i++) { foreach (var el in wall.Rows) { if (el.Bricks.BinarySearch(i) >= 0) //BinarySearch ao invés de Contains pois nosso array é ordenado { sumOfOpen++; } } if (sumOfOpen > maxSumOfOpen) { maxSumOfOpen = sumOfOpen; } sumOfOpen = 0; } return(maxNumberOfBricks - maxSumOfOpen); }
/// <summary> /// Broadcast message can be any message received after the join message, in 1 second intervals. /// </summary> /// <param name="oldWorld">The current state of the world. </param> /// <param name="message">The BroadcastMessage received. </param> /// <returns>New world based on both the old world and the BroadcastMessage. </returns> private static World FromBroadcastMessage(World oldWorld, BroadcastMessage message) { var brickWalls = message.DamagesDetails.Select(details => { var oldBrickWall = oldWorld.GridItems[details.Location.X, details.Location.Y] as BrickWall; // Assumption: BrickWall is the only thing which gets damaged. Debug.Assert(oldBrickWall != null); Trace.Assert(oldBrickWall != null); var newBrickWall = new BrickWall(oldBrickWall.Health, oldBrickWall.Location); return(newBrickWall); }).ToArray(); var tanks = message.PlayersDetails .Select(details => new Tank( details.Location, details.Health, details.FacingDirection, details.Points, details.Coins, details.PlayerNumber, details.IsShot, details.PlayerNumber == oldWorld.PlayerNumber ) ).ToArray(); return(new World(oldWorld.PlayerNumber) { BrickWalls = new HashSet <BrickWall>(brickWalls), StoneWalls = oldWorld.StoneWalls, Waters = oldWorld.Waters, Tanks = new HashSet <Tank>(tanks), // Acts as a clock for TimeVarient items. // TODO Check accuracy of this calculation ( < 1 thing). // TODO Confirm that we don't need an actual clock for this. // TODO Identify what the server sends (does it actually sends time to disappear?). Coinpacks = new HashSet <Coinpack>( oldWorld.Coinpacks .Where(coinpack => coinpack.TimeToDisappear > 1) // ? .Where(coinpack => !tanks.Select(tank => tank.Location).Contains(coinpack.Location)) .Select(coinpack => new Coinpack(coinpack.Location, coinpack.CoinValue, coinpack.TimeToDisappear - 1) ) ), Lifepacks = new HashSet <Lifepack>( oldWorld.Lifepacks .Where(lifepack => lifepack.TimeToDisappear > 1) // ? .Where(lifepack => !tanks.Select(tank => tank.Location).Contains(lifepack.Location)) .Select(lifepack => new Lifepack(lifepack.Location, lifepack.HealthValue, lifepack.TimeToDisappear - 1) ) ) }); }
//Retorna a menor quantidade de Bricks que uma linha vertical pode atingir public int GetOptimizedLine(BrickWall wall) { BrickWall clearPaths = new BrickWall(); wall.Rows.ForEach((el) => { clearPaths.Rows.Add(GetClearRowPaths(el)); }); return(FindOptimizedPath(clearPaths)); }
//Retorna uma nova BrickWall, baseado nos parametros recebidos public BrickWall GenerateBrickWall(int rows, int maxBricksInRow) { BrickWall wall = new BrickWall(); for (int i = 0; i < rows; i++) { wall.Rows.Add(GenerateBrickRow(maxBricksInRow)); } return(wall); }
public dynamic Post([FromBody] BrickWall wall) { long tick1 = DateTime.Now.Ticks; SumAndContStrategy strategy = new SumAndContStrategy(); int hits = strategy.GetOptimizedLine(wall); long tick2 = DateTime.Now.Ticks; return(new { hits, tick = tick2 - tick1 }); }
public dynamic Get(int rows, int bricks) { BrickWall wall = new BrickWall(); BrickWallGenerator generator = new BrickWallGenerator(); long tick1 = DateTime.Now.Ticks; wall = generator.GenerateBrickWall(rows, bricks); long tick2 = DateTime.Now.Ticks; return(new { wall, tick = tick2 - tick1 }); }
public dynamic Get(int rows, int bricks, int rowsInc, int bricksInc, int average) { BrickWallGenerator generator = new BrickWallGenerator(); BrickWall wall = new BrickWall(); List <float> millList = new List <float>(); List <float> hitsList = new List <float>(); SumAndContStrategy strategy = new SumAndContStrategy(); long tick1 = 0; long tick2 = 0; int bricksCount = bricksInc; int rowsCount = rowsInc; while (bricksCount < bricks || rowsCount < rows) { List <int> millListTemp = new List <int>(); List <int> hitsListTemp = new List <int>(); for (int i = 0; i < average; i++) { //Gera uma BrickWall para ser trabalhada wall = generator.GenerateBrickWall(rowsCount, bricksCount); tick1 = DateTime.Now.Ticks; //Descobre a linha que menos corta tijolos hitsListTemp.Add(strategy.GetOptimizedLine(wall)); tick2 = DateTime.Now.Ticks; millListTemp.Add(Convert.ToInt32(tick2 - tick1)); } if (rowsCount < rows) { rowsCount += rowsInc; } if (bricksCount < bricks) { bricksCount += bricksInc; } hitsList.Add(hitsListTemp.Sum() / average); millList.Add(millListTemp.Sum() / average); } return(new { millis = millList.ToArray(), hits = hitsList.ToArray() }); }
public void TestHandleCollisionPlayerWall() { var game = new Game(); var player = new Player(new Point(1, 0), game); var wall = new BrickWall(new Point(1, 0), game); var expected = player.PrevPosition; player.HandleCollision(wall); var actual = player.Position; Assert.AreEqual(expected, actual); }
/// <summary> /// Render a brickwall. /// </summary> /// <param name="brickWall">BrickWall model</param> /// <param name="squareSize">Maximum size of the containing square</param> /// <returns></returns> private static Rectangle RenderBrickWall(BrickWall brickWall, int squareSize) { var rectangle = new Rectangle { Height = squareSize, Width = squareSize, Fill = new VisualBrush( new PackIconMaterial { Kind = PackIconMaterialKind.ViewDashboard, // ViewDashboard icon looks like a brick wall Rotation = 90, // when rotated by 90 degrees Foreground = new SolidColorBrush(Colors.Brown), Opacity = brickWall.Health * 25 / 100.0 } ), Stroke = new SolidColorBrush(Colors.DimGray) }; return(rectangle); }
protected override void Start() { base.Start(); //initialMovementSpeed = 3f; movementSpeed = initialMovementSpeed; SetSpeed(movementSpeed); health = startingHealth; deathEvent += FindObjectOfType <EnemySpawner>().tankSpawner.OnEnemyDeath; deathEvent += FindObjectOfType <CoinSpawner>().ToSpawnCoin; enemyPassedEvent += FindObjectOfType <EnemySpawner>().tankSpawner.OnEnemyPassed; enemyPassedEvent += FindObjectOfType <PlayerMovement>().OnGeneralEnemyPassed; ws = FindObjectOfType <WallSpawner>(); bw = FindObjectOfType <BrickWall>(); animator = GetComponent <Animator>(); currInfo = animator.GetCurrentAnimatorStateInfo(0); animatorIdleNumber = (float)UnityEngine.Random.Range(0, 2); SetAnimationStates(false, false); enemyType = "Tank"; }
public void Open(string file) { objects = new List<MapObject>(); BufferReader reader = new BufferReader(file); if (Path.GetExtension(file) != ".adm") { throw new ArgumentException("File does not have *.adm extension."); } if (reader.ReadString() != "ADmapv2") { throw new ArgumentException("Not a valid Adrenaline map file."); } // general map info this.version = reader.ReadByte(); this.gridSize = reader.ReadByte(); // spare slots reader.Skip(15); this.Name = reader.ReadString(); this.Author = reader.ReadString(); this.floorType = reader.ReadByte(); // objects while (reader.HasMore()) { string objectType = reader.ReadString(); int instances = (int)reader.ReadUShort(); for (int i = 0; i < instances; i++) { ushort x = reader.ReadUShort(); ushort y = reader.ReadUShort(); MapObject obj = null; #region Object Creation switch (objectType) { // pickups case "objAbArmor": obj = new BulletArmorPickup(); break; case "objAbIncendary": obj = new BulletIncendiaryPickup(); break; case "objAbDefault": obj = new BulletNormalPickup(); break; case "objAbVelocity": obj = new BulletVelocityPickup(); break; case "objAnades": obj = new GrenadePickup(); break; case "objMedkit": obj = new HealthPickup(); break; case "objAeNormal": obj = new LaserPickup(); break; case "objAmines": obj = new MinePickup(); break; case "objApDisc": obj = new PlasmaDiscPickup(); break; case "objApFragma": obj = new PlasmaFragmaPickup(); break; case "objApHigh": obj = new PlasmaHighPickup(); break; case "objApNormal": obj = new PlasmaNormalPickup(); break; case "objAmNormal": obj = new RocketDualPickup(); break; case "objAmNade": obj = new RocketNukePickup(); break; case "objAcSniper": obj = new SniperPickup(); break; case "objAeSuper": obj = new SuperLaserPickup(); break; // static case "objSpawn": obj = new AllSpawn(); break; case "objFlagBlue": obj = new BlueFlag(); break; case "objFlagRed": obj = new RedFlag(); break; case "objTBlueSpawn": obj = new BlueSpawn(); break; case "objTRedSpawn": obj = new RedSpawn(); break; case "objLevelMine": obj = new LevelMine(); break; case "objTeleportDest": obj = new TeleportDestination(); break; case "objTeleportSrc": obj = new TeleportSource(); break; case "objStaticLight": obj = new Light(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()); break; // Walls case "objBlockWallBlocks": obj = new BlocksWall(); break; case "objBlockBrick": obj = new BrickWall(); break; case "objCube": obj = new CompanionCube(); break; case "objCompanion": obj = new Crate(); break; case "objBlockWall": obj = new GreyWall(); break; case "objBlockIceWall": obj = new IceWall(); break; case "objBlockLight": obj = new LightWall(); break; case "objBlockLightWall": obj = new LightWall2(); break; case "objBlockOld": obj = new OldWall(); break; case "objBlockRusty": obj = new RustyWall(); break; case "objBlockStripeWall": obj = new StripeWall(); break; case "objBlockWallpaper": obj = new WallpaperWall(); break; case "objBlockCrate": obj = new WoodWall(); break; // weapons case "objAssault": obj = new Assault(); break; case "objSawnOff": obj = new Curveshot(); break; case "objLaserRifle": obj = new Laser(); break; case "objLauncher": obj = new Launcher(); break; case "objMinigun": obj = new Minigun(); break; case "objPistol": obj = new IceWall(); break; case "Pistol": obj = new LightWall(); break; case "objPlasma": obj = new Plasma(); break; case "objShotgun": obj = new Shotgun(); break; case "objSMG": obj = new SMG(); break; case "objSniper": obj = new Sniper(); break; default: // no known object... better read bytes anyway reader.ReadUShort(); reader.ReadUShort(); break; } #endregion Object Creation if (obj != null) { obj.X = x; obj.Y = y; objects.Add(obj); } } } }
// Update is called once per frame void Update() { if (!exploded) { movement(); OutOfBoundsDestroy(); healthBar.fillAmount = health / startingHealth; RaycastHit[] hitArray = new RaycastHit[5]; RaycastHit hit; float[] spawnPositionX = new float[] { -5f, -3f, -1f, 1f, 3f, 5f }; float snapXPos = 0f; float minDistX = 1000f; for (int i = 0; i < 6; i++) { float dist = Mathf.Abs(spawnPositionX[i] - transform.position.x); if (dist < minDistX) { minDistX = dist; snapXPos = spawnPositionX[i]; } } for (int i = 0; i < 5; i++) { if (DetectWallAhead(4f, out hit, transform.position + Vector3.right * (-transform.position.x + snapXPos - 0.8f + 0.4f * i))) { Debug.Log("SnapX: " + snapXPos); float[] removalWallData = new float[2]; int listIndex = 0; int targetIndex = -1; if (i == 2) { removalWallData[0] = snapXPos; removalWallData[1] = ws.SnapWall(snapXPos, hit.point.z)[1]; foreach (float[] array in ws.wallPositionData) { if (array[0] == removalWallData[0] && array[1] == removalWallData[1]) { targetIndex = listIndex; } listIndex++; } } IDamageable damageableObject = hit.collider.GetComponent <IDamageable>(); if (damageableObject != null) { SetAnimationStates(true, false); currInfo = animator.GetCurrentAnimatorStateInfo(0); SetSpeed(0f); if (currInfo.normalizedTime > 0.5f && currInfo.IsName("Destroying")) { SetSpeed(movementSpeed); damageableObject.TakeHit(10f, Vector3.zero); animatorSpeedPercent = 0f; SetAnimationStates(false, false); if (i == 2) { if (hit.collider.GetComponent <BrickWall>() != null) { if (hit.collider.GetComponent <BrickWall>().instanceBuildStatus == BrickWall.buildStatus.Built) { int arrayIndex; switch (removalWallData[0]) { case -5f: arrayIndex = 0; break; case -3f: arrayIndex = 1; break; case -1f: arrayIndex = 2; break; case 1f: arrayIndex = 3; break; case 3f: arrayIndex = 4; break; case 5f: arrayIndex = 5; break; default: arrayIndex = 100; break; } ws.columnArrays[arrayIndex].Remove(removalWallData[1]); } } } if (targetIndex != -1) { //StartCoroutine(RemoveFromArrayList(targetIndex)); ws.wallPositionData.RemoveAt(targetIndex); } if (i == 2) { BrickWall brickwall = (BrickWall)damageableObject; brickwall.UnblockNearblyWallPlacement(); } } /* * damageableObject.TakeHit(10f, Vector3.zero); * animatorSpeedPercent = 0f; * SetAnimationStates(true, false); * * if(i==2){ * BrickWall brickwall = (BrickWall) damageableObject; * brickwall.UnblockNearblyWallPlacement(); * } */ } else { //if(detectTankAhead(1f, transform.position + Vector3.up * 2f)){ SetSpeed(0f); animatorSpeedPercent = animatorIdleNumber; SetAnimationStates(false, true); animator.SetFloat("speedPercent", animatorIdleNumber); //} } } else { if (i == 2) { if (detectTankAhead(1f, transform.position + Vector3.up * 2f)) { SetSpeed(0f); animatorSpeedPercent = animatorIdleNumber; SetAnimationStates(false, true); animator.SetFloat("speedPercent", animatorIdleNumber); } else { SetSpeed(movementSpeed); animatorSpeedPercent = 3f; SetAnimationStates(false, false); } } } } //animator.SetFloat("speedPercent", animatorSpeedPercent); //Debug.Log(animatorSpeedPercent + " " + animatorIdleNumber); transform.position -= Vector3.up; } }
/// <summary> /// Generates the basic walls, floor, and entrance for any building. /// Picks the exact position of entrance, and returns it /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="buildingObjects">Building objects to be filled with walls</param> /// <param name="buildTiles"></param> /// <param name="entranceID"></param> /// <param name="style"></param> /// <returns></returns> public static Vec2i GenerateWallsFloorAndEntrance(int width, int height, WorldObjectData[,] buildingObjects, Tile[,] buildTiles, int entranceID, BuildingStyle style, int entraceDis = -1, WorldObjectData wallType = null, Tile tileType = null) { int entWidth = 2; if (entraceDis == -1) { if (entranceID == NORTH_ENTRANCE || entranceID == SOUTH_ENTRANCE) { entraceDis = MiscMaths.RandomRange(1, width - 1); } else { entraceDis = MiscMaths.RandomRange(1, height - 1); } } //Decide the position of the entrance Vec2i entrance = null; if (entranceID == NORTH_ENTRANCE) { entrance = new Vec2i(entraceDis, height - 1); } else if (entranceID == SOUTH_ENTRANCE) { entrance = new Vec2i(entraceDis, 0); } else if (entranceID == EAST_ENTRANCE) { entrance = new Vec2i(width - 1, entraceDis); } else if (entranceID == WEST_ENTRANCE) { entrance = new Vec2i(0, entraceDis); } //Assign correct wall type if none given if (wallType == null) { switch (style) { case BuildingStyle.stone: wallType = new BrickWall(new Vec2i(0, 0)); break; case BuildingStyle.wood: //TODO - Add wallType = new BrickWall(new Vec2i(0, 0)); break; } }//Asign correct tile type if none given if (tileType == null) { switch (style) { case BuildingStyle.stone: tileType = Tile.STONE_FLOOR; break; case BuildingStyle.wood: tileType = Tile.WOOD_FLOOR; break; } } //Iterate all points for (int x = 0; x < width; x++) { for (int z = 0; z < height; z++) { //Asign tile buildTiles[x, z] = tileType; if (x == 0 || x == width - 1 || z == 0 || z == height - 1) { //Asign wall if no entrance if (!(entrance.x == x & entrance.z == z)) { if (x == 3) { buildingObjects[x, z] = new BuildingWall(new Vec2i(0, 0), "brick", 5, new GlassWindow(new Vec2i(0, 0), new Vec2i(0, 1)), 2); } else { buildingObjects[x, z] = new BuildingWall(new Vec2i(0, -1), "brick", 5); } } } } } //(buildingObjects[0, 0] as BuildingWall).AddRoof(new Roof(new Vec2i(0, 0), new Vec2i(width, height))); return(entrance); }