Beispiel #1
0
 public void exit() {
   if (buttons != null) {
     for (int i = 0; i < buttons.length; i++) {
       environment.getScreenHandler().remove(buttons[i].getComponent());
     }
   }
   if (textFields != null) {
     for (int i = 0; i < textFields.length; i++) {
       environment.getScreenHandler().remove(textFields[i]);
     }
   }
   environment.getScreenHandler().getContainer().removeMouseListener(mouseListener);
 }
Beispiel #2
0
  public void draw() {
    Graphics g = environment.getScreenHandler().getCurrentGraphics();
    g.clearRect(
        0,
        0,
        environment.getScreenHandler().getWidth(),
        environment.getScreenHandler().getHeight());
    fps.update();
    fps.draw(g, Color.red, 10, 10);
    g.setColor(Color.white);
    g.drawString(model.getInfoString(), 50, 10);
    g.setColor(Color.white);
    if (cheatMode) {
      g.setColor(Color.white);
      g.drawString("CHEATMODE", 80, 10);
    }
    g.setClip(cont.getOffsetX(), cont.getOffsetY(), cont.getDrawingSizeX(), cont.getDrawingSizeY());
    if (model.isInitialized()) {
      model.getMap().draw(g, 0);

      model.getMyCar().draw(g, 0);
      CarDrawInterface cars[] = model.getOpponentCars();
      for (int i = 0; i < cars.length; i++) {
        cars[i].draw(g, 0);
      }
      if (!model.isStarted()) {
        g.setColor(Color.white);
        g.clearRect(50, 50, 400, 150);
        g.drawString("Accellerate to start game", 100, 100);
        if (model.isMultiplayer()) {
          if (model.getNoOfHumanCars() > 1) {
            g.drawString(
                "Currently " + (model.getNoOfHumanCars() - 1) + " other human player(s) connected",
                100,
                120);
          } else {
            g.drawString("Only you and computer contolled cars are connected", 100, 120);
          }
          g.drawString("You can wait for more human players to connect", 100, 140);
        }
      }
    } else {
      g.setColor(Color.white);
      g.clearRect(50, 50, 400, 150);
      g.drawString("Loading game data, please wait...", 100, 100);
    }
  }
Beispiel #3
0
  public void init(GameEnvironmentInterface environ) {
    this.environment = environ;
    this.contAllowed = new BlockContainerData(offsetX + 1, offsetY + 20, 3, 10, blockSize);
    this.contNotAllowed =
        new BlockContainerData(offsetX + 1 + 6 * blockSize, offsetY + 20, 3, 10, blockSize);
    levelFactoryAllowed =
        new LevelFactory(environment, contAllowed, LevelFactory.GameType.UntilWaterStopped);
    levelFactoryNotAllowed =
        new LevelFactory(environment, contNotAllowed, LevelFactory.GameType.UntilWaterStopped);

    int rightColumnX =
        contNotAllowed.getDrawingPositionX(0) + contNotAllowed.getSizeX() * blockSize + 10;
    buttons = new EButton[4];
    buttons[0] = EButton.create("Save");
    buttons[0].getComponent().setBounds(rightColumnX, offsetY + 20, 73, 25);
    buttons[1] = EButton.create("Exit");
    buttons[1].getComponent().setBounds(rightColumnX, offsetY + 50, 73, 25);
    buttons[2] = EButton.create("-->");
    buttons[2]
        .getComponent()
        .setBounds(offsetX + contAllowed.getSizeX() * blockSize + 10, offsetY + 50, 73, 25);
    buttons[3] = EButton.create("<--");
    buttons[3]
        .getComponent()
        .setBounds(offsetX + contAllowed.getSizeX() * blockSize + 10, offsetY + 80, 73, 25);
    if (buttons != null) {
      for (int i = 0; i < buttons.length; i++) {
        buttons[i].addActionListener(this);
        environment.getScreenHandler().add(buttons[i].getComponent());
      }
    }
    textFields = new TextField[5];
    textFields[0] = new TextField(String.valueOf(levelFactoryAllowed.getNumberOfEmptyBlocks()), 2);
    textFields[0].setBounds(rightColumnX + 150, 100 + 3, 40, 18);
    textFields[0].setBackground(Color.white);
    textFields[1] = new TextField(String.valueOf(levelFactoryAllowed.getNumberOfStartBlocks()), 2);
    textFields[1].setBounds(rightColumnX + 150, 100 + 28, 40, 18);
    textFields[1].setBackground(Color.white);
    textFields[2] = new TextField(String.valueOf(levelFactoryAllowed.getTimeUntilWater()), 2);
    textFields[2].setBounds(rightColumnX + 150, 100 + 53, 40, 18);
    textFields[2].setBackground(Color.white);
    textFields[3] = new TextField(String.valueOf(levelFactoryAllowed.getWaterSpeed()), 2);
    textFields[3].setBounds(rightColumnX + 150, 100 + 78, 40, 18);
    textFields[3].setBackground(Color.white);
    textFields[4] = new TextField(String.valueOf(levelFactoryAllowed.getLeftToFill()), 2);
    textFields[4].setBounds(rightColumnX + 150, 100 + 103, 40, 18);
    textFields[4].setBackground(Color.white);
    for (int i = 0; i < textFields.length; i++) {
      environment.getScreenHandler().add(textFields[i]);
    }

    selectedBlock = null;
    blocksAllowed = levelFactoryAllowed.getAllowedBlocks();
    blocksNotAllowed = levelFactoryNotAllowed.getNotAllowedBlocks();
    bExit = false;
    mouseListener =
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if ((e.getModifiers() & e.BUTTON1_MASK) != 0) {
              handleLeftMouseClicked(
                  environment.getScreenHandler().getScreenX(e.getX()),
                  environment.getScreenHandler().getScreenY(e.getY()));
            }
          }
        };
    environment.getScreenHandler().getContainer().setBackground(Color.black);
    environment.getScreenHandler().getContainer().requestFocus();
    environment.getScreenHandler().getContainer().addMouseListener(mouseListener);
  }
Beispiel #4
0
  /** Draw all the game graphics */
  public void draw() {
    Graphics g = environment.getScreenHandler().getCurrentGraphics();
    g.clearRect(
        0,
        0,
        environment.getScreenHandler().getWidth(),
        environment.getScreenHandler().getHeight());
    int gameSizeX = (contAllowed.getSizeX() + contNotAllowed.getSizeX() + 3) * blockSize + 2;
    int gameSizeY = contAllowed.getSizeY() * blockSize + 2;
    g.setColor(Color.white);
    g.drawString(
        "Allowed:", contAllowed.getDrawingPositionX(0), contAllowed.getDrawingPositionY(0) - 3);
    g.drawString(
        "Not allowed:",
        contNotAllowed.getDrawingPositionX(0),
        contNotAllowed.getDrawingPositionY(0) - 3);
    g.setColor(Color.blue);
    g.drawRect(
        contAllowed.getDrawingPositionX(0),
        contAllowed.getDrawingPositionY(0),
        contAllowed.getSizeX() * contAllowed.getSquareSize(),
        contAllowed.getSizeY() * contAllowed.getSquareSize());
    g.drawRect(
        contNotAllowed.getDrawingPositionX(0),
        contNotAllowed.getDrawingPositionY(0),
        contNotAllowed.getSizeX() * contNotAllowed.getSquareSize(),
        contNotAllowed.getSizeY() * contNotAllowed.getSquareSize());

    if (blocksAllowed != null) {
      for (int i = 0; i < blocksAllowed.length; i++) {
        blocksAllowed[i].draw(g);
      }
    }
    if (blocksNotAllowed != null) {
      for (int i = 0; i < blocksNotAllowed.length; i++) {
        blocksNotAllowed[i].draw(g);
      }
    }

    if (selectedBlock != null) {
      g.setColor(Color.white);
      BlockContainerInterface cont;
      if (selectedAllowed) {
        cont = contAllowed;
      } else {
        cont = contNotAllowed;
      }
      g.drawRect(
          selectedBlock.getMovingDrawingPosX(),
          selectedBlock.getMovingDrawingPosY(),
          cont.getSquareSize(),
          cont.getSquareSize());
    }

    g.setColor(Color.white);
    int rightColumnX =
        contNotAllowed.getDrawingPositionX(0) + contNotAllowed.getSizeX() * blockSize + 10;
    g.drawString("Number of empty blocks:", rightColumnX, 100 + 15);
    g.drawString("Number of start blocks:", rightColumnX, 100 + 40);
    g.drawString("Initial time until water:", rightColumnX, 100 + 65);
    g.drawString("Initial water speed:", rightColumnX, 100 + 90);
    g.drawString("Initial blocks to fill:", rightColumnX, 100 + 115);
    rightColumnX = offsetX + gameSizeX + 20;
    g.setColor(Color.red);
    g.drawString("by Erland Isaksson", rightColumnX, offsetY + gameSizeY);
    environment.getScreenHandler().paintComponents(g);
  }
Beispiel #5
0
  public void init(GameEnvironmentInterface environment) {
    this.environment = environment;
    bQuit = false;
    cheatMode = false;

    keyListener =
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
              bQuit = true;
            } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
              model.startTurnLeft();
            } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
              model.startTurnRight();
            } else if (e.getKeyCode() == KeyEvent.VK_UP) {
              model.startAccellerating();
            } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
              model.startBraking();
            }
            if (cheatMode) {
              if (e.getKeyCode() == KeyEvent.VK_1) {
                model.setCheatModeParameter("ALLCARSSHOWSERVERCAR", "NONE");
              }
              if (e.getKeyCode() == KeyEvent.VK_2) {
                model.setCheatModeParameter("ALLCARSSHOWSERVERCAR", "BOTH");
              }
              if (e.getKeyCode() == KeyEvent.VK_3) {
                model.setCheatModeParameter("ALLCARSSHOWSERVERCAR", "ONLY");
              }
              if (e.getKeyCode() == KeyEvent.VK_4) {
                model.setCheatModeParameter("MYCARSERVERUPDATETYPE", "1");
              }
              if (e.getKeyCode() == KeyEvent.VK_5) {
                model.setCheatModeParameter("MYCARSERVERUPDATETYPE", "2");
              }
            }
          }

          public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_LEFT) {
              model.stopTurnLeft();
            } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
              model.stopTurnRight();
            } else if (e.getKeyCode() == KeyEvent.VK_UP) {
              model.stopAccellerating();
            } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
              model.stopBraking();
            }
          }
        };
    environment.getScreenHandler().setCursor(null);
    environment.getScreenHandler().getContainer().requestFocus();
    environment.getScreenHandler().getContainer().addKeyListener(keyListener);

    fps = new FpsCounter(50);
    cont = new BlockContainerData(20, 20, 30, 30, 32, 15, 12);

    model.init(environment, cont);

    environment.getScreenHandler().getContainer().setBackground(Color.black);
    // Preload images if not already loaded
    environment.getImageHandler().getImage("car1.gif");
    environment.getImageHandler().getImage("car2.gif");
    environment.getImageHandler().getImage("car3.gif");
    environment.getImageHandler().getImage("car4.gif");
    environment.getImageHandler().getImage("mapicons.gif");
    environment.getImageHandler().getImage("specialmapicons.gif");
  }
Beispiel #6
0
 public void exit() {
   environment.getScreenHandler().getContainer().removeKeyListener(keyListener);
 }