public void OnInit(IBattleField battleField) { this.battleField = battleField as BattleField; FB.FFSM.GraphChar_Driver ap = (battleField as BattleField).GetRealChar(idCare); var cc = ap.transform.GetComponent <FB.FFSM.com_FightFSM>(); logicchar = new LogicChar_Driver(battleField, idCare); foreach (var p in cc.defaultParam) { //Debug.LogError("p.name= " + p.name); //Debug.LogError("p.value= " + p.value); logicchar.SetParam(p.name, p.value); } graphchar = new GraphChar_Sender(battleField, idCare); //Charactor 脱离低级趣味 aniplayer = ap.transform.GetComponent <FB.PosePlus.AniPlayer>(); //fps = aniplayer.clips[0].fps; fightFSM = new FFSM.FightFSM(this.graphchar, this.logicchar, cc.stateTable, cc.aiStateTable, cc.stateTree, joy); if (joy is Input_AI) { (joy as Input_AI).Init(battleField, this, AiLevel); } }
public ManagerController(IPlayerRepository playerRepository, ICardRepository cardRepository, IBattleField battleField) { this.playerRepository = playerRepository; this.cardRepository = cardRepository; this.battleField = battleField; }
/// <summary> /// Generating battleships for the game /// </summary> /// <param name="battleField">Battlefield which battleships will be used in the game</param> private void GenerateGameBattleShips(IBattleField battleField) { foreach (var battleShip in battleField.BattleShips) { _gameBattleShips.Add(new GameBattleShip(this, battleShip)); } }
/// <summary> /// Validate battleships to match rules /// </summary> /// <param name="battleField">Battlefield to validate</param> /// <returns>IEnumerable of errors</returns> public IEnumerable <IBattleFieldError> Validate(IBattleField battleField) { var errors = new List <IBattleFieldError>(); var zonePoints = new HashSet <Point>(); var battleShipsPoints = new HashSet <Point>(); foreach (var battleShip in battleField.BattleShips) { var battleShipSetOfPoints = battleShip.CreateBattleshipSetOfPoints(); foreach (var battleShipPoint in battleShipSetOfPoints) { if (battleShipsPoints.Contains(battleShipPoint)) { errors.Add(new BattleFieldError(BattlefieldErrorTypes.BattleShipCrossingOther, battleShipPoint)); } else { if (zonePoints.Contains(battleShipPoint)) { errors.Add(new BattleFieldError(BattlefieldErrorTypes.BattleShipNearOther, battleShipPoint)); } battleShipsPoints.Add(battleShipPoint); } } var zoneAroundBattleShip = battleShip.CreateSetOfPointsAroundBattleShip(); foreach (var zonePoint in zoneAroundBattleShip) { zonePoints.Add(zonePoint); } } return(errors); }
/// <summary> /// This function create list of destroyers with random positions and add them to the battlfield /// </summary> /// <param name="battlefield"></param> /// <returns>New battlefield object with added destroyers and also list of the ships</returns> public static (IBattleField battlefield, List <Battleship> destroyers) CreateAndLoadDestroyersToBattlefield(IBattleField battlefield) { List <Battleship> destroyers = new List <Battleship>(); IBattleField newBattlefield = (IBattleField)battlefield.Clone(); (int x, int y, Direction direction)coordinates; bool isSucceed; for (int i = 1; i <= 2; i++) { Battleship destroyer = new Battleship(4); do { coordinates = RandomInitialCoordinates(); IBattleField battlefieldWihtNewShips; (battlefieldWihtNewShips, isSucceed) = destroyer.TryLoadBattleshipToTheBattlefield(newBattlefield, coordinates.x, coordinates.y, coordinates.direction); if (isSucceed == true) { newBattlefield = battlefieldWihtNewShips; } } while (isSucceed == false); destroyers.Add(destroyer); } return(battlefield : newBattlefield, destroyers : destroyers); }
public Input_AI_Expand(Input_AI input, IBattleField battlefield, CharController_Direct _self, FB.FFSM.AI_StateTable table, AILevel aiLevel) { this.selfCC = _self; this.battlefield = battlefield; this.input = input; this.aiLevel = aiLevel; this.ai_table = table; //ai改变属性 AILevelChange(); vIdlePos = (battlefield as BattleField).GetRealChar(selfCC.idCare).transform.position; enemyCC = battlefield.GetAllCCBySide(1)[0] as CharController_Direct; //enemyCC.SetCCLife(0); stateTable = (battlefield as BattleField).GetRealChar(selfCC.idCare).transform.GetComponent <FB.FFSM.com_FightFSM>().stateTable; Start(); ChangeState(StateMachine.idle); ai_attackstate_map = new Dictionary <int, List <AI_StateItem> >(); for (int i = 0; i <= 3; i++) { ai_attackstate_map[i] = new List <AI_StateItem>();//0 移动系列 } if (ai_table == null || ai_table.allstates == null) { return; } foreach (var a in ai_table.allstates) { ai_attackstate_map[a.attacktype].Add(a); } }
/// <summary> /// Function is checking coordinates correctness na is loading ship to the map. /// </summary> /// <param name="battlefield"></param> /// <param name="intitialXPostion"></param> /// <param name="initialYPosition"></param> /// <param name="directionOfTheShip"></param> /// <returns>Returns new battlefield with added ship and bool information about succeed ot the process</returns> public (IBattleField newBattleField, bool isSucceed) TryLoadBattleshipToTheBattlefield(IBattleField battlefield, int intitialXPostion, int initialYPosition, Direction directionOfTheShip) { bool isNoCollisions = this.TrySetCoordinatesForTheShip(battlefield, intitialXPostion, initialYPosition, directionOfTheShip); IBattleField newBattlefild = isNoCollisions ? this.LoadShipToBattlefield(battlefield) : null; return(newBattlefild, isSucceed : isNoCollisions); }
public void EnterField(IBattleField battleField) { if (battleField.NumberOfFleetSlotsAvailable > this.Size) { battleField.Fleets.Add(this); BattleResults.Messages.Add("The " + this.Name + " fleet has entered the field!"); } }
public ManagerController() { this.cardRepository = new CardRepository(); this.playerRepository = new PlayerRepository(); this.playerFactory = new PlayerFactory(); this.cardFactory = new CardFactory(); this.battleField = new BattleField(); }
public void EnterFieldTest() { IBattleField battleField = BattleFieldFactory.CreateBattleField(BattleFieldType.Small); IFleet myfleet = FleetFactory.CreateFleet(FleetConfigurationType.BalancedShips, BattleStratageyType.WeekShipsFirst); myfleet.EnterField(battleField); Assert.True(battleField.Fleets.Count() > 0); }
public ManagerController() { playerRepository = new PlayerRepository(); cardRepository = new CardRepository(); battleField = new BattleField(); playerFactory = new PlayerFactory(); cardFactory = new CardFactory(); }
public void AdvanceRoundTest() { IBattleField battleField = BattleFieldFactory.CreateBattleField(BattleFieldType.Small); IFleet fleet = FleetFactory.CreateFleet(FleetConfigurationType.BalancedShips, BattleStratageyType.WeekShipsFirst); fleet.EnterField(battleField); battleField.AdvanceRound(fleet); Assert.True(fleet.NumberOfRoundsCompleted == 1); }
/// <summary> /// Validate battleships to match rules /// </summary> /// <param name="battleField">Battlefield to validate</param> /// <returns>IEnumerable of errors</returns> public IEnumerable <IBattleFieldError> Validate(IBattleField battleField) { _resultErrors = new List <IBattleFieldError>(); GetNonValidTypeErrors(battleField.BattleShips); GetNonValidBattleshipsCount(battleField.BattleShips); return(_resultErrors); }
public Battle(IBattleField battleField, IEnumerable<Snake> snakes) : this() { this.battleField = battleField; battleSnakes = snakes.Select(snake => new BattleSnake(snake, new DummyMind())); //set snakes starting coordinates here this.battleField.AddSnakes(battleSnakes.Shuffle()); // battleSnakes.ForEach(snake => snake.Died += this.SnakeDiedHandler()); }
/// <summary> /// The function is checking is no collision on the map with other ship. /// </summary> /// <param name="battlefield"></param> /// <param name="coordinatesForTheShip"></param> /// <returns></returns> private bool IsNoColisionOnTHeMap(IBattleField battlefield, List <Coordinates> coordinatesForTheShip) { foreach (Coordinates coordinates in coordinatesForTheShip) { FieldState fieldState = battlefield.GetArray()[Convert.ToInt32(coordinates.X), Convert.ToInt32(coordinates.Y)].State; if (fieldState != FieldState.Empty) { return(false); } } return(true); }
public LogicChar_Driver(IBattleField battleField, int id) { this.battleField = battleField as BattleField; this.id = id; this.idHold = -1; ap = (battleField as BattleField).GetRealChar(id); mapParam["hp"] = 100; mapParam["hpmax"] = 500; mapParam["mp"] = 5; mapParam["mpmax"] = 500; }
public ManagerController(ICardRepository cardRepository, IPlayerRepository playerRepository, IPlayerFactory createPlayer, ICardFactory createCard, IBattleField battleField) { this.playerFactory = createPlayer; this.cardFactory = createCard; this.cardRepository = cardRepository; this.playerRepository = playerRepository; this.battleField = battleField; }
public RobotPlayer(IBoardDrawer boardDrawer, IBattleField battleField, IShipPlacer shipPlacer) { _battleField = battleField; _shipPlacer = shipPlacer; _boardDrawer = boardDrawer; _exploratoryAttack = new ExploratoryAttack(battleField, shipPlacer); _afterHitAttack = new AfterHitAttack(battleField); _currentAttackMode = AttackMode.Exploratory; }
public ShipPlacer(ShipType[] ships, IBattleField battlefield) { _ships = ships; _battleField = battlefield; _lstSpacePerRow = new List <int>(); _lstSpacePerCol = new List <int>(); for (int i = 0; i < _battleField.Size; i++) { _lstSpacePerRow.Add(_battleField.Size); _lstSpacePerCol.Add(_battleField.Size); } }
public static Battle GetSessionOrNewBattle(Battle battle, object sv) { if (battle == null) { battle = new Battle(); } if (sv != null) { IBattleField myBattleField = (IBattleField)sv; battle.myBattleField = myBattleField; } return(battle); }
/// <summary> /// Validate navy battle game field to match classic rules /// </summary> /// <param name="battleShips"></param> /// <returns></returns> public IBattleFieldValidationResult Validate(IBattleField battleField) { var validationResult = new BattleFieldValidationResult(); validationResult.ErrorList.AddRange(_battleShipsValidator.Validate(battleField)); validationResult.ErrorList.AddRange(_beyondBorderValidator.Validate(battleField)); validationResult.ErrorList.AddRange(_battleShipPositionValidator.Validate(battleField)); if (!validationResult.ErrorList.Any()) { validationResult.IsSuccess = true; } return(validationResult); }
public void StartRoundTest() { IBattleField battleField = BattleFieldFactory.CreateBattleField(BattleFieldType.Small); IFleet fleet1 = FleetFactory.CreateFleet(FleetConfigurationType.BalancedShips, BattleStratageyType.WeekShipsFirst); IFleet fleet2 = FleetFactory.CreateFleet(FleetConfigurationType.BalancedShips, BattleStratageyType.StrongShipsFirst); fleet1.EnterField(battleField); fleet2.EnterField(battleField); foreach (IStarShip ship in fleet2.StarShips) { ship.Health = 0; } bool result = battleField.CheckForVictory(); Assert.True(result); }
/// <summary> /// Validate battleships to match rules /// </summary> /// <param name="battleField">Battlefield to validate</param> /// <returns>IEnumerable of errors</returns> public IEnumerable <IBattleFieldError> Validate(IBattleField battleField) { var resultErrors = new List <IBattleFieldError>(); foreach (var battleShip in battleField.BattleShips) { var endPoint = battleShip.GetEndPoint(); var startPoint = battleShip.StartPoint; if (startPoint.X >= 1 && startPoint.X <= battleField.Width && startPoint.Y >= 1 && startPoint.Y <= battleField.Width) { continue; } resultErrors.Add(new BattleFieldError(BattlefieldErrorTypes.BattleShipOutOfBorder, startPoint)); } return(resultErrors); }
private static IBattleField SetUpBattleField() { IBattleField battleField = BattleFieldFactory.CreateBattleField(BattleFieldType.Large); IFleet fleet1 = FleetFactory.CreateFleet(FleetConfigurationType.SmallShips, BattleStratageyType.WeekShipsFirst); IFleet fleet2 = FleetFactory.CreateFleet(FleetConfigurationType.BalancedShips, BattleStratageyType.StrongShipsFirst); IFleet fleet3 = FleetFactory.CreateFleet(FleetConfigurationType.HeavyShips, BattleStratageyType.NoPriority); IFleet fleet4 = FleetFactory.CreateFleet(FleetConfigurationType.BalancedShips, BattleStratageyType.WeekShipsFirst); IFleet fleet5 = FleetFactory.CreateFleet(FleetConfigurationType.BalancedShips, BattleStratageyType.NoPriority); IFleet fleet6 = FleetFactory.CreateFleet(FleetConfigurationType.BalancedShips, BattleStratageyType.NoPriority); fleet1.EnterField(battleField); fleet2.EnterField(battleField); fleet3.EnterField(battleField); fleet4.EnterField(battleField); fleet5.EnterField(battleField); fleet6.EnterField(battleField); return(battleField); }
/// <summary> /// The function load the battleship to the battlefield /// </summary> /// <param name="battlefield"></param> /// <returns>Returns new battlfield object with new battlship</returns> private IBattleField LoadShipToBattlefield(IBattleField battlefield) { IBattleField newBattleField = (IBattleField)battlefield.Clone(); int xOfTheBattlefield = battlefield.GetArray().GetLength(0) - 1; int yOfTheBattlefield = battlefield.GetArray().GetLength(1) - 1; int?maxXcoordinate = this.CoordinatesOfTheShip.Max(a => a.X); int?maxYcoordinate = this.CoordinatesOfTheShip.Max(a => a.Y); int?minXcoordinate = this.CoordinatesOfTheShip.Min(a => a.X); int?minYcoordinate = this.CoordinatesOfTheShip.Min(a => a.Y); foreach (Coordinates mast in this.CoordinatesOfTheShip) { newBattleField = newBattleField.AddMastOfTheShip(this.id, Convert.ToInt32(mast.X), Convert.ToInt32(mast.Y)); } return(newBattleField); }
public void PostBattleResultsTest() { BattleResults.Messages.Clear(); IBattleField battleField = SetUpBattleField(); battleField.StartBattle(); var br1 = battleField.WorkingFleets.FirstOrDefault().WorkingStarShips.Count(); BattleResults.Messages.Clear(); battleField = SetUpBattleField(); battleField.StartBattle(); var br2 = battleField.WorkingFleets.FirstOrDefault().WorkingStarShips.Count(); BattleResults.Messages.Clear(); battleField = SetUpBattleField(); battleField.StartBattle(); var br3 = battleField.WorkingFleets.FirstOrDefault().WorkingStarShips.Count(); bool allThreeAreDiffrent = br1 != br2 && br2 != br3 && br1 != br3; Assert.True(allThreeAreDiffrent); }
/// <summary> /// This function get coordinates from the user. /// </summary> /// <returns>Two coordinates x and y</returns> public static (int x, int y) GetCoorinatesFromUser(IBattleField battlefield) { Console.Write("x:"); int x; while (Int32.TryParse(Console.ReadLine(), out x) == false || battlefield.GetArray().GetLength(0) <= x || x < 0) { Console.WriteLine("The coordinate is wrong. You should type a number from 0 to 9"); Console.Write("x:"); } Console.Write("y:"); int y; while (Int32.TryParse(Console.ReadLine(), out y) == false || battlefield.GetArray().GetLength(1) <= y || y < 0) { Console.WriteLine("The coordinate is wrong. You should type a number from 0 to 9"); Console.Write("y:"); } return(x : x, y : y); }
public void StartBattleTest() { IBattleField battleField = BattleFieldFactory.CreateBattleField(BattleFieldType.Large); IFleet fleet1 = FleetFactory.CreateFleet(FleetConfigurationType.SmallShips, BattleStratageyType.WeekShipsFirst); IFleet fleet2 = FleetFactory.CreateFleet(FleetConfigurationType.BalancedShips, BattleStratageyType.StrongShipsFirst); IFleet fleet3 = FleetFactory.CreateFleet(FleetConfigurationType.HeavyShips, BattleStratageyType.NoPriority); IFleet fleet4 = FleetFactory.CreateFleet(FleetConfigurationType.BalancedShips, BattleStratageyType.WeekShipsFirst); IFleet fleet5 = FleetFactory.CreateFleet(FleetConfigurationType.BalancedShips, BattleStratageyType.NoPriority); IFleet fleet6 = FleetFactory.CreateFleet(FleetConfigurationType.BalancedShips, BattleStratageyType.NoPriority); fleet1.EnterField(battleField); fleet2.EnterField(battleField); fleet3.EnterField(battleField); fleet4.EnterField(battleField); fleet5.EnterField(battleField); fleet6.EnterField(battleField); battleField.StartBattle(); Assert.True(battleField.Fleets.Where(x => x.WorkingStarShips.Count() > 0).Count() == 1); bool result = battleField.CheckForVictory(); Assert.True(result); }
/// <summary> /// This function create list of battleships with random positions and add them to the battlfields. /// </summary> /// <param name="battlefield"></param> /// <returns>New battlefield object with added destroyers and also list of the ships.</returns> public static (IBattleField battlefield, List <Battleship> ships) CreateAndLoadBattleshipsToBattlefield(IBattleField battlefield) { List <Battleship> battleships = new List <Battleship>(); Battleship battleship = new Battleship(5); (int x, int y, Direction direction)coordinates; IBattleField NewBattleField = (IBattleField)battlefield.Clone(); bool isSucceed; do { coordinates = RandomInitialCoordinates(); IBattleField battlefieldWihtNewShips; (battlefieldWihtNewShips, isSucceed) = battleship.TryLoadBattleshipToTheBattlefield(NewBattleField, coordinates.x, coordinates.y, coordinates.direction); if (isSucceed == true) { NewBattleField = battlefieldWihtNewShips; } } while (isSucceed == false); battleships.Add(battleship); return(battlefield : NewBattleField, ships : battleships); }
public void SetBattleField(int width, int height) { this.battleField = new BattleField(width, height); }
public GraphChar_Sender(IBattleField battleField, int id) { this.battleField = battleField; this.id = id; ap = (battleField as BattleField).GetRealChar(id); }