/*
   * Button or JTextField clicked
   */
  public void switchCards(String s) {
    System.out.println("Switching to " + s);

    CardLayout cl = (CardLayout) (mainPanels.getLayout());
    cl.show(mainPanels, s);
    mainPanels.revalidate();

    CardLayout cl2 = (CardLayout) (sidePanels.getLayout());
    cl2.show(sidePanels, s);
    sidePanels.revalidate();
  }
Пример #2
0
  private void addConfigurable(Configurable configurable, boolean addToSidePanel) {
    myName2Config.add(configurable);

    if (addToSidePanel) {
      mySidePanel.addPlace(
          createPlaceFor(configurable), new Presentation(configurable.getDisplayName()));
    }
  }
Пример #3
0
 private void drawSnake(Graphics2D g) {
   g.setColor(panel.getColor());
   for (BodyPart bodyPart : snake.getBody()) {
     g.fillRect(
         bodyPart.getX() * CELL_SIZE - CELL_SIZE,
         game.getScreenSize().height - (bodyPart.getY() * CELL_SIZE),
         CELL_SIZE,
         CELL_SIZE);
   }
 }
Пример #4
0
  private void initSidePanel() {
    boolean isDefaultProject = myProject == ProjectManager.getInstance().getDefaultProject();

    mySidePanel = new SidePanel(this, myHistory);
    mySidePanel.addSeparator("Project Settings");
    addProjectConfig();
    if (!isDefaultProject) {
      addModulesConfig();
    }
    addProjectLibrariesConfig();

    if (!isDefaultProject) {
      addFacetsConfig();
      addArtifactsConfig();
    }

    ProjectStructureConfigurableContributor[] adders =
        ProjectStructureConfigurableContributor.EP_NAME.getExtensions();
    for (ProjectStructureConfigurableContributor adder : adders) {
      for (Configurable configurable : adder.getExtraProjectConfigurables(myProject, myContext)) {
        addConfigurable(configurable, true);
      }
    }

    mySidePanel.addSeparator("Platform Settings");
    addJdkListConfig();
    addGlobalLibrariesConfig();

    for (ProjectStructureConfigurableContributor adder : adders) {
      for (Configurable configurable : adder.getExtraPlatformConfigurables(myProject, myContext)) {
        addConfigurable(configurable, true);
      }
    }

    if (Registry.is("ide.new.project.settings")) {
      mySidePanel.addSeparator("--");
      addErrorPane();
    }
  }
Пример #5
0
  /** Starts the game running. */
  private void startGame() {
    /*
     * Initialize everything we're going to be using.
     */
    this.random = new Random();
    this.snake = new LinkedList<>();
    this.directions = new LinkedList<>();
    this.logicTimer = new Clock(9.0f);
    this.isNewGame = true;

    // Set the timer to paused initially.
    logicTimer.setPaused(true);

    /*
     * This is the game loop. It will update and render the game and will
     * continue to run until the game window is closed.
     */
    while (true) {
      // Get the current frame's start time.
      long start = System.nanoTime();

      // Update the logic timer.
      logicTimer.update();

      /*
       * If a cycle has elapsed on the logic timer, then update the game.
       */
      if (logicTimer.hasElapsedCycle()) {
        updateGame();
      }

      // Repaint the board and side panel with the new content.
      board.repaint();
      side.repaint();

      /*
       * Calculate the delta time between since the start of the frame
       * and sleep for the excess time to cap the frame rate. While not
       * incredibly accurate, it is sufficient for our purposes.
       */
      long delta = (System.nanoTime() - start) / 1000000L;
      if (delta < FRAME_TIME) {
        try {
          Thread.sleep(FRAME_TIME - delta);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
Пример #6
0
  // змейка будет двигаться как только нужная задержка была достигнута
  // обрабатывает внесенные изменения и обновляет игровое поле
  @Override
  public void update(long nanosPassed) {

    processInput();
    if (!paused) {
      if (isGameOver()) {
        game.setScene(new GameOverScence(game, panel, delay));
        return;
      }

      if (snakeMoveDelay.updateAndCheck(nanosPassed)) {
        stepsCount++;
        mlSeconds += 200;
        String seconds = Clock.getTime(mlSeconds);
        panel.setData(seconds, stepsCount, appleCount);

        snake.move(); // удлинение змейки, при поедании яблока
        BodyPart head = snake.head();
        if (head.getX() < 1) {
          head.setX(WORLD_WIDTH);
        }
        if (head.getX() > WORLD_WIDTH) {
          head.setX(1);
        }
        if (head.getY() < 1) {
          head.setY(WORLD_HEIGHT);
        }
        if (head.getY() > WORLD_HEIGHT) {
          head.setY(1);
        }
        if (head.getX() == apple.getX() && head.getY() == apple.getY()) {
          List<BodyPart> body = snake.getBody();
          BodyPart lastPart = body.get(body.size() - 1);
          body.add(new BodyPart(lastPart.getX(), lastPart.getY()));
          ++appleCount;
          if (isGameOver()) {
            game.setScene(new GameOverScence(game, panel, delay));
          } else {
            placeApple();
          }
        }
      }
    }
  }
  // Constructor connection receiving a socket number
  public ClientGUI(String host, int port, int udpPort) {

    super("Clash of Clans");
    defaultPort = port;
    defaultUDPPort = udpPort;
    defaultHost = host;

    // the server name and the port number
    JPanel serverAndPort = new JPanel(new GridLayout(1, 5, 1, 3));
    tfServer = new JTextField(host);
    tfPort = new JTextField("" + port);
    tfPort.setHorizontalAlignment(SwingConstants.RIGHT);

    // CHAT COMPONENTS
    chatStatus = new JLabel("Please login first", SwingConstants.LEFT);
    chatField = new JTextField(18);
    chatField.setBackground(Color.WHITE);

    JPanel chatControls = new JPanel();
    chatControls.add(chatStatus);
    chatControls.add(chatField);
    chatControls.setBounds(0, 0, 200, 50);

    chatArea = new JTextArea("Welcome to the Chat room\n", 80, 80);
    chatArea.setEditable(false);
    JScrollPane jsp = new JScrollPane(chatArea);
    jsp.setBounds(0, 50, 200, 550);

    JPanel chatPanel = new JPanel(null);
    chatPanel.setSize(1000, 600);
    chatPanel.add(chatControls);
    chatPanel.add(jsp);

    // LOGIN COMPONENTS
    mainLogin = new MainPanel();
    mainLogin.add(new JLabel("Main Login"));

    usernameField = new JTextField("user", 15);
    passwordField = new JTextField("password", 15);
    login = new CButton("Login");
    login.addActionListener(this);

    sideLogin = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    sideLogin.add(usernameField);
    sideLogin.add(passwordField);
    sideLogin.add(login);

    // MAIN MENU COMPONENTS
    mainMenu = new MainPanel();
    mmLabel = new JLabel("Main Menu");
    timer = new javax.swing.Timer(1000, this);
    mainMenu.add(mmLabel);

    sideMenu = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    cmButton = new CButton("Customize Map");
    tmButton = new CButton("Troop Movement");
    gsButton = new CButton("Game Start");
    logout = new CButton("Logout");
    cmButton.addActionListener(this);
    tmButton.addActionListener(this);
    gsButton.addActionListener(this);
    logout.addActionListener(this);
    sideMenu.add(cmButton);
    // sideMenu.add(tmButton);
    sideMenu.add(gsButton);
    sideMenu.add(logout);

    // CM COMPONENTS
    mainCM = new MainPanel(new GridLayout(mapSize, mapSize));
    tiles = new Tile[mapSize][mapSize];
    int tileSize = mainCM.getWidth() / mapSize;
    for (int i = 0; i < mapSize; i++) {
      tiles[i] = new Tile[mapSize];
      for (int j = 0; j < mapSize; j++) {
        tiles[i][j] = new Tile(i, j);
        tiles[i][j].setPreferredSize(new Dimension(tileSize, tileSize));
        tiles[i][j].setSize(tileSize, tileSize);
        tiles[i][j].addActionListener(this);

        if ((i + j) % 2 == 0) tiles[i][j].setBackground(new Color(102, 255, 51));
        else tiles[i][j].setBackground(new Color(51, 204, 51));

        mainCM.add(tiles[i][j]);
      }
    }

    sideCM = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    cmBack = new CButton("Main Menu");
    cmBack.setSize(150, 30);
    cmBack.setPreferredSize(new Dimension(150, 30));
    cmBack.addActionListener(this);
    sideCM.add(cmBack);

    // TM COMPONENTS
    mainTM = new MainPanel(null);
    mapTM = new Map(600);
    mapTM.setPreferredSize(new Dimension(600, 600));
    mapTM.setSize(600, 600);
    mapTM.setBounds(0, 0, 600, 600);
    mainTM.add(mapTM);

    sideTM = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    tmBack = new CButton("Main Menu");
    tmBack.setSize(150, 30);
    tmBack.setPreferredSize(new Dimension(150, 30));
    tmBack.addActionListener(this);
    sideTM.add(tmBack);

    JRadioButton button;
    ButtonGroup group;

    ub = new ArrayList<JRadioButton>();
    group = new ButtonGroup();

    button = new JRadioButton("Barbarian");
    button.addActionListener(this);
    ub.add(button);
    sideTM.add(button);
    group.add(button);

    button = new JRadioButton("Archer");
    button.addActionListener(this);
    ub.add(button);
    sideTM.add(button);
    group.add(button);

    createBuildings();
    bb = new ArrayList<JRadioButton>();

    group = new ButtonGroup();

    JRadioButton removeButton = new JRadioButton("Remove Building");
    bb.add(removeButton);
    sideCM.add(removeButton);
    group.add(removeButton);

    for (int i = 0; i < bList.size(); i++) {
      button = new JRadioButton(bList.get(i).getName() + '-' + bList.get(i).getQuantity());
      bb.add(button);
      sideCM.add(button);
      group.add(button);
    }

    mainPanels = new MainPanel(new CardLayout());
    mainPanels.add(mainLogin, "Login");
    mainPanels.add(mainMenu, "Menu");
    mainPanels.add(mainCM, "CM");
    mainPanels.add(mainTM, "TM");

    sidePanels = new SidePanel(new CardLayout());
    sidePanels.add(sideLogin, "Login");
    sidePanels.add(sideMenu, "Menu");
    sidePanels.add(sideCM, "CM");
    sidePanels.add(sideTM, "TM");

    JPanel mainPanel = new JPanel(null);
    mainPanel.setSize(1000, 600);
    mainPanel.add(sidePanels);
    mainPanel.add(mainPanels);
    mainPanel.add(chatPanel);

    add(mainPanel, BorderLayout.CENTER);

    try {
      setIconImage(ImageIO.read(new File("images/logo.png")));
    } catch (IOException exc) {
      exc.printStackTrace();
    }

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(1000, 600);
    setVisible(true);
    setResizable(false);
    chatField.requestFocus();
  }
Пример #8
0
  @Override
  public ActionCallback navigateTo(@Nullable final Place place, final boolean requestFocus) {
    final Configurable toSelect = (Configurable) place.getPath(CATEGORY);

    JComponent detailsContent = myDetails.getTargetComponent();

    if (mySelectedConfigurable != toSelect) {
      if (mySelectedConfigurable instanceof BaseStructureConfigurable) {
        ((BaseStructureConfigurable) mySelectedConfigurable).onStructureUnselected();
      }
      saveSideProportion();
      removeSelected();

      if (toSelect != null) {
        detailsContent = toSelect.createComponent();
        myDetails.setContent(detailsContent);
      }

      mySelectedConfigurable = toSelect;
      if (mySelectedConfigurable != null) {
        myUiState.lastEditedConfigurable = mySelectedConfigurable.getDisplayName();
      }

      if (toSelect instanceof MasterDetailsComponent) {
        final MasterDetailsComponent masterDetails = (MasterDetailsComponent) toSelect;
        if (myUiState.sideProportion > 0) {
          masterDetails.getSplitter().setProportion(myUiState.sideProportion);
        }
        masterDetails.setHistory(myHistory);
      }

      if (toSelect instanceof DetailsComponent.Facade) {
        ((DetailsComponent.Facade) toSelect)
            .getDetailsComponent()
            .setBannerMinHeight(myToolbarComponent.getPreferredSize().height);
      }

      if (toSelect instanceof BaseStructureConfigurable) {
        ((BaseStructureConfigurable) toSelect).onStructureSelected();
      }
    }

    if (detailsContent != null) {
      JComponent toFocus = IdeFocusTraversalPolicy.getPreferredFocusedComponent(detailsContent);
      if (toFocus == null) {
        toFocus = detailsContent;
      }
      if (requestFocus) {
        myToFocus = toFocus;
        UIUtil.requestFocus(toFocus);
      }
    }

    final ActionCallback result = new ActionCallback();
    Place.goFurther(toSelect, place, requestFocus).notifyWhenDone(result);

    myDetails.revalidate();
    myDetails.repaint();

    if (toSelect != null) {
      mySidePanel.select(createPlaceFor(toSelect));
    }

    if (!myHistory.isNavigatingNow() && mySelectedConfigurable != null) {
      myHistory.pushQueryPlace();
    }

    return result;
  }