public bool Isfinished() { int amountOfChests = 0; for (int i = 0; i < FieldDoublyDoublyLinkedList.RowFirst.Length; i++) { FieldDoublyDoublyLink FDDL = FieldDoublyDoublyLinkedList.RowFirst[i]; while (FDDL != null) { if (FDDL.Floor.Type == "destination") { if (FDDL.Floor.Chest != null) { amountOfChests++; } } FDDL = FDDL.Next; } } return(amountOfChests == Destinations); }
public void AddField(FieldDoublyDoublyLink fieldType, int row) { if (fieldType.Floor.Type == "truck") { FieldDoublyDoublyLinkedList.Truck = fieldType; } if (FieldDoublyDoublyLinkedList.RowFirst[row] == null) { if (row == 0) { FieldDoublyDoublyLinkedList.RowFirst[row] = fieldType; FieldDoublyDoublyLinkedList.Last = fieldType; } else { FieldDoublyDoublyLinkedList.RowFirst[row] = fieldType; FieldDoublyDoublyLinkedList.RowFirst[row - 1].Down = fieldType; fieldType.Up = FieldDoublyDoublyLinkedList.RowFirst[row - 1]; FieldDoublyDoublyLinkedList.Last = fieldType; } } else if (row == 0 && FieldDoublyDoublyLinkedList.RowFirst[row] != null) { fieldType.Previous = FieldDoublyDoublyLinkedList.Last; FieldDoublyDoublyLinkedList.Last.Next = fieldType; FieldDoublyDoublyLinkedList.Last = fieldType; } else { fieldType.Previous = FieldDoublyDoublyLinkedList.Last; FieldDoublyDoublyLinkedList.Last.Up.Next.Down = fieldType; fieldType.Up = FieldDoublyDoublyLinkedList.Last.Up.Next; FieldDoublyDoublyLinkedList.Last.Next = fieldType; FieldDoublyDoublyLinkedList.Last = fieldType; } }
public void AddEmployee(Employee employee, FieldDoublyDoublyLink field) { Employee = employee; employee.Current = field; }
public void AddTruck(Truck truck, FieldDoublyDoublyLink field) { Truck = truck; truck.Current = field; }
private void ShowMaze() { string[] values = new string[maze.FieldDoublyDoublyLinkedList.RowFirst.Length]; for (int i = 0; i < values.Length; i++) { FieldDoublyDoublyLink item = new FieldDoublyDoublyLink(); item = maze.FieldDoublyDoublyLinkedList.RowFirst[i]; while (item != null) { switch (item.Floor.Type) { case "floor": if (item.Floor.Truck != null) { values[i] += '@'; } else if (item.Floor.Chest != null) { values[i] += 'O'; } else if (item.Floor.Employee != null) { values[i] += item.Floor.Employee.Type; } else { values[i] += '.'; } break; case "destination": if (item.Floor.Truck != null) { values[i] += '@'; } else if (item.Floor.Chest != null) { values[i] += '0'; } else if (item.Floor.Employee != null) { values[i] += item.Floor.Employee.Type; } else { values[i] += 'X'; } break; case "wall": values[i] += '█'; break; case "freefall": if (item.Floor.Truck != null) { values[i] += '@'; } else if (item.Floor.Chest != null) { values[i] += 'O'; } else if (item.Floor.Employee != null) { values[i] += item.Floor.Employee.Type; } else { values[i] += ' '; } break; case "pitfall": if (item.Floor.Truck != null) { values[i] += '@'; } else if (item.Floor.Chest != null) { values[i] += 'O'; } else if (item.Floor.Employee != null) { values[i] += item.Floor.Employee.Type; } else { values[i] += '~'; } break; case "empty": values[i] += ' '; break; default: break; } item = item.Next; } } outputView.DisplayMaze(values); }
public Maze ParseMaze(char mazeNumber) { try { if (mazeNumber == 's') { Environment.Exit(0); } string[] lines = File.ReadAllLines("../../../Mazes/doolhof" + mazeNumber + ".txt"); Maze = new Maze(lines.Count()); int row = -1; foreach (string line in lines) { row++; foreach (char c in line) { FieldDoublyDoublyLink fieldDoublyDoublyLink = new FieldDoublyDoublyLink(); switch (c) { case '.': fieldDoublyDoublyLink.Floor = new Normal(); Maze.AddField(fieldDoublyDoublyLink, row); break; case '#': fieldDoublyDoublyLink.Floor = new Wall(); Maze.AddField(fieldDoublyDoublyLink, row); break; case 'o': Chest chest = new Chest(); fieldDoublyDoublyLink.Floor = new Normal(); fieldDoublyDoublyLink.Floor.Chest = chest; Maze.AddField(fieldDoublyDoublyLink, row); chest.Current = fieldDoublyDoublyLink; break; case 'x': Maze.Destinations++; fieldDoublyDoublyLink.Floor = new Destination(); Maze.AddField(fieldDoublyDoublyLink, row); break; case '~': fieldDoublyDoublyLink.Floor = new Pitfall(); Maze.AddField(fieldDoublyDoublyLink, row); break; case '@': Truck truck = new Truck(); fieldDoublyDoublyLink.Floor = new Normal(); fieldDoublyDoublyLink.Floor.Truck = truck; Maze.AddField(fieldDoublyDoublyLink, row); Maze.AddTruck(truck, fieldDoublyDoublyLink); break; case '$': Employee employee = new Employee(); fieldDoublyDoublyLink.Floor = new Normal(); fieldDoublyDoublyLink.Floor.Employee = employee; Maze.AddField(fieldDoublyDoublyLink, row); Maze.AddEmployee(employee, fieldDoublyDoublyLink); break; default: fieldDoublyDoublyLink.Floor = new Empty(); Maze.AddField(fieldDoublyDoublyLink, row); break; } } } } catch { outputView.FileNotFound(); outputView.ChooseMaze(); } return(Maze); }