Exemplo n.º 1
0
  private void drawLadder() {
    int width = (int) (frameSize.getWidth() / player);
    int height = (int) (frameSize.getHeight());

    for (int i = 0; i < player; i++) {
      draw.gImg.drawLine(
          width * i + width / 2, 0, width * i + width / 2, (int) frameSize.getHeight() - 50);
    }
    for (int i = 0; i < ladderMap.length; i++)
      for (int j = 0; j < ladderMap[i].length - 1; j++) {
        if (ladderMap[i][j] == 1) {
          draw.gImg.drawLine(
              width * j + width / 2,
              (int) ((frameSize.getHeight() - 80) / 10 * i + frameSize.getHeight() * 0.02),
              width * (j + 1) + width / 2,
              (int) ((frameSize.getHeight() - 80) / 10 * i + frameSize.getHeight() * 0.02));
          // draw.gImg.drawLine((int)(frameSize.getWidth()/player*j+frameSize.getWidth()/player/2),
          // (int)((frameSize.getHeight()-80)/10*i+frameSize.getHeight()*0.02),
          // (int)(frameSize.getWidth()/player*(j+1)+frameSize.getWidth()/player/2),
          // (int)((frameSize.getHeight()-80)/10*i+frameSize.getHeight()*0.02));
        }
      }
    draw.repaint();
  }
Exemplo n.º 2
0
  public void actionPerformed(ActionEvent event) {
    if (d.again) {
      initTree(tree);
      d.again = false;
    }
    if (event.getSource() == send) {
      String c1 = attachment1.getText();
      String c2 = attachment2.getText();
      String c3 = valueOfArc.getText();

      if (c1.matches(regularExpression)
          && c2.matches(regularExpression)
          && c3.matches(regularExpression)) {

        int s1 = Integer.parseInt(c1);
        int s2 = Integer.parseInt(c2);
        int value = Integer.parseInt(c3);

        if (s1 <= d.getNumberOfNodes() && s2 <= d.getNumberOfNodes() && s1 != s2) {
          Arc a = new Arc(s1, s2, value);

          boolean already = false;
          int emplacement = 0;
          int i = 0;

          while (tree[i] != null && i < tree.length) {
            if ((tree[i].getNode1() == a.getNode1() || tree[i].getNode1() == a.getNode2())
                && (tree[i].getNode2() == a.getNode1() || tree[i].getNode2() == a.getNode2())) {
              emplacement = i;
              already = true;
            }
            i++;
          }
          if (!already) {
            tree[d.getNumberOfArc()] = a;
            d.addArc(a, d.getNumberOfArc());
          } else {
            tree[emplacement].setCost(value);
            d.modifArc(emplacement, value);
          }

          d.repaint();
        }
      }
    } else if (event.getSource() == step) {
      if (tree[0] != null) {
        if (d.getCpt() == 0) {
          if (d.getChoice().equals("Kruskal")) {
            k = new Kruskal(tree, d.getNumberOfNodes(), d.getNumberOfArc());
            d.finalTree = k.tree;
          }

          d.end = true;
        }

        if (d.finalTree[d.getCpt()] != null) {
          d.setCpt(d.getCpt() + 1);
        }
        d.repaint();
      }
    }
  }
Exemplo n.º 3
0
  private void init() {
    setLayout(new BorderLayout());
    setVisible(false);

    state = 2;

    con.removeAll();

    setSize(600, 450);

    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    frameSize = getSize();
    setLocation(
        (int) (screen.getWidth() / 2 - frameSize.getWidth() / 2),
        (int) (screen.getHeight() / 2 - frameSize.getHeight() / 2));

    con = getContentPane();
    setVisible(true);

    ladderWidth = player;
    ladderMap = new int[ladderHeight][ladderWidth];

    player_pl = new JPanel();
    goal_pl = new JPanel();
    player_pl.setLayout(new GridLayout(1, 1, 5, 5));
    goal_pl.setLayout(new GridLayout(1, 1, 5, 5));

    player_bt = new JButton[player];
    goal_bt = new JButton[player];

    for (int i = 0; i < player; i++) {
      String s = String.valueOf(i + 1) + "번";
      player_bt[i] = new JButton(s);
      goal_bt[i] = new JButton("꽝");
      player_bt[i].setBounds(
          (int) (frameSize.getWidth() / player * i + frameSize.getWidth() / player * 0.1), 5,
          (int) (frameSize.getWidth() / player * 0.85), 25);
      goal_bt[i].setBounds(
          (int) (frameSize.getWidth() / player * i + frameSize.getWidth() / player * 0.05),
          (int) (frameSize.getHeight() - 50),
          (int) (frameSize.getWidth() / player * 0.9),
          25);
      player_pl.add(player_bt[i]);
      goal_pl.add(goal_bt[i]);
      player_bt[i].addActionListener(this);
      goal_bt[i].addActionListener(this);
    }

    while (true) {
      int i = (int) (Math.random() * 10);
      if (i < player) {
        goal_bt[i].setText("당첨");
        break;
      }
    }

    con.add(player_pl, "North");
    con.add(goal_pl, "South");

    draw = new Draw();
    con.add(draw, "Center");
    draw.init();
    initLadder();
    validate();
    repaint();

    // play = new Play(this, draw, frameSize,1);
    // play.start();
    //
    // play2 = new Play(this, draw, frameSize,5);
    // play2.start();
    play = new Play[player];

    addComponentListener(new ComponentResizedHdl());
  }