public Weed(int x, int y) { X = x; Y = y; WeedState = WeedStates.Alive; FieldState = FieldCellStates.Weed; }
public FieldCell GetCurrentPosition(FieldCellStates state, Field field) { for (var i = 0; i < field.Width; i++) { for (int j = 0; j < field.Height; j++) { if (field.field[i, j] == state) { return(new FieldCell(i, j, state)); } } } throw new Exception("Something went wrong"); }
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 FieldCell(int x, int y, FieldCellStates state) { X = x; Y = y; State = state; }