public void shoot(BattleShip.AccountManagement.UserAccount user, BattleShip.GameWindow.GamePanel.Field field) { UserSession session = userPlacements[user]; Ship ship = session.shoot(field); if (ship != null) { foreach (IGameCallback c in subscribers.Values) { c.eventHit(user, field, ship); } } else { foreach (IGameCallback c in subscribers.Values) { c.eventMiss(user, field); } } if (strategy.isFinished()) { UserAccount winner = strategy.getWinner(); foreach (IGameCallback c in subscribers.Values) { c.endGame(winner, ""); } } else { subscribers[strategy.getNextPlayer()].eventTurn(); } }
/// <summary> /// Create the buttons at their starting locations, and set their properties. /// </summary> private void InitShips() { BattleShips[0] = new BattleShip(1, 3, new Point(30, 50), Color.LightGreen, new Bitmap(Properties.Resources.Ship3x1)); BattleShips[1] = new BattleShip(1, 4, new Point(90, 50), Color.DarkOliveGreen, new Bitmap(Properties.Resources.Ship4x1V1)); BattleShips[2] = new BattleShip(1, 4, new Point(150, 50), Color.Chartreuse, new Bitmap(Properties.Resources.Ship4x1V2)); BattleShips[3] = new BattleShip(1, 5, new Point(30, 200), Color.SpringGreen, new Bitmap(Properties.Resources.Ship5x1)); BattleShips[4] = new BattleShip(2, 5, new Point(90, 200), Color.Goldenrod, new Bitmap(Properties.Resources.Ship5x2)); BattleShips[5] = new BattleShip(6, 1, new Point(30, 380), Color.Chocolate, new Bitmap(Properties.Resources.Ship6x1)); // Add mouse functionality to each button. foreach (var ship in BattleShips) { ship.MouseUp += b_MouseUp; } if (!_show) { return; } foreach (var ship in BattleShips) { ShipWarsForm.Collection.Add(ship); } ShipWarsForm.Collection.Add(randomFleet); }
// Update is called once per frame void Update() { if (goal == null) { goal = FindObjectOfType <Port>(); } shipsSavedDisplay.text = " " + ships; if (playerObject == null) { playerObject = FindObjectOfType <MineSweeper>(); } if (playerObject != null) { mineSweeperHPLabel.text = playerObject.hitPoints.ToString(); } if (objectiveObject == null) { objectiveObject = FindObjectOfType <BattleShip>(); } if (objectiveObject != null) { battleShipHPLabel.text = objectiveObject.hitPoints.ToString(); } }
public bool FillPlayerBattleShip(int longitude, int latitude) { if (longitude != 6) { if (ShipsPlaced > 0) { BattleShip battleship = new BattleShip(longitude, latitude); foreach (var myPlayerShip in PlayerShipsList) { foreach (var x in battleship.Longitude) { if (myPlayerShip.Longitude.Contains(x) && myPlayerShip.Latitude.Contains(latitude)) { return(false); } } } ShipsPlaced--; PlayerShipsList.Add(battleship); return(true); } else { return(false); } } return(false); }
/// <summary> /// Метод возвращает корабль в зависимости от перданного типа корaбля /// </summary> /// <param name="shipType"></param> /// <returns>Корабль полученый из строки</returns> private ShipBase CreateShipFromString(string shipType) { ShipBase shipBase = null; switch (shipType) { case "b": shipBase = new BattleShip(); // линкор break; case "c": shipBase = new Carrier(); // эсминец break; case "cr": shipBase = new Cruiser(); // крейсер break; case "s": shipBase = new Submarine(); // подлодка break; default: throw new Exception("Нет так кого корабля!"); } return(shipBase); }
public void Open(BattleShip playerChar, BattleShip enemyChar) { Window.SetActive(true); PlayerBlock.SetCharacter(playerChar); PlayerBlock.ToggleTargets(false); EnemyBlock.SetCharacter(enemyChar); PlayerChar = playerChar; AttackingChar = PlayerChar; AttackingCharBlock = PlayerBlock; EnemyChar = enemyChar; DefendingChar = EnemyChar; DefendingCharBlock = EnemyBlock; PlayerBlock.ToggleAttackIcons(isPlayerTurn); PlayerBlock.ToggleDefenseIcons(!isPlayerTurn); EnemyBlock.ToggleAttackIcons(!isPlayerTurn); EnemyBlock.ToggleDefenseIcons(isPlayerTurn); PlayerBlock.OnMovementFinished += BattleBlock_OnMovementFinished; EnemyBlock.OnMovementFinished += BattleBlock_OnMovementFinished; EnemyDefend(); }
public void CreatesShipsTest() { var moqGame = new Player("User"); Player player = new Player("User"); player.IsWinner = false; player.Name = "User"; player.Ships = new List <Ship>(); dynamic BattleShip = new BattleShip(); BattleShip.Name = "BattleShip"; BattleShip.Length = 5; BattleShip.ShipType = ShipType.BattleShip; BattleShip.Hits = 0; BattleShip.IsSunk = false; dynamic Destroyer = new Destroyer(); Destroyer.Name = "Destroyer"; Destroyer.Length = 4; Destroyer.ShipType = ShipType.Destroyer; Destroyer.Hits = 0; Destroyer.IsSunk = false; player.Ships.Add(BattleShip); player.Ships.Add(Destroyer); player.Ships.Add(Destroyer); Assert.AreEqual(moqGame, player); }
public void Should_Create_BattleShip() { var sut = new BattleShip(); sut.Size.Should().Be(ShipSize.BattleShip); sut.ShipId.Should().NotBeEmpty(); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(string Player1Name, string Player2Name, int x, int y, int TouchingRule) { BattleShip = new BattleShip(x, y, Player1Name, Player2Name); InsertBoat(ECellState.Carrier, 1); InsertBoat(ECellState.Battleship, 1); InsertBoat(ECellState.Submarine, 1); InsertBoat(ECellState.Cruiser, 1); InsertBoat(ECellState.Patrol, 1); BattleShip.TouchingRule = ETouchingRule.CanTouch; Domain.GameState gameState = new Domain.GameState() { DT = DateTime.Now, Json = BattleShip.GetSerializedGameState(), Game = new Game() { CreationDT = DateTime.Now, PlayerA = BattleShip.Player1Name, PlayerB = BattleShip.Player2Name } } ; // createInitialGamestate _context.GameStates.Add(gameState); await _context.SaveChangesAsync(); /*_context.Games.Add(Game); * await _context.SaveChangesAsync();*/ return(RedirectToPage("../Setup/Index")); //return Page(); }
// Start is called before the first frame update void Start() { playerObject = FindObjectOfType <MineSweeper>(); objectiveObject = FindObjectOfType <BattleShip>(); Port.PlayerSavedAShipEvent += OnPlayerSavesShip; }
public void Should_Return_Sink_Result_When_A_Ship_Is_Sunk() { var expectedGame = GivenGame(); var expectedShip = new BattleShip { Hits = 4 }; expectedGame.Player.GameBoard.Ships = new List <IShip> { expectedShip }; expectedGame.Player.GameBoard.Grids = new List <IGrid> { new Grid(1, 1) { GridType = GridType.Battleship, ShipId = expectedShip.ShipId } }; _sut = expectedGame.Player; var actualResult = _sut.FireShot(new Coordinate(1, 1)); actualResult.Should().BeOfType <ShotResult>().Which.Should().Be(ShotResult.Sink); }
public void SetCharacter(BattleShip character) { Character = character; CharLabel.text = character.ShipData.Name; CharImage.sprite = character.ShipData.Sprite; /*if (Character.Alignment == "player") { * foreach (var target in Targets) { * target.gameObject.SetActive (false); * } * }*/ HPbar.maxValue = Character.MaxHP; UpdateInfo(); for (int i = 0; i < character.AttacksCount; i++) { AttackIcons [i].gameObject.SetActive(true); } for (int i = 0; i < character.BlocksCount; i++) { DefenseIcons [i].gameObject.SetActive(true); } character.OnDamageTaken += Character_OnDamageTaken; }
private void button3_Click(object sender, EventArgs e) { this.Hide(); BattleShip game = new BattleShip(); game.ShowDialog(); }
public void ShipInfo() { BattleShip battleShip = new BattleShip(spil.Type.Patrolboat, 3); PrivateObject privateObject = new PrivateObject(battleShip); Assert.AreEqual <int?>(3, privateObject.GetFieldOrProperty("length") as int?); }
//END OF BATTLESHIP() FUNCTION static void PlaceShipsLoop(BattleShip game, bool player1Turn) { ICollection <Ship> pShips = player1Turn ? game.Player1Ships : game.Player2Ships; ICollection <ECellState> gShips = player1Turn ? game.Ships1 : game.Ships2; ECellState[,] board = player1Turn ? game._board2 : game._board1; while (pShips.Count < game.ShipCountPerPlayer) { if (!game.NextMoveByPlayer2 && game.Player2Name == "AI") { PlaceShipsAI(game, gShips, board); } else { Console.Clear(); BattleShipConsoleUi.DrawBoard(game.GetBoards(), game.NextMoveByPlayer2, game.Player1Name, game.Player2Name); Console.WriteLine("Place boat, enter start and end square i.e a1-a5 to place boat with length 5"); Console.WriteLine(); Console.WriteLine( $"Now placing {gShips.ToArray()[0]}, it requires {(int) gShips.ToArray()[0]} Cells"); PlaceShips(game, gShips, board, Console.ReadLine() ?? "", true); pShips = player1Turn ? game.Player1Ships : game.Player2Ships; gShips = player1Turn ? game.Ships1 : game.Ships2; board = player1Turn ? game._board2 : game._board1; } } //Thread.Sleep(800); }
public ShipDesignerMap(GameDataManager dataManager) { DataManager = dataManager; Modules = new ModuleData[dataManager.Modules.Count]; dataManager.Modules.Values.CopyTo(Modules, 0); Ship = new BattleShip(); }
public void AttackTarget(BattleShip target, BodyPart bodyPart) { target.TakeDamage(Attack, bodyPart); if (OnAttackedTarget != null) { OnAttackedTarget(this); } }
public void ValidateDrawDirectionShape(BattleShip.Direction shipDirection, bool[,] expectedShape) { RandomMock _random = new RandomMock((int)shipDirection); BattleShip _battleShip = new BattleShip(_random); Assert.Equal(_battleShip.GetShape(), expectedShape); }
void BattleShip_OnDamageTaken(BattleShip sender, BodyPart bodyPart, bool block, int amount) { // ShowFlyingText ("-" + amount + " HP", Color.red); if (sender.HP <= 0) { Destroy(gameObject); } }
public async Task <bool> AddShipHorizontally(ShipAddRequest request, Board board) { int.TryParse(request.VerticalStartingPoint, out int verticalPos); int.TryParse(request.HorizontalStartingPoint, out int horizontalPos); int.TryParse(request.Length, out int Length); var serializeRequest = JsonConvert.SerializeObject(request); logger.LogInformation($"Starting horizontal addition for Ship:{serializeRequest}"); //bool result = false; var boardGrid = board.BoardGrid; //check if addition possible if (await IsShipPlacementHorizontallyPossible(request, boardGrid.Grid)) { logger.LogInformation("Initiating Addition for Ship: " + serializeRequest); //Initialize the BattleShip var ship = new BattleShip { LengthOfShip = Length, Orientation = Orientation.Horizontal }; var cells = new List <Cell>(); //get the all the cells for the ship starting from head to end. for (int i = 0; i < Length; i++) { //1. Mark the grid cells occupied. boardGrid.Grid[verticalPos][horizontalPos].OccupiedStatus = OccupiedStatus.Occupied; //2. Add cells to Cell list for the ship. cells.Add(new Cell { HIndex = horizontalPos, VIndex = verticalPos, OccupiedStatus = OccupiedStatus.Occupied }); //change the horizontal index horizontalPos++; } //Assign the list to ship.ShipPosition = cells; battleshipBoardGame.Ships.Add(ship); //Add Successful. logger.LogInformation($"Ship : {serializeRequest} was added successfully!"); return(true); } logger.LogInformation($"Ship : {serializeRequest} was not added!"); return(false); }
void closee(int x) { if (x == 1) { this.Hide(); BattleShip ss = new BattleShip(); ss.ShowDialog(); } }
public void TestConstructor_Success() { // Act var battleShip = new BattleShip(new Coordinate(4, 5), new Coordinate(4, 7)); // Assert Assert.AreEqual(new Coordinate(4, 5), battleShip.Head); Assert.AreEqual(new Coordinate(4, 7), battleShip.Tail); }
// Use this for initialization void Start() { battleShipOBJ = GameObject.FindGameObjectsWithTag("Battle Ship"); for (int i = 0; i < battleShipOBJ.Length; i++) { BS = battleShipOBJ[i].GetComponent <BattleShip>(); } }
public void AddBattleShip_Single_Ship(int playerId) { // Arrange var battleShip = BattleShip.CreateBattleship(playerId, 1, 1, 5, true); // Act & Assert var board = Board.CreateBoard(playerId); board.AddBattleShip(battleShip); }
void Character_OnDamageTaken(BattleShip sender, BodyPart bodyPart, bool block, int amount) { string messageString = ""; if (block) { messageString = "Block! "; } ShowFlyingText(messageString + "-" + amount, Targets [(int)bodyPart].transform.position, Color.red); }
public void IsPlacingBattleShipWorksWitHorizontallyInCorrectParams() { string correctparam = "C7"; bool incorrectIsVertical = false; BattleShip battleShip = new BattleShip(); string thisShouleBeTrue = battleShip.SetBattleShipLocation(correctparam, incorrectIsVertical); string failString = "The head location C7 can't horizontally locate the battleship. Please choose other head location or direction."; Assert.AreEqual(thisShouleBeTrue, failString); }
public void IsPlacingBattleShipWorksWitVerticallyCorrectParams() { string correctparam = "A1"; bool correctIsVertical = false; BattleShip battleShip = new BattleShip(); string thisShouleBeTrue = battleShip.SetBattleShipLocation(correctparam, correctIsVertical); string successString = "Your battleship is successfully located"; Assert.AreEqual(thisShouleBeTrue, successString); }
private void PlaceShipOnGrid(List <List <BattleshipGridCell> > grid, BattleShip ship, GridCoordinate firstCell) { for (int i = 0; i < ship.Length; ++i) { var nextLine = ship.IsVertical ? firstCell.Line + i : firstCell.Line; var nextColumn = ship.IsVertical ? firstCell.Column : firstCell.Column + i; grid[nextLine][nextColumn] = BattleshipGridCell.Ship; } }
public ShipSaveData(BattleShip ship) { Modules = new List <ModuleSaveData>(); foreach (BattleModule module in ship.Modules) { Modules.Add(new ModuleSaveData(module)); } Position = ship.Position; Velocity = ship.Velocity; }
public void TestHit_NotSink() { // Arrange var battleShip = new BattleShip(new Coordinate(4, 5), new Coordinate(4, 6)); // Act battleShip.Hit(); // Assert Assert.IsFalse(battleShip.IsSink()); }
public void Should_Sink() { var sut = new BattleShip { Hits = ShipSize.BattleShip }; var actualResult = sut.IsSunk(); actualResult.Should().BeTrue(); }
public void BuildShips() { foreach (var shipsize in ShipSizesXy) { Point location = GetNextLocation(shipsize); var newBattleShip = new BattleShip { SizeXy = shipsize, Xy1 = new Point() { X = location.X,Y = location.Y}, Xy2 = new Point() { X = location.X + shipsize.X,Y=location.Y + shipsize.Y} }; Ships.Add(newBattleShip); } }
void Start() { Debug.Log ("start in ebm"); hit_Counter = 0; ship_Size = 4; bs = new BattleShip (); bs.Init_Ship (ship_Size); place_Battleship (); Debug.Log ("done start in ebm"); }
public void shoot(BattleShip.AccountManagement.UserAccount user, BattleShip.GameWindow.GamePanel.Field field) { }
public void eventHit(BattleShip.AccountManagement.UserAccount user, BattleShip.GameWindow.GamePanel.Field field, BattleShip.GameWindow.GamePanel.Ship ship) { gameWindow.setFieldStatus(user, field, FieldStatus.HIT, ship); }
public void Fire(int x, int y, BattleShip.Core.Utils.Common.Direction direction, Rectangle rectPlayField) { m_SoundGun.Play(); bActive = true; bVisible = true; asSprite.X = x; asSprite.Y = y; m_CurrDirection = direction; this.rectPlayField = rectPlayField; }
void Start() { hit_Counter = 0; bs = new BattleShip(); ship_Size = 4; bs.Init_Ship(ship_Size); first_Completion = false; Debug.Log("done start in pbm"); }
public static void EditMap(int x, int y, int iData, BattleShip.Core.Utils.Common.MapLayer layer) { switch (layer) { case BattleShip.Core.Utils.Common.MapLayer.Base: if (iData == 2) iData = 108; m_iMap[y, x] = iData; break; case BattleShip.Core.Utils.Common.MapLayer.Trans: m_iMapTrans[y, x] = iData; break; case BattleShip.Core.Utils.Common.MapLayer.Object: m_iMapObj[y, x] = iData; break; default: break; } }
public static int GetMap(int x, int y, BattleShip.Core.Utils.Common.MapLayer layer) { if (x >= 0 && x < m_iMapWidth && y >= 0 && y < m_iMapHeight) { switch (layer) { case BattleShip.Core.Utils.Common.MapLayer.Base: return m_iMap[y, x]; case BattleShip.Core.Utils.Common.MapLayer.Trans: return m_iMapTrans[y, x]; case BattleShip.Core.Utils.Common.MapLayer.Object: return m_iMapObj[y, x]; default: return -1; } } else return -1; }
public int GetPrevTile(BattleShip.Core.Utils.Common.MapLayer layer) { switch (layer) { case BattleShip.Core.Utils.Common.MapLayer.Base: m_iTileBaseCurrIndex--; if (m_iTileBaseCurrIndex < m_iTileBaseStart) { m_iTileBaseCurrIndex = m_iTileBaseEnd; } return m_iTileBaseCurrIndex; case BattleShip.Core.Utils.Common.MapLayer.Trans: m_iTileTransCurrIndex--; if (m_iTileTransCurrIndex < m_iTileTransStart) { m_iTileTransCurrIndex = m_iTileTransEnd; } return m_iTileTransCurrIndex; case BattleShip.Core.Utils.Common.MapLayer.Object: m_iTileObjCurrIndex--; if (m_iTileObjCurrIndex < m_iTileObjStart) { m_iTileObjCurrIndex = m_iTileObjEnd; } return m_iTileObjCurrIndex; default: return -1; } }
void Start() { hit_Counter = 0; first_Completion = false; curr_ship_indx = 0; allPlayerShips = new BattleShip[SgameInfo.max_number_of_ships]; for (int i = 0; i < SgameInfo.max_number_of_ships; i++) { allPlayerShips[i] = new BattleShip(); allPlayerShips[i].Init_Ship(SgameInfo.max_Ship_Size-i); } Debug.Log("done start in pbm"); }
private void place_Battleship(BattleShip btshp,int ship_Size) { Vector2 vc; int random_x_value=0; int random_y_value=0; //int last_placed_x = 0; //int last_placed_y = 0; int initial_y = 0; int initial_x = 0; int i=0; int temp_calc; //placing first loc of AI ship random_y_value = Random.Range (0, 10); random_x_value = Random.Range (0, 10); vc = new Vector2 (random_x_value, random_y_value); if (btshp.Set_Loc(vc)) { //location ok - increase counter initial_y = random_y_value; initial_x = random_x_value; //last_placed_y = initial_y; // last_placed_x = random_x_value; // Debug.Log("Placed AI ship at X" + vc.x + " Y" + vc.y); i++; } //Debug.Log ("continuing creation of AI's ship"); //placing ship with 4 squars while (i<ship_Size) { // generating location for ship // if condition occurs, then Y axis is contant and X values will be randomly generated. if (initial_y>initial_x) { temp_calc = initial_x - (ship_Size - (ship_Size - i)); do { random_x_value = Random.Range (temp_calc, ((initial_x+(ship_Size-1))-(i-1))); } while ((random_x_value>=10)||(random_x_value<0)); vc = new Vector2 (random_x_value, initial_y); if (btshp.Set_Loc(vc)) { //location ok - increase counter //last_placed_x = random_x_value; // Debug.Log("Placed AI ship at X" + vc.x + " Y" + vc.y); i++; } } //X axis is contant and Y values will be randomly generated. else { temp_calc = initial_y - (ship_Size - (ship_Size - i)); do { random_y_value = Random.Range (temp_calc, ((initial_y+(ship_Size-1))-(i-1))); } while ((random_y_value>=10)||(random_y_value<0)); vc = new Vector2 (initial_x, random_y_value); if (btshp.Set_Loc(vc)) { //location ok - increase counter //last_placed_y = random_y_value; // Debug.Log("Placed AI ship at X" + vc.x + " Y" + vc.y); i++; } } } }
public void eventMiss(BattleShip.AccountManagement.UserAccount user, BattleShip.GameWindow.GamePanel.Field field) { gameWindow.setFieldStatus(user, field, FieldStatus.MISS, null); }
void Start() { //Debug.Log ("start in ebm"); hit_Counter = 0; allAIships = new BattleShip[SgameInfo.max_number_of_ships]; for (int i = 0; i < SgameInfo.max_number_of_ships; i++) { allAIships[i] = new BattleShip(); allAIships[i].Init_Ship(SgameInfo.max_Ship_Size - i); place_Battleship(allAIships[i], SgameInfo.max_Ship_Size - i); //Debug.Log("ship sized created " + (SgameInfo.max_Ship_Size - i)); } Debug.Log("done start in EnemyBoardManager"); }
public void updateField(UserAccount user, BattleShip.GameWindow.GamePanel.Field field, BattleShip.GameWindow.GamePanel.FieldStatus fieldStatus) { Console.WriteLine("Playfield of User:"******" at Field " + field.xCoordinate + "/" + field.yCoordinate + " was "+ fieldStatus); }