Пример #1
0
 @Override
 public int hashCode() {
   int result = skill;
   result = 31 * result + (scheme != null ? scheme.hashCode() : 0);
   result = 31 * result + (name != null ? name.hashCode() : 0);
   return result;
 }
  /**
   * Overrides the parent class to return random colors. Only valid for cells with integer states,
   * this gets a color corresponding to the given state.
   *
   * @param state The current cell state.
   * @param numStates The number of states used in the simulation.
   * @param currentView The view used by the cell.
   * @return A color appropriate for the given state.
   */
  public Color getColor(int state, int numStates, CellStateView currentView) {
    // the number of times this method has been called
    numCalls++;

    // create an array of random colors, but only when necessary. Why this
    // complicated scheme? Because the properties may change the number of
    // states. And if the number of states changes, the initial states panel
    // will draw random colors for that many states. But that may be more
    // than the number of states being used by the current simulation. So
    // the initial states panel would inadvertently change the colors of the
    // current simulation. Very annoying. The "else-if" code prevents that.
    if (randomColors == null) {
      randomColors = new Color[numStates];
      for (int i = 0; i < numStates; i++) {
        randomColors[i] = new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
      }

      super.setEmptyColor(randomColors[0]);
      super.setFilledColor(randomColors[numStates - 1]);
    } else if (randomColors.length < numStates) {
      // copy the original colors (so they are not lost)
      Color[] newRandomColors = new Color[numStates];
      for (int i = 0; i < randomColors.length; i++) {
        newRandomColors[i] = randomColors[i];
      }

      // now create new colors (tack them onto the end of the original
      // colors)
      for (int i = randomColors.length; i < numStates; i++) {
        newRandomColors[i] =
            new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256));
      }

      randomColors = newRandomColors;

      // and reset the empty and filled colors, but only if this is the
      // same view (otherwise this is being called by the initial state
      // tab, and we don't want to change the simulation; we only want
      // to change the initial state which is trying to set up for a
      // different number of cell states.)
      if (this.currentView == currentView) {
        super.setEmptyColor(randomColors[0]);
        super.setFilledColor(randomColors[numStates - 1]);
      }
    }

    // only set the current view when first called
    if (numCalls == 1) {
      this.numStates = numStates;
      this.currentView = currentView;
    }

    // now get the color that will be returned. Note that this replaces the
    // array color with the filled and empty color as appropriate. Why?
    // Because the filled and empty colors can be reset from the menu by the
    // user. But those reset values are not stored in this class' color
    // array.
    Color theColor = null;
    if (state == 0) {
      theColor = getEmptyColor();
    } else if (state == numStates - 1) {
      theColor = getFilledColor();
    } else {
      theColor = randomColors[state];
    }

    return theColor;
  }
 /** Overrides the parent so that the random array is also given a new filled color. */
 public void setFilledColor(Color color) {
   super.setFilledColor(color);
   randomColors[numStates - 1] = color;
 }
 /** Overrides the parent so that the random array is also given a new empty color. */
 public void setEmptyColor(Color color) {
   super.setEmptyColor(color);
   randomColors[0] = color;
 }
Пример #5
0
  /**
   * main: This method initializes and coordinates the main actions of the game. Pre: None Post: The
   * game has been completed
   */
  public static void main(String[] args) {
    JOptionPane.showMessageDialog(
        null,
        "CLEANSANITY\n"
            + "Instructions:\n"
            + "Use W, A, S, and D to move the Cleansinator towards the exit (a pulsating GREEN tile)\n"
            + "Clean the forces of dirt by pointing at them and pressing the RIGHT or LEFT MOUSE BUTTONS.\n"
            + "Use COMMA and PERIOD to zoom in and out.\n"
            + "Press SHIFT to toggle sprint.\n"
            + "Use P and O to increase/decrease the volume.",
        "CLEANSANITY",
        JOptionPane.PLAIN_MESSAGE);

    String strSeedToSetTo =
        JOptionPane.showInputDialog(
            null, "Input a game seed:", "CLEANSANITY", JOptionPane.INFORMATION_MESSAGE);
    try {
      iCurrentMapSeed = Integer.parseInt(strSeedToSetTo);
    } catch (NumberFormatException e) {
      iCurrentMapSeed = strSeedToSetTo.hashCode();
    }

    JOptionPane.showMessageDialog(
        null,
        "CLEANSANITY\n" + "NOW PLAYING: " + iCurrentMapSeed,
        "CLEANSANITY",
        JOptionPane.PLAIN_MESSAGE);

    strGamePath = new File("").getAbsolutePath();

    // Initialization begins
    iGameReadinessState = -1;
    mainGameWindow = new GameWindow();

    GameInput.initGameInput();
    GameSettings.initGameSettings();
    GameSettings.setDefaultKeyBindings();
    ColorScheme.initColorScheme();

    iMSPFOGmAdj = GameSettings.iMSPFOGm;
    lCurrentFrame = 0;
    mainGameWindow.start();

    entveCurrentEntities = new Vector<Entity>();
    addEntity(
        ContentLibrary.PLAYER_BLUEPRINT,
        0,
        0,
        0,
        new ControllerPlayer(),
        new SkeletonHumanoid(),
        ContentLibrary.PLAYER_COLORS);
    // addEntity(ContentLibrary.RAT_BLUEPRINT, 10,17,0, new ControllerAI(), new SkeletonCreature(),
    // ContentLibrary.CREATURE_COLORS);
    // addEntity(ContentLibrary.DIRTY_BUBBLE_BLUEPRINT, 15,15,0, new ControllerAI(), new
    // SkeletonBubble(), ContentLibrary.DIRTY_BUBBLE_COLORS);
    addItem(
        new Item(
            ContentLibrary.DUSTER_BLUEPRINT,
            new ControllerItem(),
            new SkeletonDuster(),
            ContentLibrary.DUSTER_COLORS,
            0,
            handleEntity(0).ensSkeleton.sklaSkeleton[5]),
        handleEntity(0));
    addItem(
        new Item(
            ContentLibrary.BROOM_BLUEPRINT,
            new ControllerItem(),
            new SkeletonBroom(),
            ContentLibrary.BROOM_COLORS,
            0,
            handleEntity(0).ensSkeleton.sklaSkeleton[6]),
        handleEntity(0));

    dngCurrentDungeon = new Dungeon(iCurrentMapSeed);

    iGameReadinessState += 1;
    // Initialization ends
    bRenderMenu = false;
    bRenderGame = true;

    mainGameWindow.show();
    // The Gameplay Loop
    while (true) {

      lGameLoopStartTime = System.currentTimeMillis();

      if (bRenderGame) {
        doGameLoop();
        ColorScheme.updateColorList();
        lCurrentFrame++;
      }
      // Do features such as zoom in, zoom out, calling out menus, etc.
      doNonGameplayInput();
      // Checks whether different music needs to be played
      GameSounds.updateGameSounds();
      regulateFramerate();
    }
  }