public GridSquare GetOptimumTarget(TrackingGrid grid, GridSquare lastShot) { Console.WriteLine("HunterKiller looking for target"); GridSquare potentialTarget = LookForTarget(grid, lastShot); return(potentialTarget); }
private void TrackingGrid_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { var EntryGuid = TrackingGrid.CurrentRowStringValue(TrackablesCols.Guid); if (!Helpers.ChildFormControl.FormIsOpenByGuid(typeof(ViewTrackingForm), EntryGuid)) { NewTrackingView(EntryGuid); } }
public ViewDeviceForm(ExtendedForm parentForm, MappedObject device, bool startHidden = false) : base(parentForm, device, startHidden) { currentViewDevice = (Device)device; InitializeComponent(); InitDBControls(); controlParser = new DBControlParser(this); controlParser.EnableFieldValidation(); defaultFormTitle = this.Text; liveBox = new LiveBox(this); liveBox.AttachToControl(CurrentUserTextBox, DevicesCols.CurrentUser, LiveBoxSelectAction.UserSelect, DevicesCols.MunisEmpNum); liveBox.AttachToControl(DescriptionTextBox, DevicesCols.Description, LiveBoxSelectAction.SelectValue); munisToolBar = new MunisToolBar(this); munisToolBar.InsertMunisDropDown(ToolStrip1, 6); windowList = new WindowList(this); windowList.InsertWindowList(ToolStrip1); statusSlider = new SliderLabel(); statusSlider.FlashStripOnNewMessage = true; StatusStrip.Items.Add(statusSlider.ToToolStripControl(StatusStrip)); RefreshCombos(); DataGridHistory.DoubleBuffered(true); TrackingGrid.DoubleBuffered(true); SetEditMode(false); LoadCurrentDevice(); WatchdogInstance.Watchdog.StatusChanged += Watchdog_StatusChanged; if (!startHidden) { this.Show(); } else { // Let the base class know that the hidden form is ready. // Since no load event occurs, we need someway to notify // when all the components are instantiated and populated. base.HiddenFormReady(); } }
private void LoadTracking(string deviceGuid) { using (var results = DBFactory.GetDatabase().DataTableFromQueryString(Queries.SelectTrackingByDevGuid(deviceGuid))) { if (results.Rows.Count > 0) { CollectCurrentTracking(results); TrackingGrid.Populate(results, TrackingGridColumns()); TrackingGrid.Columns[TrackablesCols.CheckType].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; TrackingGrid.Columns[TrackablesCols.CheckType].DefaultCellStyle.Font = new Font(TrackingGrid.Font, FontStyle.Bold); DisableSorting(TrackingGrid); } else { TrackingGrid.DataSource = null; } FillTrackingBox(); } }
public GridSquare GetOptimumTarget(TrackingGrid grid, GridSquare lastShotInGame) { Console.WriteLine("PingKiller looking for target"); GridSquare potentialTarget = null; while (true) { if (lastShot == null) { lastShot = new GridSquare { PositionX = 0, PositionY = 0 }; potentialTarget = lastShot; } else { potentialTarget = new GridSquare(); bool evenRow = lastShot.PositionY % 2 == 0; if ((evenRow && lastShot.PositionX < 7) || (!evenRow && lastShot.PositionX < 8)) { potentialTarget.PositionY = lastShot.PositionY; potentialTarget.PositionX = lastShot.PositionX + 2; } else { potentialTarget.PositionY = lastShot.PositionY + 1; if (potentialTarget.PositionY > 9) { potentialTarget.PositionX = -1; } if (potentialTarget.PositionX != -1) { evenRow = !evenRow; // Even rows if (evenRow) { potentialTarget.PositionX = 0; } else { // Odd rows potentialTarget.PositionX = 1; } } } lastShot = potentialTarget; } if (potentialTarget.PositionX != -1) { if (!grid.Squares[potentialTarget.PositionX, potentialTarget.PositionY].HitPeg && !grid.Squares[potentialTarget.PositionX, potentialTarget.PositionY].Marked) { break; } else { lastShot = potentialTarget; } } else { break; } } return(potentialTarget); }
private void TabControl1_MouseDown(object sender, MouseEventArgs e) { TrackingGrid.Refresh(); }
private GridSquare LookForTarget(TrackingGrid grid, GridSquare lastShot) { GridSquare target = new GridSquare(); // Last shot was hit - keep going in same direction if (lastShot != null) { bool changeDirection = false; bool offBoard = false; while (true) { if (startingHunt) { if (!grid.Squares[lastShot.PositionX, lastShot.PositionY - 1].Marked && !grid.Squares[lastShot.PositionX, lastShot.PositionY - 1].HitPeg && lastShot.PositionY > 0) { direction = Direction.South; } else if (!grid.Squares[lastShot.PositionX, lastShot.PositionY + 1].Marked && !grid.Squares[lastShot.PositionX, lastShot.PositionY + 1].HitPeg && lastShot.PositionY < 10) { direction = Direction.North; } else if (!grid.Squares[lastShot.PositionX - 1, lastShot.PositionY].Marked && !grid.Squares[lastShot.PositionX - 1, lastShot.PositionY].HitPeg && lastShot.PositionX > 0) { direction = Direction.West; } else if (!grid.Squares[lastShot.PositionX + 1, lastShot.PositionY].Marked && !grid.Squares[lastShot.PositionX + 1, lastShot.PositionY].HitPeg && lastShot.PositionX < 10) { direction = Direction.East; } } if (lastShot.HitPeg && !startingHunt) { // Hit last shot keep going hitDirection = direction.ToString(); // Force swap if we are at the edge of the board if ((direction == Direction.South && lastShot.PositionY == 0) || (direction == Direction.North && lastShot.PositionY == 9) || (direction == Direction.East && lastShot.PositionX == 9) || (direction == Direction.West && lastShot.PositionX == 0)) { offBoard = true; if (moreDirections) { changeDirection = true; } else { target.PositionX = -1; break; } } else { if (moreDirections) { changeDirection = true; } } } if (!lastShot.HitPeg || changeDirection) { if (moreDirections) { // If we hit something lastTime - switch direction if (hitDirection != null) { // Don't change anymore moreDirections = false; direction = (Direction)Enum.Parse(typeof(Direction), hitDirection); } if (direction == Direction.South) { direction = Direction.North; } else if (direction == Direction.North) { direction = Direction.East; } else if (direction == Direction.East) { direction = Direction.West; } else if (direction == Direction.West) { direction = Direction.East; } } } target = searchGridForTarget(lastShot.HitPeg == true && !offBoard ? lastShot : initialHitLocation); if (!moreDirections) { if (target.PositionX == -1) { // No more targets break; } else { // If we've already fired here - no more targets if (grid.Squares[target.PositionX, target.PositionY].Marked || grid.Squares[target.PositionX, target.PositionY].HitPeg) { target.PositionX = -1; break; } } } if (target.PositionX != -1) { if (!grid.Squares[target.PositionX, target.PositionY].Marked && !grid.Squares[target.PositionX, target.PositionY].HitPeg) { break; } } } startingHunt = false; } return(target); }