Beispiel #1
0
  /**
   * Constructs a new game.
   *
   * @param web <code>true</code> if this game is meant to be an applet (which can be played
   *     online), and <code>false</code> otherwise. Note: this doesn't work yet.
   */
  public Game() {
    Game.applet = false;
    canvas = new Canvas(this);
    solidShapes = Collections.newSetFromMap(new ConcurrentHashMap<Shape, Boolean>());
    allShapes = Collections.newSetFromMap(new ConcurrentHashMap<Shape, Boolean>());

    // TODO: sort out which data structures actually have to support concurrency
    layerContents = new ConcurrentHashMap<Integer, java.util.List<Shape>>();
    layers = new CopyOnWriteArrayList<Integer>();
    layerOf = new ConcurrentHashMap<Shape, Integer>();

    counters = new ArrayList<Counter>();

    Mouse mouse = new Mouse();
    if (applet) {
      addMouseMotionListener(mouse);
      addMouseListener(mouse);
      addKeyListener(new Keyboard());
    } else {
      frame = new JFrame();
      frame.addMouseMotionListener(mouse);
      frame.addMouseListener(mouse);
      frame.addKeyListener(new Keyboard());
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    setDefaults();
  }
Beispiel #2
0
 public void addTick(Cam c) {
   tickArr.add(new Tick(hs1.getSliderPos(), hsYPos, c, hs1.getPosInSeconds()));
   // set the older ticks to inactive
   for (int i = 0; i < tickArr.size() - 1; i++) {
     tickArr.get(i).setToInActive();
   }
   // sort the ticks in case one was placed before an existing tick
   Collections.sort(tickArr);
 }
Beispiel #3
0
  /**
   * Set the layer that a given shape will be displayed in. Since the shapes in this game are two
   * dimensional, it must be decided which will appear "on top" when two shapes overlap. The shape
   * in the higher layer will appear on top.
   *
   * <p>Setting a shape's layer will only affect how it is displayed; a shape's layer has no effect
   * on how it interacts with other shapes. (For example, two shapes can touch even if they are in
   * different layers. See {@link Shape#isTouching(Shape)}.)
   *
   * @param shape the shape whose layer is being set.
   * @param layer the layer into which this shape will be moved.
   */
  static void setLayer(Shape shape, int layer) {
    removeFromLayers(shape);

    // add new stuff
    if (!layerContents.containsKey(layer)) {
      layerContents.put(layer, new CopyOnWriteArrayList<Shape>());
      int insertionPoint = ~Collections.binarySearch(layers, layer);
      layers.add(insertionPoint, layer);
    }
    layerContents.get(layer).add(shape);
    layerOf.put(shape, layer);
  }
Beispiel #4
0
 /*Create an array list of random orders for the available status - this will help put the equipment randomly*/
 private void randomizeOrderRent() {
   for (int counter = 0; counter < RENTCAPACITYX * RENTCAPACITYY; counter++) {
     randomOrder.add(counter);
   }
   Collections.shuffle(randomOrder);
 }