public Ship(CoordPair loc, int length, bool horizontal) { if (length > 5 || length < 2) { throw new ArgumentException("Invalid Length"); } if (horizontal) { if (length + loc.X - 1 > 9) { throw new ArgumentException("Invalid Coordinates"); } } else { if (length + loc.Y - 1 > 9) { throw new ArgumentException("Invalid Coordinates"); } } Location = loc; Length = length; Horizontal = horizontal; UndamagedTiles = GetOccupiedArea(0); DamagedTiles = new CoordSet(); }
public RectangleF GetBoardArea(int loc1X, int loc1Y, int loc2X, int loc2Y) { CoordPair TL, BR; if (loc1X < loc2X) { if (loc1Y < loc2Y) { TL = new CoordPair(loc1X, loc1Y); BR = new CoordPair(loc2X, loc2Y); } else { TL = new CoordPair(loc1X, loc2Y); BR = new CoordPair(loc2X, loc1Y); } } else { if (loc1Y < loc2Y) { TL = new CoordPair(loc2X, loc1Y); BR = new CoordPair(loc1X, loc2Y); } else { TL = new CoordPair(loc2X, loc2Y); BR = new CoordPair(loc1X, loc1Y); } } float tileWidth = (Width - 11 * LineWidth) / 10; return(new RectangleF(LineWidth + (LineWidth + tileWidth) * TL.X, LineWidth + (LineWidth + tileWidth) * TL.Y, tileWidth + (tileWidth + LineWidth) * (BR.X - TL.X), tileWidth + (tileWidth + LineWidth) * (BR.Y - TL.Y))); }
public TrackerTile this[CoordPair C] { get { return(tiles[C.Y, C.X]); } set { var old = tiles[C.Y, C.X]; tiles[C.Y, C.X] = value; TileChanged?.Invoke(this, new TileChangedEventArgs(C, old)); } }
public PrimaryTile this[CoordPair cp] { get { return(tiles[cp.Y, cp.X]); } set { var old = tiles[cp.Y, cp.X]; tiles[cp.Y, cp.X] = value; TileChanged?.Invoke(this, new TileChangedEventArgs(cp, old)); } }
public bool Hit(CoordPair cp) { if (UndamagedTiles.Remove(cp)) { DamagedTiles.Add(cp); return(true); } return(false); }
public bool TryHit(CoordPair coord) { if (this[coord] == PrimaryTile.Ship) { this[coord] = PrimaryTile.Hit; return(true); } this[coord] = PrimaryTile.Miss; return(false); }
public static bool IsValidCoord(int x, int y, out CoordPair s) { if (IsValidCoord(x, y)) { s = new CoordPair(x, y); return(true); } s = new CoordPair(0, 0); return(false); }
public void PlayerMove(CoordPair cp) { if (AI.TryHit(cp)) { PlayerTracker[cp] = TrackerTile.Hit; } else { PlayerTracker[cp] = TrackerTile.Miss; } }
public static Ship CreateRandom(Random rnd, int length) { bool horizontal = rnd.NextDouble() < 0.5; CoordPair loc; if (horizontal) { loc = new CoordPair(rnd.Next(11 - length), rnd.Next(10)); } else { loc = new CoordPair(rnd.Next(10), rnd.Next(11 - length)); } return(new Ship(loc, length, horizontal)); }
public CoordSet GetOccupiedArea(int range) { CoordSet cs = new CoordSet(); int firstX = Location.X - range; int firstY = Location.Y - range; int lastX = Location.X + range + (Horizontal ? Length - 1 : 0); int lastY = Location.Y + range + (Horizontal ? 0 : Length - 1); for (int x = firstX; x <= lastX; x++) { for (int y = firstY; y <= lastY; y++) { if (CoordPair.IsValidCoord(x, y)) { cs.Add(new CoordPair(x, y)); } } } return(cs); }
public TileChangedEventArgs(CoordPair loc, TrackerTile oldTile) { Location = loc; OldTile = oldTile; }
public TileChangedEventArgs(CoordPair loc, PrimaryTile oldTile) { Location = loc; OldTile = oldTile; }
public RectangleF GetBoardArea(CoordPair loc1, CoordPair loc2) { return(GetBoardArea(loc1.X, loc1.Y, loc2.X, loc2.Y)); }
public RectangleF GetTileArea(CoordPair cp) { return(GetTileArea(cp.X, cp.Y)); }
public void GetPossibleShipLocs(CoordPair cp) { }