public int attack(Enemy.EnemyClass enemy) { Random damageDealt = new Random(); int minDamageAfterArmor = minDamage * (100 - enemy.armor)/100; int maxDamageAfterArmor = maxDamage * (100 - enemy.armor) / 100; return damageDealt.Next(minDamageAfterArmor, maxDamageAfterArmor); }
public int attack(Enemy.EnemyClass enemy) { Random damageDealt = new Random(); int minDamageAfterArmor = (int) MinDamageWithEquipment() * (100 - enemy.armor)/100; int maxDamageAfterArmor = (int) MaxDamageWithEquipment() * (100 - enemy.armor) / 100; return damageDealt.Next(minDamageAfterArmor, maxDamageAfterArmor); }
public void AddTilesAndTileObjects(int[,] tileTextureMap, int[,] tileObjectTextureMap) { for (int x = 0; x < MapWidth; x++) { for (int y = 0; y < MapHeight; y++) { int tileTextureIndex = tileTextureMap[y, x]; if (tileTextureIndex != -1) _tiles[y, x] = new Tile(new Point(x, y), Texture.tileTextures[tileTextureIndex]); if (tileTextureIndex == 1) _tiles[y, x]._active = true; //For tiles that are stone, mark them as active, this will need better implementation to allow for different active textures int tileObjectTextureIndex = tileObjectTextureMap[y, x]; if (tileObjectTextureIndex != -1) { //these two conditionals probably shouldnt be here if (tileObjectTextureIndex == 4) { _tiles[y, x]._tileObject = _players[0]; _observers.Add(_players[0]); } //make tile inactive if the tile object is an enemy else if (tileObjectTextureIndex == 5) { Enemy enemy = new Enemy(new Point(x, y), Texture.tileObjectTextures[tileObjectTextureIndex], 100, 100, 100, false); _tiles[y, x]._tileObject = enemy; _tiles[y, x]._active = false; _observers.Add(enemy); } else { TileObject to = new TileObject(new Point(x, y), Texture.tileObjectTextures[tileObjectTextureIndex]); _tiles[y, x]._tileObject = to; _observers.Add(to); } } } } for (int x = 0; x < MapWidth; x++) { for (int y = 0; y < MapHeight; y++) { if (y - 1 >= 0) _tiles[y, x]._top = _tiles[y - 1, x]; if (y + 1 < MapHeight) _tiles[y, x]._bottom = _tiles[y + 1, x]; if (x - 1 >= 0) _tiles[y, x]._left = _tiles[y, x - 1]; if (x + 1 < MapWidth) _tiles[y, x]._right = _tiles[y, x + 1]; } } }
protected override void Update(GameTime gameTime) { if (lastRollDisplayed > 0 && gameTime.TotalGameTime.TotalSeconds - lastRollDisplayed > 2) { lastRollDisplayed = 0; playerDieTexture = null; enemyDieTexture = null; } switch (gameState) { case Constants.GAME_STATE.Roll: if (tileMap.IsBattleTile(current)) { gameState = Constants.GAME_STATE.SecondAction; break; } if (TouchPanel.IsGestureAvailable) { GestureSample gesture = TouchPanel.ReadGesture(); if (gesture.GestureType == GestureType.Tap) { lastRollDisplayed = gameTime.TotalGameTime.TotalSeconds; movesLeft = Die.getInstance().roll(); playerDieTexture = Texture.diceTextures.ElementAt<Texture2D>(movesLeft - 1); //Calculate moveable squares Tuple<int, Point> message = new Tuple<int, Point>(movesLeft, current._location); tileMap.FindMoveableTiles(message); gameState = Constants.GAME_STATE.Move; } } break; case Constants.GAME_STATE.FirstAction: if (TouchPanel.IsGestureAvailable) { GestureSample gesture = TouchPanel.ReadGesture(); if (gesture.GestureType == GestureType.Tap) { lastRollDisplayed = gameTime.TotalGameTime.TotalSeconds; gameState = Constants.GAME_STATE.SecondAction; } } break; case Constants.GAME_STATE.Move: engagedEnemy = tileMap.FindAdjacentEnemies(current); if (engagedEnemy != null) { gameState = Constants.GAME_STATE.SecondAction; break; } if (movesLeft == 0) gameState = Constants.GAME_STATE.Roll; if (TouchPanel.IsGestureAvailable) { GestureSample gesture = TouchPanel.ReadGesture(); if (gesture.GestureType == GestureType.FreeDrag) tileMap._camera.MoveCamera(-gesture.Delta); if (gesture.GestureType == GestureType.Tap) { int x = (int)tileMap._camera._cameraPosition.X + (int)gesture.Position.X - Constants.MARGIN_LEFT; int y = (int)tileMap._camera._cameraPosition.Y + (int)gesture.Position.Y - Constants.MARGIN_TOP; TileObject to = current._tileObject; Tile t = tileMap.GetTile(new Point(x / Constants.TILE_WIDTH, y / (Constants.TILE_HEIGHT - Constants.TILE_OFFSET))); if (tileMap.MoveTileObject(to, new Point(t._location.X, t._location.Y))) { movesLeft -= (Math.Abs(current._location.X - t._location.X) + Math.Abs(current._location.Y - t._location.Y)); current = t; Tuple<int, Point> message = new Tuple<int, Point>(movesLeft, current._location); tileMap.FindMoveableTiles(message); if (tileMap.IsBattleTile(current)) break; if (movesLeft == 0) gameState = Constants.GAME_STATE.Roll; } } } break; case Constants.GAME_STATE.SecondAction: if (TouchPanel.IsGestureAvailable) { GestureSample gesture = TouchPanel.ReadGesture(); if (gesture.GestureType == GestureType.Tap) { Player player = (Player) current._tileObject; lastRollDisplayed = gameTime.TotalGameTime.TotalSeconds; playerRoll = Die.getInstance().roll(); playerDieTexture = Texture.diceTextures.ElementAt<Texture2D>(playerRoll - 1); enemyRoll = Die.getInstance().roll(); enemyDieTexture = Texture.diceTextures.ElementAt<Texture2D>(enemyRoll - 1); if (playerRoll > enemyRoll) { engagedEnemy._health -= 1; if (engagedEnemy._health == 0) { tileMap.RemoveTileObject(engagedEnemy); Tuple<TileObject, TileObject> bundle = new Tuple<TileObject, TileObject>(player, engagedEnemy); tileMap.notifyObservers(Constants.GAME_UPDATE.Capture, bundle); } if (movesLeft == 0) gameState = Constants.GAME_STATE.Roll; } else if (playerRoll == enemyRoll) { engagedEnemy._health -= 1; if (engagedEnemy._health == 0) { tileMap.RemoveTileObject(engagedEnemy); Tuple<TileObject, TileObject> bundle = new Tuple<TileObject, TileObject>(player, engagedEnemy); tileMap.notifyObservers(Constants.GAME_UPDATE.Capture, bundle); } player._health -= 1; //GAME OVER! if (player._health == 0) tileMap.RemoveTileObject(player); if (movesLeft == 0) gameState = Constants.GAME_STATE.Roll; } else { player._health -= 1; //GAME OVER! if (player._health == 0) tileMap.RemoveTileObject(player); if (movesLeft == 0) gameState = Constants.GAME_STATE.Roll; } Tuple<int, Point> message = new Tuple<int, Point>(movesLeft, current._location); tileMap.FindMoveableTiles(message); gameState = Constants.GAME_STATE.Move; } } break; case Constants.GAME_STATE.End: break; } // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); base.Update(gameTime); }
public bool Attacks(IAttack attack, Enemy target, bool ActionCommandSuccessful) { return(target.TakeDamage(this.protection, attack, ActionCommandSuccessful)); }