public Field(FieldCellStates[,] fieldInit, List <Weed> weedsForField, FieldCell initCell, FieldCell winnerCell) { field = fieldInit; weeds = weedsForField; initialCell = initCell; winCell = winnerCell; }
public static SinglyLinkedList <FieldCell> BossSearch(Field field, FieldCell start, FieldCell playerPosition) { var correctWay = new SinglyLinkedList <FieldCell>(start); var visited = new HashSet <FieldCell>(); var queue = new Queue <SinglyLinkedList <FieldCell> >(); visited.Add(start); queue.Enqueue(new SinglyLinkedList <FieldCell>(start)); while (queue.Count != 0) { var way = queue.Dequeue(); var incidentCells = GetIncidentCells(way.Value); foreach (var incidentCell in incidentCells) { var nextWay = new SinglyLinkedList <FieldCell>( new FieldCell(incidentCell.X, incidentCell.Y, incidentCell.State), way); if (!field.InBounds(nextWay.Value) || visited.Contains(nextWay.Value)) { continue; } queue.Enqueue(nextWay); visited.Add(nextWay.Value); if (nextWay.Value.X == playerPosition.X && nextWay.Value.Y == playerPosition.Y) { return(nextWay); } } } return(correctWay); }
public bool CanMove(int x, int y, Field field) { var cell = new FieldCell(x, y, FieldCellStates.Empty); if (!field.InBounds(cell) || field.field[x, y] is FieldCellStates.Weed) { return(false); } return(true); }
private static List <FieldCell> GetIncidentCells(FieldCell cell) { var incidentPoints = new List <FieldCell>(); for (var dy = -1; dy <= 1; dy++) { for (var dx = -1; dx <= 1; dx++) { if ((dx != 0 && dy != 0) || (dx == 0 && dy == 0)) { continue; } incidentPoints.Add(new FieldCell(cell.X + dx, cell.Y + dy, FieldCellStates.Empty)); } } return(incidentPoints); }
public static Field FromLines(string[] lines) { var len1 = lines[0].Length; var len2 = lines.Length; var field = new FieldCellStates[len1, len2]; var weeds = new List <Weed>(); var initialCell = new FieldCell(0, 0, FieldCellStates.Empty); var winCell = new FieldCell(0, 0, FieldCellStates.Empty); for (var y = 0; y < len2; y++) { for (var x = 0; x < len1; x++) { switch (lines[y][x]) { case 'W': field[x, y] = FieldCellStates.Weed; weeds.Add(new Weed(x, y)); break; case '#': field[x, y] = FieldCellStates.Empty; break; case '@': field[x, y] = FieldCellStates.WinCell; winCell = new FieldCell(x, y, FieldCellStates.WinCell); break; case 'P': field[x, y] = FieldCellStates.Player; initialCell = new FieldCell(x, y, FieldCellStates.Player); break; default: field[x, y] = FieldCellStates.Empty; break; } } } return(new Field(field, weeds, initialCell, winCell)); }
public Player(FieldCell initCell) { CurrentPos = initCell; Scores = 0; Health = 20; }
public bool InBounds(FieldCell cell) { return(cell.X >= 0 && cell.X < this.Width && cell.Y >= 0 && cell.Y < this.Height); }