예제 #1
0
  FactorySimulation(Factory inFactory, JTable inTable, FactoryManager mFactoryManager) {
    isDone = false;
    mFactory = inFactory;
    this.mFactoryManager = mFactoryManager;
    mFNodes = new FactoryNode[mFactory.getWidth()][mFactory.getHeight()];

    // Create the nodes of the factory
    for (int height = 0; height < mFactory.getHeight(); height++) {
      for (int width = 0; width < mFactory.getWidth(); width++) {
        mFNodes[width][height] = new FactoryNode(width, height);
        mFObjects.add(mFNodes[width][height]);
      }
    }

    // Link all of the nodes together
    for (FactoryNode[] nodes : mFNodes) {
      for (FactoryNode node : nodes) {
        int x = node.getX();
        int y = node.getY();
        if (x != 0) node.addNeighbor(mFNodes[x - 1][y]);
        if (x != mFactory.getWidth() - 1) node.addNeighbor(mFNodes[x + 1][y]);
        if (y != 0) node.addNeighbor(mFNodes[x][y - 1]);
        if (y != mFactory.getHeight() - 1) node.addNeighbor(mFNodes[x][y + 1]);
      }
    }

    // Create the resources
    for (Resource resource : mFactory.getResources()) {
      FactoryResource fr = new FactoryResource(resource);
      mFObjects.add(fr);
      mFNodes[fr.getX()][fr.getY()].setObject(fr);
      mFNodeMap.put(fr.getName(), mFNodes[fr.getX()][fr.getY()]);
    }

    // Create the task board
    Point taskBoardLocation = mFactory.getTaskBoardLocation();
    mTaskBoard =
        new FactoryTaskBoard(
            inTable, inFactory.getProducts(), taskBoardLocation.x, taskBoardLocation.y);
    mFObjects.add(mTaskBoard);
    mFNodes[taskBoardLocation.x][taskBoardLocation.y].setObject(mTaskBoard);
    mFNodeMap.put("Task Board", mFNodes[taskBoardLocation.x][taskBoardLocation.y]);

    for (int i = 11; i < 13; ++i) {
      for (int j = 11; j < 13; ++j) {
        FactoryWorkbench mFactoryWorkbench = new FactoryWorkbench(new Rectangle(i, j, 1, 1));
        mFNodes[i][j].setObject(mFactoryWorkbench);
        // mFNodeMap.put("Workbench", mFNodes[0][mFactory.getHeight()-1]);
        mFObjects.add(mFactoryWorkbench);
        mFactoryworkbenches.add(mFactoryWorkbench);
      }
    }

    FactoryWorkroomDoor door =
        new FactoryWorkroomDoor(new Rectangle(9, 12, 1, 1), mFactoryworkbenches);
    mFNodes[9][12].setObject(door);
    mFNodeMap.put("Workroom", mFNodes[9][12]);
    mFObjects.add(door);

    //		mFactoryWorkbench = new FactoryWorkbench(new Rectangle(0, mFactory.getHeight()-1, 1, 1));
    //		mFNodes[0][mFactory.getHeight()-1].setObject(mFactoryWorkbench);
    //		mFNodeMap.put("Workbench", mFNodes[0][mFactory.getHeight()-1]);
    //		mFObjects.add(mFactoryWorkbench);

    Scanner reader = null;
    try {
      reader = new Scanner(new File("walss"));
      while (reader.hasNext()) {
        int x = reader.nextInt();
        int y = reader.nextInt();
        String file = reader.next();
        FactoryWall fw = new FactoryWall(new Rectangle(x, y, 1, 1), file);
        mFObjects.add(fw);
        mFNodes[fw.getX()][fw.getY()].setObject(fw);
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } finally {
      if (reader != null) {
        reader.close();
      }
    }

    // Create the workers, set their first task to look at the task board
    for (int i = 0; i < mFactory.getNumberOfWorkers() + 5; i++) {
      // Start each worker at the first node (upper left corner)
      // Note, may change this, but all factories have an upper left corner(0,0) so it makes sense
      FactoryWorker fw = new FactoryWorker(i, mFNodes[0][0], this);
      mFObjects.add(fw);
      mFWorkers.add(fw);
    }

    for (int i = 0; i < 3; ++i) {
      FactoryStockPersons sp = new FactoryStockPersons(i, mFNodes[0][0], this);
      mFObjects.add(sp);
      mFWorkers.add(sp);
    }

    mMailBox = new FactoryMailBox(mFactory.getResources());
    mFObjects.add(mMailBox);
    mFNodes[0][0].setObject(mMailBox);
    mFNodeMap.put("MailBox", mFNodes[0][0]);

    FactoryRobotBin robotBin = new FactoryRobotBin(new Rectangle(10, 0, 1, 1));
    mFNodes[10][0].setObject(robotBin);
    mFNodeMap.put("RobotBin", mFNodes[10][0]);
    mFObjects.add(robotBin);

    for (int i = 0; i < 15; i++) {
      FactoryRobot robot = new FactoryRobot(i, this.getNode("RobotBin"), this);
      mFObjects.add(robot);
      mFWorkers.add(robot);
    }

    for (FactoryWorker fw : mFWorkers) {
      fw.getThread().start();
    }
  }
예제 #2
0
 public double getHeight() {
   return mFactory.getHeight();
 }
예제 #3
0
 public String getName() {
   return mFactory.getName();
 }
예제 #4
0
 public double getWidth() {
   return mFactory.getWidth();
 }
  FactorySimulation(Factory inFactory, JTable inTable) {
    mFactory = inFactory;
    mFNodes = new FactoryNode[mFactory.getWidth()][mFactory.getHeight()];

    // Create the nodes of the factory
    for (int height = 0; height < mFactory.getHeight(); height++) {
      for (int width = 0; width < mFactory.getWidth(); width++) {
        mFNodes[width][height] = new FactoryNode(width, height);
        mFObjects.add(mFNodes[width][height]);
      }
    }

    Scanner reader = null;
    try {
      reader = new Scanner(new File("walls"));
      while (reader.hasNext()) {
        int x = reader.nextInt();
        int y = reader.nextInt();
        String file = reader.next();
        FactoryWall fw = new FactoryWall(new Rectangle(x, y, 1, 1), file);
        mFObjects.add(fw);
        mFNodes[fw.getX()][fw.getY()].setObject(fw);
      }
    } catch (FileNotFoundException fnfe) {
      fnfe.getMessage();
    } finally {
      if (reader != null) reader.close();
    }

    // Link all of the nodes together
    for (FactoryNode[] nodes : mFNodes) {
      for (FactoryNode node : nodes) {
        int x = node.getX();
        int y = node.getY();
        if (x != 0) node.addNeighbor(mFNodes[x - 1][y]);
        if (x != mFactory.getWidth() - 1) node.addNeighbor(mFNodes[x + 1][y]);
        if (y != 0) node.addNeighbor(mFNodes[x][y - 1]);
        if (y != mFactory.getHeight() - 1) node.addNeighbor(mFNodes[x][y + 1]);
      }
    }

    // Create walls
    /*for (int i = 0; i < 10; i++) {
    	FactoryWall fw = new FactoryWall(new Rectangle(7, i, 1, 1));
    	mFObjects.add(fw);
    	mFNodes[fw.getX()][fw.getY()].setObject(fw);
    }
    for (int i = 0; i < 6; i++) {
    	FactoryWall fw = new FactoryWall(new Rectangle(i, 9, 1, 1));
    	mFObjects.add(fw);
    	mFNodes[fw.getX()][fw.getY()].setObject(fw);
    }*/

    // Create the resources
    for (Resource resource : mFactory.getResources()) {
      FactoryResource fr = new FactoryResource(resource);
      mFObjects.add(fr);
      mFNodes[fr.getX()][fr.getY()].setObject(fr);
      mFNodeMap.put(fr.getName(), mFNodes[fr.getX()][fr.getY()]);
    }

    // Create the task board
    Point taskBoardLocation = mFactory.getTaskBoardLocation();
    mTaskBoard =
        new FactoryTaskBoard(
            inTable, inFactory.getProducts(), taskBoardLocation.x, taskBoardLocation.y);
    mFObjects.add(mTaskBoard);
    mFNodes[taskBoardLocation.x][taskBoardLocation.y].setObject(mTaskBoard);
    mFNodeMap.put("Task Board", mFNodes[taskBoardLocation.x][taskBoardLocation.y]);

    // Create the workers, set their first task to look at the task board
    for (int i = 0; i < mFactory.getNumberOfWorkers(); i++) {
      // Start each worker at the first node (upper left corner)
      // Note, may change this, but all factories have an upper left corner(0,0) so it makes sense
      FactoryWorker fw = new FactoryWorker(i, mFNodes[0][0], this);
      mFObjects.add(fw);
      mFWorkers.add(fw);
    }

    // Create the mailbox
    mMailbox =
        new FactoryMailbox(mFactory.getResources()); // Mailbox that can stock the factory resources
    mFObjects.add(mMailbox); // Add this object to be rendered
    mFNodes[0][0].setObject(mMailbox); // Link this object to node 0,0
    mFNodeMap.put("Mailbox", mFNodes[0][0]); // Make it easy to find the mailbox node

    // Create some stockpersons
    for (int i = 0; i < 3; i++) {
      FactoryStockPerson sp = new FactoryStockPerson(i, mFNodes[0][0], this);
      mFObjects.add(sp);
      mFWorkers.add(sp);
    }
  }