public bool GenerateRandomBoardWithShips() { var max = Options.OPTIONS["Board size"]; foreach (var ship in Ships) { var success = false; var safety = 0; while (safety < max * 2) { success = GamingBoard.PlaceShip(ship, GetDirection()); safety++; if (success) { break; } } if (success) { continue; } GamingBoard.FillBoard(); return(false); } GamingBoard.RemoveNeighbours(max); return(true); }
public void TestGamingBoard() { Options.SetDefaultOptions(); var gamingBoard = new GamingBoard(); Assert.AreEqual("GamingBoard", gamingBoard.CurrentBoardName()); Assert.AreEqual(BoardSquareState.Water, gamingBoard[0, 0]); gamingBoard[1, 1] = BoardSquareState.Carrier; Assert.AreEqual(BoardSquareState.Carrier, gamingBoard[1, 1]); }
public Player(string name, List <Coordinates> movesDoneList, List <Ship> ships, GamingBoard gamingBoard, TrackingBoard trackingBoard, List <Ship> sunkShips, int hitPoints) { UserName = name; MovesDoneList = movesDoneList; Ships = ships; GamingBoard = gamingBoard; SunkShips = sunkShips; HitPoints = hitPoints; TrackingBoard = trackingBoard; }
public GamingBoard GetDomainGamingBoard() { var gamingBoard = new GamingBoard(Size); foreach (var square in BoardSquares) { gamingBoard[square.X, square.Y] = gamingBoard.BoardSquareStateFromString(square.Value); } return(gamingBoard); }
public Player(string name) { UserName = name; MovesDoneList = new List <Coordinates>(); Ships = new List <Ship>(); InitializeShips(); GamingBoard = new GamingBoard(); TrackingBoard = new TrackingBoard(); SunkShips = new List <Ship>(); HitPoints = Ships.Sum(ship => ship.Health); }
public Computer(string name, List <Coordinates> movesDoneList, List <Ship> ships, GamingBoard gamingBoard, TrackingBoard trackingBoard, List <Ship> sunkShips, int hitPoints, List <Coordinates> allPossibleCoordinates) : base(name, movesDoneList, ships, gamingBoard, trackingBoard, sunkShips, hitPoints) { UserName = name; MovesDoneList = movesDoneList; Ships = ships; GamingBoard = gamingBoard; TrackingBoard = trackingBoard; SunkShips = sunkShips; HitPoints = hitPoints; AllPossibleCoordinates = allPossibleCoordinates; }
} // end GetDomainPlayer public Computer GetDomainComputer(List <Domain.Ships.Ship> ships, GamingBoard gamingBoard, TrackingBoard trackingBoard, List <Domain.Ships.Ship> sunkShips) { var hitPoints = ships.Sum(c => c.Health); var allPossibleCoordinates = new List <Coordinates>(); var allCoordinatesDeserialized = JsonConvert.DeserializeObject <List <int> >(AllCoordinates); var i = 0; while (i < allCoordinatesDeserialized.Count) { allPossibleCoordinates.Add(new Coordinates(allCoordinatesDeserialized[i], Coordinates.IntToYCoordinate(allCoordinatesDeserialized[i + 1]))); i += 2; } return(new Computer(Name, GetMovesDoneList(), ships, gamingBoard, trackingBoard, sunkShips, hitPoints, allPossibleCoordinates)); } // end GetDomainComputer
private static GamingBoard RegenerateOgBoards(Player savePlayer) { var size = savePlayer.GamingBoard.BoardSize; var newGamingBoard = new GamingBoard(size); foreach (var ship in savePlayer.Ships) { foreach (var coordinate in ship.ShipCoordinates) { newGamingBoard[coordinate.GetX(), coordinate.GetY()] = ship.BoardSquareState; } } return(newGamingBoard); }
private void timer1_Tick(object sender, System.EventArgs e) { switch (brushes[ant.Y, ant.X]) { case Color.White: direction = (Direction)Math.Abs(((int)direction + 1) % 4); break; case Color.Red: direction = (Direction)(((int)direction - 1 > -1 ? (int)direction - 1 : 3) % 4); break; case Color.Green: direction = (Direction)Math.Abs(((int)direction + 1) % 4); break; case Color.Blue: direction = (Direction)(((int)direction - 1 > -1 ? (int)direction - 1 : 3) % 4); break; } brushes[ant.Y, ant.X] = (Color)((int)(brushes[ant.Y, ant.X] + 1) % 4); GamingBoard.Refresh(); GamingBoard.Update(); switch (direction) { case Direction.Up: ant.Y--; break; case Direction.Right: ant.X++; break; case Direction.Down: ant.Y++; break; case Direction.Left: ant.X--; break; } }
public string GetBoardsAsString(GamingBoard gamingBoard, TrackingBoard trackingBoard) { var sb = new StringBuilder(); sb.Append(GetLettersForBoard(gamingBoard.BoardSize)); sb.Append("\t"); sb.Append(GetLettersForBoard(trackingBoard.BoardSize) + Environment.NewLine); for (var i = 0; i < gamingBoard.BoardSize; i++) { sb.Append(GetRowSeparator(gamingBoard.BoardSize) + "\t"); sb.Append(GetRowSeparator(trackingBoard.BoardSize) + Environment.NewLine); sb.Append(GetNumbersForBoard(i)); for (var j = 0; j < gamingBoard.BoardSize + 1; j++) { if (j < gamingBoard.BoardSize) { sb.Append("| " + GetBoardSquareStateSymbol(gamingBoard[i, j]) + " "); continue; } if (j == gamingBoard.BoardSize) { sb.Append("|\t"); sb.Append(GetNumbersForBoard(i)); } for (var k = 0; k < trackingBoard.BoardSize; k++) { sb.Append("| " + GetBoardSquareStateSymbol(trackingBoard[i, k]) + " "); } } sb.Append("|" + Environment.NewLine); } sb.Append(GetRowSeparator(gamingBoard.BoardSize) + "\t"); sb.Append(GetRowSeparator(trackingBoard.BoardSize)); return(sb.ToString()); }
public Player GetDomainPlayer(List <Domain.Ships.Ship> ships, GamingBoard gamingBoard, TrackingBoard trackingBoard, List <Domain.Ships.Ship> sunkShips) { return(new Player(Name, GetMovesDoneList(), ships, gamingBoard, trackingBoard, sunkShips, ships.Sum(c => c.Health))); } // end GetDomainPlayer