public virtual void Move(MoveDirectionEnum direction, int value) { var level = GetLevel(); level[PositionX, PositionY] = new EmptySpace(PositionX, PositionY); switch (direction) { case MoveDirectionEnum.Vertical: PositionY += value; if (!IsValid(level)) { PositionY -= value; } break; case MoveDirectionEnum.Horizontal: PositionX += value; if (!IsValid(level)) { PositionX -= value; } break; } level[PositionX, PositionY] = this; }
private void UseDynamite() { _playSound(SoundFilesEnum.BombSound); Energy -= UseDynamiteCost; var level = GetLevel(); double dmg = 0; for (var x = -1; x < 2; x++) { for (var y = -1; y < 2; y++) { var posX = x + PositionX; var posY = y + PositionY; if (!IsLevelCellValid(posX, posY, level.Width, level.Height)) { continue; } if (level[posX, posY] is Enemy enemy) { enemy.SubstractEnemyHp(Convert.ToInt32(dmg)); } else if (level[posX, posY] is Player.Player player) { player.SubstractPlayerHp(Convert.ToInt32(dmg)); } else { level[posX, posY] = new EmptySpace(posX, posY); } dmg += DynamiteTileDamage; } } Log("Bot decided use dynamite"); }
private void Teleport() { _playSound(SoundFilesEnum.TeleportSound); Energy -= TeleportCost; var level = GetLevel(); int posX; int posY; do { posX = Randomizer.Random(level.Width); posY = Randomizer.Random(level.Height); } while (Math.Abs(PositionX - posX) + Math.Abs(PositionY - posY) > TeleportRange); level[PositionX, PositionY] = new EmptySpace(PositionX, PositionY); var pathfinder = new Pathfinder(); var path = pathfinder.FindPath(PositionX, PositionY, posX, posY, level, (l, p) => true); var task = new Task(() => { foreach (var point in path) { PositionX = point.X; PositionY = point.Y; var temp = level[PositionX, PositionY]; level[PositionX, PositionY] = this; Thread.Sleep(50); level[PositionX, PositionY] = temp; } level[PositionX, PositionY] = this; }); task.Start(); Log("Bot decided to use teleport"); }
public void ItemRotate() { _space = transform.parent.GetComponent <EmptySpace>(); Vector3 angle = _space.GetSideRotation(); transform.rotation = Quaternion.Euler(angle); }
public RadioToggle(string title, System.Func <bool> getValueCallback = null, System.Action <bool> setValueCallback = null) { var horizontal = new HorizontalLayout(); _value = new ValueComponent <bool>(getValueCallback, setValueCallback); _filled = new EmptySpace(); _filled.Style.Set(Styles.Margin, Dim.right * 5); horizontal.Attach(_filled, new Label(title)); AddChild(horizontal); }
private void Move(Level level, Point dest) { if (!level[dest.X, dest.Y].CanMove) { return; } level[dest.X, dest.Y].BreakAction(this); level[dest.X, dest.Y] = this; level[PositionX, PositionY] = new EmptySpace(PositionX, PositionY); PositionX = dest.X; PositionY = dest.Y; }
public ToggleBase(string title) : base() { // var horizontal = new HorizontalLayout(); _filled = new EmptySpace(); _filled.Style.Set(Styles.Border, new Dim(2)); _filled.Style.Set(Styles.Margin, Dim.right * 5); /* horizontal. */ Attach(_filled, _label = new Label(title)); // AddChild(horizontal); Theme.Current.Apply(this, typeof(ToggleBase)); }
private GameEntity FillOneTitle(int i, int j, Func <Level> getLevel, Action <int> changePlayerHp, GameEntitiesEnum entityType) { switch (entityType) { case GameEntitiesEnum.Rock: var rock = new Rock(i, j, getLevel, changePlayerHp); return(rock); default: var es = new EmptySpace(i, j); return(es); } }
private void EnemyMovement() { var level = GetLevel(); Point dest; try { dest = GetNextPosition(level, GetPlayerPosX(), GetPlayerPosY()); } catch (Exception) { return; } if (!(level[dest.X, dest.Y] is Player.Player)) { level[dest.X, dest.Y] = this; level[PositionX, PositionY] = new EmptySpace(PositionX, PositionY); PositionX = dest.X; PositionY = dest.Y; } }
/// <summary> /// Executes behavior with given context /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override BehaviorReturnCode Behave(IBehaviorContext context) { UnitBehaviorContext unitContext = context as UnitBehaviorContext; if (unitContext == null) { returnCode = BehaviorReturnCode.Failure; return(returnCode); } EmptySpace space = unitContext.Unit.Environment as EmptySpace; if (space == null) { returnCode = BehaviorReturnCode.Failure; return(returnCode); } returnCode = BehaviorReturnCode.Failure; unitContext.EnvironmentTarget = null; foreach (var body in space.EnvironmentMap.Values) { Anomaly anomaly = body as Anomaly; if (anomaly == null) { continue; } unitContext.EnvironmentTarget = body; break; } if (unitContext.EnvironmentTarget != null) { context.AddLogMessage("Anomaly found."); returnCode = BehaviorReturnCode.Success; } return(returnCode); }
public Slider(string title, System.Func <float> getValueCallback = null, System.Action <float> setValueCallback = null, float min = 0, float max = 1, float width = 100f) : base(width) { _valueComponent = new ValueComponent <float>(getValueCallback, setValueCallback); _max = max; _min = min; _inactiveBar = new HorizontalGrid(); _activeBar = new EmptySpace(); _verticalLayout = new VerticalLayout(); _valueLabel = new ValueLabel(title, () => string.Format("{0:0.00}", Value)); Value = getValueCallback(); _verticalLayout.Attach( _inactiveBar.Attach( new HorizontalLayout().Attach( _activeBar ) ) ); BuildLayout(); }
public void UseDynamite() { if (Inventory.TntQuantity == 0) { return; } _playSound(SoundFilesEnum.BombSound); Inventory.TntQuantity--; AchievementsController.WasBombUsed = true; var level = GetLevel(); double dmg = 0; for (var x = -2; x < 3; x++) { for (var y = -2; y < 3; y++) { if (x == 0 && y == 0 || (x == -2 || x == 2) && (y == -2 || y == 2)) { continue; } var posX = x + PositionX; var posY = y + PositionY; if (!IsLevelCellValid(posX, posY, level.Width, level.Height)) { continue; } if (level[posX, posY] is Enemy enemy) { enemy.SubstractEnemyHp(Convert.ToInt32(dmg)); } else { level[posX, posY] = new EmptySpace(posX, posY); } dmg += DynamiteTileDamage; } } Energy = Energy / 2; SubstractPlayerHp(Convert.ToInt32(dmg), PlayerAnimationsEnum.Explosion); }
public void Teleport() { if (Energy < MaxEnergy) { return; } _playSound(SoundFilesEnum.TeleportSound); var level = GetLevel(); Energy = 0; int posX; int posY; do { posX = Randomizer.Random(level.Width); posY = Randomizer.Random(level.Height); } while (Math.Abs(PositionX - posX) + Math.Abs(PositionY - posY) > _teleportRange); level[PositionX, PositionY] = new EmptySpace(PositionX, PositionY); var pathfinder = new Pathfinder(); var path = pathfinder.FindPath(PositionX, PositionY, posX, posY, level, (l, p) => true); var task = new Task(() => { foreach (var point in path) { SetAnimation(PlayerAnimationsEnum.Teleport); PositionX = point.X; PositionY = point.Y; var temp = level[PositionX, PositionY]; level[PositionX, PositionY] = this; Thread.Sleep(50); level[PositionX, PositionY] = temp; } level[PositionX, PositionY] = this; }); task.Start(); }
public void GenerateMap() { //Make a list of tiles. When foreachly drawn they produce current map. try { //Reading text-file StreamReader streamReader = new StreamReader("Content/Maps/map1.txt"); String wholeString = streamReader.ReadToEnd(); String[] wholeStringSplits = wholeString.Split('.'); //Finding dimensions String wholeDimensions = wholeStringSplits[0]; String[] dimensions = wholeDimensions.Split(new char[] { '\r', '\n', ',' }, StringSplitOptions.RemoveEmptyEntries); boardSizeColumns = Int32.Parse(dimensions[0]); boardSizeRows = Int32.Parse(dimensions[1]); //Generating map for (int count = 0; count < boardSizeColumns; count++) { tiles[count] = new Dictionary <int, Tile>(); } String wholeMap = wholeStringSplits[1]; String[] singleTiles = wholeMap.Split(new char[] { '\r', '\n', ',' }, StringSplitOptions.RemoveEmptyEntries); int currentColumnTiles = 0; int currentRowTiles = 0; foreach (String tileString in singleTiles) { int tileType = Int32.Parse(tileString); Tile tile; tile = new Tile(tileTextures[(TileType)tileType], currentColumnTiles, currentRowTiles); tiles[currentColumnTiles][currentRowTiles] = tile; currentColumnTiles++; if (currentColumnTiles > boardSizeColumns - 1) { currentColumnTiles = 0; currentRowTiles++; } } //Generating objects for (int count = 0; count < boardSizeColumns; count++) { boardObjects[count] = new Dictionary <int, BoardObject>(); } String wholeUnits = wholeStringSplits[2]; String[] singleUnits = wholeUnits.Split(new char[] { '\r', '\n', ',' }, StringSplitOptions.RemoveEmptyEntries); int currentColumnObjects = 0; int currentRowObjects = 0; foreach (String unitString in singleUnits) { String[] belongsToAndUnitNumberString = unitString.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries); String belongsToString = belongsToAndUnitNumberString[0]; Player belongsTo = nobody; if (belongsToString == "p1") { belongsTo = player1; } else if (belongsToString == "p2") { belongsTo = player2; } int objectNumber = Int32.Parse(belongsToAndUnitNumberString[1]); BoardObject boardObject; if (objectNumber == 0) { boardObject = new EmptySpace(currentColumnObjects, currentRowObjects, belongsTo); } else { boardObject = new Unit(objectTextures[(ObjectType)objectNumber], dotTexture, (ObjectType)objectNumber, 2, currentColumnObjects, currentRowObjects, belongsTo); belongsTo.AssignUnit((Unit)boardObject); } boardObjects[currentColumnObjects][currentRowObjects] = boardObject; currentColumnObjects++; if (currentColumnObjects > boardSizeColumns - 1) { currentColumnObjects = 0; currentRowObjects++; } } } catch { //Error while loading board } selectedUnit = currentPlayer.FirstUnit(); //activeTile = tiles[selectedUnit.BoardColumnIndex][selectedUnit.BoardRowIndex]; highlight.ChangePosition(selectedUnit.BoardColumnIndex, selectedUnit.BoardRowIndex); highlight.DrawHighlight = true; }
private void MakePreviousPositionEmpty(Level level) { level[PositionX, PositionY] = new EmptySpace(PositionX, PositionY); }
public void ChooseEmptySpaceTests() { var emptySpace = new EmptySpace(); }
public Room(int i) { if (i <= 13) { room = new Block[emptyRoomTemplate.GetLength(0), emptyRoomTemplate.GetLength(1)]; for (int y = 0; y < emptyRoomTemplate.GetLength(0); y++) { for (int x = 0; x < emptyRoomTemplate.GetLength(1); x++) { if (emptyRoomTemplate[y, x] == 0) { room[y, x] = new EmptySpace(); } else if (emptyRoomTemplate[y, x] == 1) { room[y, x] = new Wall.Outer(); } else if (emptyRoomTemplate[y, x] == 2) { Wall.Inner wall; if (emptyRoomTemplate[y, x - 1] == 2 || emptyRoomTemplate[y, x - 1] == 1) { int min = Math.Min(emptyRoomTemplate[y - 1, x] - 2, emptyRoomTemplate[y + 1, x] - 2); int max = Math.Max(emptyRoomTemplate[y - 1, x] - 2, emptyRoomTemplate[y + 1, x] - 2); wall = new Wall.Inner(min, max, x, y); } else { int min = Math.Min(emptyRoomTemplate[y, x - 1] - 2, emptyRoomTemplate[y, x + 1] - 2); int max = Math.Max(emptyRoomTemplate[y, x - 1] - 2, emptyRoomTemplate[y, x + 1] - 2); wall = new Wall.Inner(min, max, x, y); } room[y, x] = wall; mergeWall(wall); } else { room[y, x] = new Floor.Vanilla(); } } } createTree(); shuffleList(); explodeWalls(); } else { room = new Block[treasureRoomTemplate.GetLength(0), treasureRoomTemplate.GetLength(1)]; for (int y = 0; y < treasureRoomTemplate.GetLength(0); y++) { for (int x = 0; x < treasureRoomTemplate.GetLength(1); x++) { if (treasureRoomTemplate[y, x] == 1) { room[y, x] = new Wall.Outer(); } else { room[y, x] = new Floor.Vanilla(); } } } } }
public void create() { PlayerPrefs.DeleteAll(); PlayerPrefs.SetInt("Lives", 3); var mainLayout = MyGameObject.Instantiate <VerticalStack>(); mainLayout.ActualDimentions = this.ActualDimentions; LabelMenu = MyGameObject.Instantiate <MyGameLabel>(); LabelMenu.create("MENU", 5f, Color.white); LabelMenu.TextFontSize = 15; LabelMenu.AligmentMode = TextAnchor.MiddleCenter; mainLayout.AddChildren(LabelMenu); //------------Boton GovermentWorkOut---------- EmptySpace GovermentWorkOut_Button = MyGameObject.Instantiate <EmptySpace>(); GovermentWorkOut_Button.ActualDimentions = new Vector3(0.6f, 0.2f, 1f); GovermentWorkOut_Button.MarginProperty.Top = 0.05f; GovermentWorkOut_Button.createColiderBackground(); GovermentWorkOut_Button.setBackground("Textures/MenuGamesMain/yellowButton", true); LabelGovernmentWorkOut = MyGameObject.Instantiate <MyGameLabel>(); LabelGovernmentWorkOut.create("Government work out", 2f, Color.white); LabelGovernmentWorkOut.TextFontSize = 3; LabelGovernmentWorkOut.AligmentMode = TextAnchor.MiddleCenter; GovermentWorkOut_Button.AddChildren(LabelGovernmentWorkOut); // -- Redirecciona a la Scene correspondiente GovermentWorkOut_Button.TapEvent += (MyGameObject sender, System.EventArgs e) => { SceneManager.LoadScene("GovermentWorkOut"); }; //------------------------------------------------ //------------Boton BalanceTheWorld---------- EmptySpace BalanceTheWorld_Button = MyGameObject.Instantiate <EmptySpace>(); BalanceTheWorld_Button.ActualDimentions = new Vector3(0.6f, 0.2f, 1f); BalanceTheWorld_Button.MarginProperty.Top = 0.05f; BalanceTheWorld_Button.createColiderBackground(); BalanceTheWorld_Button.setBackground("Textures/MenuGamesMain/redButton", true); LabelBalanceTheWorld = MyGameObject.Instantiate <MyGameLabel>(); LabelBalanceTheWorld.create("Balance The World", 2f, Color.white); LabelBalanceTheWorld.TextFontSize = 3; LabelBalanceTheWorld.AligmentMode = TextAnchor.MiddleCenter; BalanceTheWorld_Button.AddChildren(LabelBalanceTheWorld); // -- Redirecciona a la Scene correspondiente BalanceTheWorld_Button.TapEvent += (MyGameObject sender, System.EventArgs e) => { SceneManager.LoadScene("TheWorldBalance"); }; //------------------------------------------------ //------------Boton TaxMan---------- EmptySpace TaxMan_Button = MyGameObject.Instantiate <EmptySpace>(); TaxMan_Button.ActualDimentions = new Vector3(0.6f, 0.2f, 1f); TaxMan_Button.MarginProperty.Top = 0.05f; TaxMan_Button.createColiderBackground(); TaxMan_Button.setBackground("Textures/MenuGamesMain/yellowButton", true); LabelTaxMan = MyGameObject.Instantiate <MyGameLabel>(); LabelTaxMan.create("Avoid the TaxMan", 2f, Color.white); LabelTaxMan.TextFontSize = 3; LabelTaxMan.AligmentMode = TextAnchor.MiddleCenter; TaxMan_Button.AddChildren(LabelTaxMan); // -- Redirecciona a la Scene correspondiente TaxMan_Button.TapEvent += (MyGameObject sender, System.EventArgs e) => { SceneManager.LoadScene("TaxMan"); }; //------------------------------------------------ //------------Boton Investment---------- EmptySpace Investment_Button = MyGameObject.Instantiate <EmptySpace>(); Investment_Button.ActualDimentions = new Vector3(0.6f, 0.2f, 1f); Investment_Button.MarginProperty.Top = 0.05f; Investment_Button.createColiderBackground(); Investment_Button.setBackground("Textures/MenuGamesMain/redButton", true); LabelInvestment = MyGameObject.Instantiate <MyGameLabel>(); LabelInvestment.create("Invest To Progress", 2f, Color.white); LabelInvestment.TextFontSize = 3; LabelInvestment.AligmentMode = TextAnchor.MiddleCenter; Investment_Button.AddChildren(LabelInvestment); // -- Redirecciona a la Scene correspondiente Investment_Button.TapEvent += (MyGameObject sender, System.EventArgs e) => { SceneManager.LoadScene("InvestToProgress"); }; //------------------------------------------------ //------------Boton Censorship---------- EmptySpace Censorship_Button = MyGameObject.Instantiate <EmptySpace>(); Censorship_Button.ActualDimentions = new Vector3(0.6f, 0.2f, 1f); Censorship_Button.MarginProperty.Top = 0.05f; Censorship_Button.createColiderBackground(); Censorship_Button.setBackground("Textures/MenuGamesMain/yellowButton", true); LabelCensorship = MyGameObject.Instantiate <MyGameLabel>(); LabelCensorship.create("Censorship", 2f, Color.white); LabelCensorship.TextFontSize = 3; LabelCensorship.AligmentMode = TextAnchor.MiddleCenter; Censorship_Button.AddChildren(LabelCensorship); // -- Redirecciona a la Scene correspondiente Censorship_Button.TapEvent += (MyGameObject sender, System.EventArgs e) => { SceneManager.LoadScene("CensorShip"); }; //------------------------------------------------ //------------Boton NetWorking---------- EmptySpace NetWorking_Button = MyGameObject.Instantiate <EmptySpace>(); NetWorking_Button.ActualDimentions = new Vector3(0.6f, 0.2f, 1f); NetWorking_Button.MarginProperty.Top = 0.05f; NetWorking_Button.createColiderBackground(); NetWorking_Button.setBackground("Textures/MenuGamesMain/redButton", true); LabelNetworking = MyGameObject.Instantiate <MyGameLabel>(); LabelNetworking.create("Free Trade", 2f, Color.white); LabelNetworking.TextFontSize = 3; LabelNetworking.AligmentMode = TextAnchor.MiddleCenter; NetWorking_Button.AddChildren(LabelNetworking); // -- Redirecciona a la Scene correspondiente NetWorking_Button.TapEvent += (MyGameObject sender, System.EventArgs e) => { SceneManager.LoadScene("Networking"); }; //------------------------------------------------ //------------Boton Bureaucracy_Button---------- EmptySpace Bureaucracy_Button = MyGameObject.Instantiate <EmptySpace>(); Bureaucracy_Button.ActualDimentions = new Vector3(0.6f, 0.2f, 1f); Bureaucracy_Button.MarginProperty.Top = 0.05f; Bureaucracy_Button.createColiderBackground(); Bureaucracy_Button.setBackground("Textures/MenuGamesMain/yellowButton", true); LabelB = MyGameObject.Instantiate <MyGameLabel>(); LabelB.create("Bureaucracy", 2f, Color.white); LabelB.TextFontSize = 3; LabelB.AligmentMode = TextAnchor.MiddleCenter; Bureaucracy_Button.AddChildren(LabelB); // -- Redirecciona a la Scene correspondiente Bureaucracy_Button.TapEvent += (MyGameObject sender, System.EventArgs e) => { SceneManager.LoadScene("Bureaucracy"); }; //------------------------------------------------ //------------Boton TradeBarriers_Button---------- EmptySpace TradeBarriers_Button = MyGameObject.Instantiate <EmptySpace>(); TradeBarriers_Button.ActualDimentions = new Vector3(0.6f, 0.2f, 1f); TradeBarriers_Button.MarginProperty.Top = 0.05f; TradeBarriers_Button.createColiderBackground(); TradeBarriers_Button.setBackground("Textures/MenuGamesMain/redButton", true); LabelTRadeBarriers = MyGameObject.Instantiate <MyGameLabel>(); LabelTRadeBarriers.create("JumpTheTradeBarriers", 2f, Color.white); LabelTRadeBarriers.TextFontSize = 3; LabelTRadeBarriers.AligmentMode = TextAnchor.MiddleCenter; TradeBarriers_Button.AddChildren(LabelTRadeBarriers); // -- Redirecciona a la Scene correspondiente TradeBarriers_Button.TapEvent += (MyGameObject sender, System.EventArgs e) => { SceneManager.LoadScene("JumpTheTradeBarriers"); }; //------------------------------------------------ //------------Boton Memory_button---------- EmptySpace Memory_button = MyGameObject.Instantiate <EmptySpace>(); Memory_button.ActualDimentions = new Vector3(0.6f, 0.2f, 1f); Memory_button.MarginProperty.Top = 0.05f; Memory_button.createColiderBackground(); Memory_button.setBackground("Textures/MenuGamesMain/yellowButton", true); LabelMemory = MyGameObject.Instantiate <MyGameLabel>(); LabelMemory.create("Memory", 2f, Color.white); LabelMemory.TextFontSize = 3; LabelMemory.AligmentMode = TextAnchor.MiddleCenter; Memory_button.AddChildren(LabelMemory); // -- Redirecciona a la Scene correspondiente Memory_button.TapEvent += (MyGameObject sender, System.EventArgs e) => { SceneManager.LoadScene("Memory"); }; //------------------------------------------------ // se hace el boton hijo de la Scene principal mainLayout.AddChildren(GovermentWorkOut_Button); mainLayout.AddChildren(BalanceTheWorld_Button); mainLayout.AddChildren(TaxMan_Button); mainLayout.AddChildren(Investment_Button); mainLayout.AddChildren(Censorship_Button); mainLayout.AddChildren(NetWorking_Button); mainLayout.AddChildren(Bureaucracy_Button); mainLayout.AddChildren(TradeBarriers_Button); mainLayout.AddChildren(Memory_button); this.AddChildren(mainLayout); this.setBackground("Textures/MenuGamesMain/blackButton", true); this.correctCenter(false); }