示例#1
0
        private GameState TankAction(CombatTank t1, CombatTank t2, bool blueRound)
        {
            var xEnemy   = t2.PosX;
            var yEnemy   = t2.PosY;
            var step     = 0;
            var gamePath = PathAlgo.GetPath(GameMap, new Point2D(t1.PosX, t1.PosY), new Point2D(t2.PosX, t2.PosY),
                                            GameDiagonalMovement.Never).ToArray();

            do
            {
                if (t1.IsEnemyInRange(xEnemy, yEnemy))
                {
                    if (t1.CanShoutEnemy(xEnemy, yEnemy, GameMap))
                    {
                        t2.ShieldLife -= t1.GunPower;
                        break;
                    }
                }
                step++;
                if (step < gamePath.Length)
                {
                    t1.PosX = gamePath[step].X;
                    t1.PosY = gamePath[step].Y;
                }
            } while (step < t1.Speed);
            return(blueRound ? new GameState(t1, t2) : new GameState(t2, t1));
        }
示例#2
0
        /// <summary>
        /// Init batle game between two tanks set on a 2d map
        /// </summary>
        /// <param name="map">Map is stored as int map; value 0 means empty, other value (1) means not empty</param>
        /// <param name="blueTankModel">First tank in battlefield</param>
        /// <param name="posBlue">2 length array represents postion of blue tank on map</param>
        /// <param name="redTankModel">second tank in battlefield</param>
        /// <param name="posRed">2 length array represents postion of red tank on map</param>
        /// <param name="maxTurns">Maximum number of game's turns</param>
        public TankBattleGame(int[][] map, TankModel blueTankModel, int[] posBlue, TankModel redTankModel, int[] posRed, int maxTurns = 100)
        {
            MaxTurns = maxTurns;
            GameMap  = map;
            var validator = new TankModelValidator();

            var resultBlueTankModel = validator.Validate(blueTankModel);

            if (!resultBlueTankModel.IsValid)
            {
                throw new Exception($"Tank model failed, Exception message{resultBlueTankModel.Errors[0].ErrorMessage}");
            }

            var resultRedTankModel = validator.Validate(redTankModel);

            if (!resultRedTankModel.IsValid)
            {
                throw new Exception($"Tank model failed, Exception message{resultRedTankModel.Errors[0].ErrorMessage}");
            }

            BlueTank = new CombatTank(posBlue[0], posBlue[1], blueTankModel);
            RedTank  = new CombatTank(posRed[0], posRed[1], redTankModel);
            PathAlgo = new AStar();
        }
示例#3
0
 public GameState(CombatTank blueTank, CombatTank redTank)
 {
     BlueTank = new CombatTank(blueTank.ModelName, blueTank.Speed, blueTank.GunRange, blueTank.GunPower, blueTank.ShieldLife, blueTank.PosX, blueTank.PosY);
     RedTank  = new CombatTank(redTank.ModelName, redTank.Speed, redTank.GunRange, redTank.GunPower, redTank.ShieldLife, redTank.PosX, redTank.PosY);
 }