public List <Vector2> CheckSelectionArea(Vector2 min, Vector2 max) { //Can be cashed List <Vector2> units = new List <Vector2>(); List <GridLoc> selectedBlocks = new List <GridLoc>(); //- for (int w = 0; w < gridArray.GetLength(0); w++) { for (int h = 0; h < gridArray.GetLength(1); h++) { Vector2 unitPos = GetCellCoorToWorld(w, h); unitPos.x -= 0.5f; unitPos.y -= 0.5f; if (unitPos.x > min.x && unitPos.x < max.x && unitPos.y > min.y && unitPos.y < max.y) { var block = new GridLoc(w, h); units.Add(unitPos); selectedBlocks.Add(block); } } } //foreach(var block in selectedBlocks) //{ // Debug.Log(block.x + " " + block.y); //} return(units); }
internal override bool handleOther(Direction d, GridLoc orGLoc, GridLoc currentIndex) { if (d == Direction.Right) { int c = viewpager.getCount(); if (viewpager.currentIndex >= c - 1) { base.handleOther(d, orGLoc, currentIndex); return(false); } else { base.handleOther(d, orGLoc, currentIndex); return(true); } } else if (d == Direction.Left) { if (viewpager.currentIndex <= 0) { base.handleOther(d, orGLoc, currentIndex); return(false); } else { base.handleOther(d, orGLoc, currentIndex); return(true); } } else { base.handleOther(d, orGLoc, currentIndex); return(true); } }
protected void AutoRefreshTimer_Tick(object sender, EventArgs e) { GridExp.DataBind(); GridLoc.DataBind(); if (IsPostBack) { checkExp(); checkLoc(); } QueueView(); }
private bool CheckSnakeCrash(GridLoc pos, List <GridLoc> snake) { foreach (var snakePos in snake) { if (pos.row == snakePos.row && pos.col == snakePos.col) { return(true); } } return(false); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } // TODO: Add your update logic here var kstate = Keyboard.GetState(); switch (state) { case GameStates.StartScreen: if (kstate.IsKeyDown(Keys.Space)) { state = GameStates.Play; } break; case GameStates.Play: CheckDirKeys(kstate); if (gameTime.TotalGameTime > moveTimer) { var new1 = new GridLoc(p1Snake[p1Snake.Count - 1], p1Dir); var new2 = new GridLoc(p2Snake[p2Snake.Count - 1], p2Dir); p1Crashed = CheckCrash(new1); p2Crashed = CheckCrash(new2); if (p1Crashed || p2Crashed) { state = GameStates.EndScreen; } else { p1Snake.Add(new1); p2Snake.Add(new2); moveTimer = gameTime.TotalGameTime + moveDelay; } } break; case GameStates.EndScreen: if (kstate.IsKeyDown(Keys.Y)) { InitializePlayers(); state = GameStates.StartScreen; } else if (kstate.IsKeyDown(Keys.N)) { Exit(); } break; } base.Update(gameTime); }
public int NearestWireIntersectDist() { var minDist = int.MaxValue; var count = 0; var curr = new GridLoc(); foreach (var move in Moves(_wire2)) { for (int i = 0; i < move.Distance; i++) { curr = curr.Move(move.Direction); count++; if (_grid1.ContainsKey(curr)) { var dist = _grid1[curr] + count; minDist = Math.Min(minDist, dist); } } } return(minDist); }
public int NearestManhattanIntersectDist() { // Manhattan distance is simply the sume of differences between points for their // x and y coordinates. var minDist = int.MaxValue; var curr = new GridLoc(); foreach (var move in Moves(_wire2)) { for (int i = 0; i < move.Distance; i++) { curr = curr.Move(move.Direction); if (_grid1.ContainsKey(curr)) { var dist = Math.Abs(curr.X) + Math.Abs(curr.Y); minDist = Math.Min(minDist, dist); } } } return(minDist); }
public GridLoc(GridLoc oldPos, Dir d) { row = oldPos.row; col = oldPos.col; switch (d) { case Dir.Up: row--; break; case Dir.Down: row++; break; case Dir.Left: col--; break; case Dir.Right: col++; break; } }
protected void CheckLocApp_Click(object sender, EventArgs e) { if (IsPostBack) { var strSql = new StringBuilder(string.Empty); var con = new SqlConnection(strConnection); var conQueue = new SqlConnection(strConnection); var cmd = new SqlCommand(); var ChecklocApp = (Button)sender; var grdRow1 = (GridViewRow)ChecklocApp.NamingContainer; var lblID = (Label)grdRow1.FindControl("LabelID"); var cusTime = DateTime.Now; var named = User.Identity.Name; try { ApproveSecurity(con, conQueue, cmd, lblID, cusTime, named); } catch (SqlException ex) { var errorMsg = "Error in Updation"; errorMsg += ex.Message; throw new Exception(errorMsg); } finally { con.Close(); conQueue.Close(); GridLoc.DataBind(); } } }
private IDictionary <GridLoc, int> BuildGrid(string steps) { var curr = new GridLoc(); var result = new Dictionary <GridLoc, int>(); int moves = 0; result.Add(curr, moves++); foreach (var move in Moves(steps)) { for (int i = 0; i < move.Distance; i++) { curr = curr.Move(move.Direction); if (!result.ContainsKey(curr)) { result.Add(curr, moves++); } else { moves++; } } } return(result); }
private void RadioCheck(object sender) { var strSql = new StringBuilder(string.Empty); var con = new SqlConnection(strConnection); var conQueue = new SqlConnection(strConnection); var cmd = new SqlCommand(); //CheckBox CheckNo = (CheckBox)sender; var rdbl = (RadioButtonList)sender; var grdRow = (GridViewRow)rdbl.NamingContainer; //CheckBox chkNo = (CheckBox)grdRow.FindControl("CheckNo"); var chkRl = (RadioButtonList)grdRow.FindControl("RadioButtonList1"); var lblID = (Label)grdRow.FindControl("LabelID"); var cusTime = DateTime.Now; var named = User.Identity.Name; if (chkRl.SelectedValue == "False") { try { const string strQueueUpdate = "Update NewQueue set Status = @Status, StatusTime = @StatusTime WHERE QueueID = @QueueID"; cmd.CommandType = CommandType.Text; cmd.CommandText = strQueueUpdate; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Status", "SECTNA"); cmd.Parameters.AddWithValue("@StatusTime", cusTime); cmd.Parameters.AddWithValue("@QueueID", lblID.Text); cmd.Connection = conQueue; conQueue.Open(); cmd.ExecuteNonQuery(); } catch (SqlException ex) { var errorMsg = "Error in Updation"; errorMsg += ex.Message; throw new Exception(errorMsg); } finally { con.Close(); conQueue.Close(); GridLoc.DataBind(); GridExp.DataBind(); } } else if (chkRl.SelectedValue == "True") { try { const string strQueueUpdate = "Update NewQueue set Status = @Status WHERE QueueID = @QueueID"; cmd.CommandType = CommandType.Text; cmd.CommandText = strQueueUpdate; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@Status", "SECTA"); cmd.Parameters.AddWithValue("@QueueID", lblID.Text); cmd.Connection = conQueue; conQueue.Open(); cmd.ExecuteNonQuery(); } catch (SqlException ex) { var errorMsg = "Error in Updation"; errorMsg += ex.Message; throw new Exception(errorMsg); } finally { con.Close(); conQueue.Close(); //GridLoc.DataBind(); //GridExp.DataBind(); } } }
private bool CheckCrash(GridLoc pos) { return(CheckBorderCrash(pos) || CheckSnakeCrash(pos, p1Snake) || CheckSnakeCrash(pos, p2Snake)); }
private bool CheckBorderCrash(GridLoc pos) { return(pos.row < 0 || pos.row >= gridHeight || pos.col < 0 || pos.col >= gridWidth); }