private Color h_GetCellColor(CCell pCell) { Color backColor = Color.Goldenrod; if (pCell.IsExit) { backColor = Color.Goldenrod; } else { switch (pCell.CellType) { case ECellType.Wall: backColor = Color.Gray; break; case ECellType.Empty: backColor = Color.WhiteSmoke; break; case ECellType.Box: backColor = Color.Green; break; case ECellType.Worker: backColor = Color.DarkRed; break; } } return(backColor); }
private CCell h_FindNextCell(CCell pCell, EDirection enDirection) { int iDeltaX = 0; int iDeltaY = 0; switch (enDirection) { case EDirection.Left: iDeltaX = -1; break; case EDirection.Right: iDeltaX = +1; break; case EDirection.Up: iDeltaY = -1; break; case EDirection.Down: iDeltaY = +1; break; } return (Field.FirstOrDefault(p => p.X == pCell.X + iDeltaX && p.Y == pCell.Y + iDeltaY )); }
public bool Move(EDirection enDirection) { CCell pWorkerCell = Field.FirstOrDefault( p => p.CellType == ECellType.Worker); CCell pCellOnMyWay = h_FindNextCell(pWorkerCell, enDirection); if (pCellOnMyWay == null) { return(false); } switch (pCellOnMyWay.CellType) { case ECellType.Wall: return(false); case ECellType.Empty: break; case ECellType.Box: CCell pCellOnMyWay2 = h_FindNextCell(pCellOnMyWay, enDirection); if (pCellOnMyWay2 == null) { return(false); } if (pCellOnMyWay2.CellType == ECellType.Wall) { return(false); } if (pCellOnMyWay2.CellType == ECellType.Box) { return(false); } pCellOnMyWay2.CellType = ECellType.Box; pCellOnMyWay.CellType = ECellType.Empty; break; default: return(false); break; } pCellOnMyWay.CellType = ECellType.Worker; pWorkerCell.CellType = ECellType.Empty; return(true); }
/// <summary> /// Загрузка из файла /// </summary> /// <param name="sFileName"></param> public void Load(string sFileName) { // 1;;;;;;;;;;1 string[] arLines = File.ReadAllLines(sFileName); for (int yy = 0; yy < arLines.Length; yy++) { string[] arRows = arLines[yy].Split( new[] { ';' }, StringSplitOptions.None); for (int xx = 0; xx < arRows.Length; xx++) { ECellType enType; string sValue = arRows[xx]; // xx, yy switch (sValue) { case "": case "0": { enType = ECellType.Empty; break; } case "1": { enType = ECellType.Wall; break; } case "2": { enType = ECellType.Place; break; } case "3": { enType = ECellType.Box; break; } case "4": { enType = ECellType.Worker; break; } default: { throw new Exception("Неверный формат файла, некорректное значение " + sValue); } } CCell pCell = new CCell(xx, yy, enType); Field.Add(pCell); } } }
private Control h_GetInCell(CCell pCell) { if (pCell.Container != null) { return(pCell.Container as Control); } foreach (Control pC in panel1.Controls) { if (pC.Tag == null) { continue; } var pInCell = pC.Tag as CCell; if (pInCell == null) { continue; } if (pInCell.X == pCell.X && pInCell.Y == pCell.Y) { return(pC); } } return(null); }