public BattleshipCompetition(IBattleshipOpponent op1, IBattleshipOpponent op2, Size boardSize, params int[] shipSizes) { if (op1 == null) { throw new ArgumentNullException("op1"); } if (op2 == null) { throw new ArgumentNullException("op2"); } if (boardSize.Width <= 2 || boardSize.Height <= 2) { throw new ArgumentOutOfRangeException("boardSize"); } if (shipSizes == null || shipSizes.Length < 1) { throw new ArgumentNullException("shipSizes"); } if (shipSizes.Where(s => s <= 0).Any()) { throw new ArgumentOutOfRangeException("shipSizes"); } if (shipSizes.Sum() >= (boardSize.Width * boardSize.Height)) { throw new ArgumentOutOfRangeException("shipSizes"); } this.op1 = op1; this.op2 = op2; this.boardSize = boardSize; this.shipSizes = new List<int>(shipSizes); }
/// <summary> /// Initializes a new instance of the System.Drawing.Point class from a System.Drawing.Size. /// </summary> /// <param name="sz"> /// A System.Drawing.Size that specifies the coordinates for the new System.Drawing.Point. /// </param> public Point(Size sz) { this.isEmpty = false; this.x = sz.Width; this.y = sz.Width; }
/// <summary> /// Converts the specified System.Drawing.PointF to a System.Drawing.Point by /// rounding the values of the System.Drawing.PointF to the next higher integer /// values. /// </summary> /// <param name="value"> /// The System.Drawing.PointF to convert. /// </param> /// <returns> /// The System.Drawing.Point this method converts to. /// </returns> //public static Point Ceiling(PointF value) //{ //throw new NotImplementedException(); //} /// <summary> /// Converts the specified System.Drawing.PointF to a System.Drawing.Point object /// by rounding the System.Drawing.Point values to the nearest integer. /// </summary> /// <param name="value"> /// The System.Drawing.PointF to convert. /// </param> /// <returns> /// The System.Drawing.Point this method converts to. /// </returns> //public static Point Round(PointF value) //{ //return new Point((int)value.X, (int)value.Y); //} /// <summary> /// Returns the result of subtracting specified System.Drawing.Size from the /// specified System.Drawing.Point. /// </summary> /// <param name="pt"> /// The System.Drawing.Point to be subtracted from. /// </param> /// <param name="sz"> /// The System.Drawing.Size to subtract from the System.Drawing.Point. /// </param> /// <returns> /// The System.Drawing.Point that is the result of the subtraction operation. /// </returns> public static Point Subtract(Point pt, Size sz) { return new Point(pt.x - sz.Width, pt.y - sz.Height); }
/// <summary> /// Converts the specified System.Drawing.Point structure to a System.Drawing.PointF /// structure. /// </summary> /// <param name="p"> /// The System.Drawing.Point to be converted. /// </param> /// <returns> /// The System.Drawing.PointF that results from the conversion. /// </returns> //public static implicit operator PointF(Point p) //{ //return new PointF(p.x, p.y); //} /// <summary> /// Adds the specified System.Drawing.Size to the specified System.Drawing.Point. /// </summary> /// <param name="pt"> /// The System.Drawing.Point to add. /// </param> /// <param name="sz"> /// The System.Drawing.Size to add /// </param> /// <returns> /// The System.Drawing.Point that is the result of the addition operation. /// </returns> public static Point Add(Point pt, Size sz) { return new Point(pt.x + sz.Width, pt.y + sz.Height); }
public void NewGame(Size size) { this.gameSize = size; }
//initialize things here public void NewGame(Size size) { }
/// <summary> /// Converts the specified System.Drawing.Size to a System.Drawing.SizeF. /// </summary> /// <param name="p"> /// The System.Drawing.Size to convert. /// </param> /// <returns> /// The System.Drawing.SizeF structure to which this operator converts. /// </returns> //public static implicit operator SizeF(Size p) //{ //return new SizeF(p._width, p._height); //} /// <summary> /// Converts the specified System.Drawing.SizeF structure to a System.Drawing.Size /// structure by rounding the values of the System.Drawing.Size structure to /// the next higher integer values. /// </summary> /// <param name="value"> /// The System.Drawing.SizeF structure to convert. /// </param> /// <returns> /// The System.Drawing.Size structure this method converts to. /// </returns> //public static Size Ceiling(SizeF value) //{ //throw new NotImplementedException(); //} /// <summary> /// Converts the specified System.Drawing.SizeF structure to a System.Drawing.Size /// structure by rounding the values of the System.Drawing.SizeF structure to /// the nearest integer values. /// </summary> /// <param name="value"> /// The System.Drawing.SizeF structure to convert. /// </param> /// <returns> /// The System.Drawing.Size structure this method converts to. /// </returns> //public static Size Round(SizeF value) //{ //throw new NotImplementedException(); //} /// <summary> /// Subtracts the width and height of one System.Drawing.Size structure from /// the width and height of another System.Drawing.Size structure. /// </summary> /// <param name="sz1"> /// The System.Drawing.Size structure on the left side of the subtraction operator. /// </param> /// <param name="sz2"> /// The System.Drawing.Size structure on the right side of the subtraction operator. /// </param> /// <returns> /// The System.Drawing.Size that is a result of the subtraction operation. /// </returns> public static Size Subtract(Size sz1, Size sz2) { return new Size(sz1._width - sz2._width, sz1._height - sz2._height); }
/// <summary> /// Adds the width and height of one System.Drawing.Size structure to the width /// and height of another System.Drawing.Size structure. /// </summary> /// <param name="sz1"> /// The first System.Drawing.Size to add. /// </param> /// <param name="sz2"> /// The second System.Drawing.Size to add. /// </param> /// <returns> /// A System.Drawing.Size structure that is the result of the addition operation. /// </returns> public static Size Add(Size sz1, Size sz2) { return new Size(sz1._width + sz2._width, sz1._height + sz2._height); }
public void NewGame(Size size) { width = size.Width; height = size.Height; state = new State[width, height]; left = new int[width, height]; right = new int[width, height]; below = new int[width, height]; above = new int[width, height]; space = new int[width, height]; hits = new int[width, height]; remainingShips = new List<int>(); mustExplore = new List<Point>(); }
public bool Place(Point location, ShipOrientation orientation, Size boardSize) { this.mLocation = location; this.mOrientation = orientation; this.isPlaced = true; if (!IsValid(boardSize)) { mLocation = new Point(-1, -1); isPlaced = false; return false; } return true; }
public bool IsValid(Size boardSize) { if (!this.isPlaced) { return false; } if (this.mLocation.X < 0 || this.mLocation.Y < 0) { return false; } if (this.mOrientation == ShipOrientation.Horizontal) { if (this.mLocation.Y >= boardSize.Height || this.mLocation.X + this.mLength > boardSize.Width) { return false; } } else { if (this.mLocation.X >= boardSize.Width || this.mLocation.Y + this.mLength > boardSize.Height) { return false; } } return true; }