public bool SetFood(Serpent serpent) { if (!HasNormalCell(serpent)) { return(false); } int x, y; Random r = new Random(); while (true) { x = r.Next(0, RowCount); y = r.Next(0, ColCount); Cell cell = GetCell(x, y); if (cell.IsNormal() && !serpent.InBody(cell)) { break; } } _cellFood = _cells[x][y]; _cellFood.Kind = CellKind.Food; RedrawMapCell(x, y); return(true); }
public Cell AStarMove2Goal(Cell goal) { List <Point> pathGoal = null; List <Point> pathTail = null; pathGoal = GetPath2Goal(goal); if (pathGoal.Count > 0) { Serpent vsp = new Serpent(this); vsp.VirtualMoveByPath(pathGoal); Cell vtail = vsp.GetTail(); pathTail = vsp.GetPath2Goal(vtail); if (pathTail.Count == 0) { return(AStarMove2Tail(goal)); } else { return(Point2MapCell(pathGoal[0])); } } else { return(AStarMove2Tail(goal)); } }
private void SetSerpent() { int cnt = int.Parse(txtSerpentCount.Text); serpent = new Serpent(cnt, map.CellCount, this.pnlGame, map); pnlGame.serpent = serpent; map.DrawSerpentCells(serpent); }
public void DrawSerpentCell(Serpent serpent, int idx) { Cell cell = serpent.GetCell(idx); Rectangle rect = GetCellRect(cell.Row, cell.Col); RelateDirection before = serpent.GetCellRelation(idx, -1); RelateDirection after = serpent.GetCellRelation(idx, 1); cell.Draw(_graphic, rect, CellMargin, idx, before, after); }
public void DrawSerpentCells(Serpent serpent) { for (int i = 0; i < serpent.Body.Count; i++) { Cell cell = serpent.Body[i]; Rectangle rect = GetCellRect(cell.Row, cell.Col); RelateDirection before = serpent.GetCellRelation(i, -1); RelateDirection after = serpent.GetCellRelation(i, 1); cell.Draw(_graphic, rect, CellMargin, i, before, after); } }
public Serpent(Serpent src) { MinCount = src.MinCount; MaxCount = src.MaxCount; MapPtr = src.MapPtr; _rndInt = new Random(DateTime.Now.Millisecond); foreach (Cell cell in src.Body) { this.Body.Add(new Cell(cell)); } }
private bool CreateSerpent() { int maxcount = map.CellCount / 2; if (!CheckInputNumber(txtSerpentCount, "蛇の長さ", 4, maxcount)) { return(false); } int count = int.Parse(txtSerpentCount.Text); serpent = new Serpent(count, maxcount, pnlGame, map); pnlGame.serpent = serpent; map.DrawSerpentCells(serpent); return(true); }
public Cell AStarMove2Tail(Cell goal) { Cell head = GetHead(); // Get the list of movable cells List <Cell> nextCells = GetMovableCells(head.Row, head.Col); if (nextCells.Count == 0) { return(null); } List <Cell> tails = new List <Cell>(); // If moved cell can find path to tail, add to the tail list foreach (Cell cell in nextCells) { Serpent vsp = new Serpent(this); vsp.VirtualMoveCell(cell); Cell tail = vsp.GetTail(); if (vsp.GetPath2Goal(tail).Count > 0) { tails.Add(cell); } } // If not cell can find tail then check the nextcells if (tails.Count == 0) { tails.AddRange(nextCells); } // Get farthest cell to goal int dis0 = GetCellsDistance(tails[0], goal); Cell cellGot = tails[0]; for (int i = 1; i < tails.Count; i++) { int disloop = GetCellsDistance(tails[i], goal); if (disloop > dis0) { dis0 = disloop; cellGot = tails[i]; } } return(cellGot); }
public void DrawSerpentCells2(Serpent serpent) { Graphics g = Graphics.FromImage(_bitmap); for (int i = 0; i < serpent.Body.Count; i++) { Cell cell = serpent.Body[i]; Rectangle rect = GetCellRect(cell.Row, cell.Col); RelateDirection before = serpent.GetCellRelation(i, -1); RelateDirection after = serpent.GetCellRelation(i, 1); cell.Draw(g, rect, CellMargin, i, before, after); } g.Dispose(); _graphic.DrawImage(_bitmap, 0, 0); }
public bool HasNormalCell(Serpent serpent) { int row, col; for (row = 0; row < RowCount; row++) { for (col = 0; col < ColCount; col++) { Cell cell = GetCell(row, col); if (cell.IsNormal() && !serpent.InBody(cell)) { return(true); } } } return(false); }