디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

안녕하세여 자바 과제중인데 해결이 안돼서 ㅜㅜ..

초심자(211.211) 2011.12.19 10:52:22
조회 88 추천 0 댓글 1

블락스케이프라고 비슷한거 만드는데요

막 박스 이동시켜서 노란거 탈출 시키는거거든여

박스끼리 서로 막 통과하고 난리났어요

이거 어떻게 해결할수있나여?

박스는 2d로그렸어여
클래스하나에 다때려넣엇거든요..

으으.. 박스끼리만 안겹치면 좋겠는데 어떻게 못하는건가요? 새로 다 다시짜야하나여?


 import java.awt.*;
 import javax.swing.*;
 import java.awt.event.*;
 import java.awt.image.BufferedImage;


 public class GameStart extends JPanel implements MouseListener,
    MouseMotionListener {
  Rectangle rect = new Rectangle(0, 0, 314, 314);
  Rectangle vbox1 = new Rectangle(2,54,100,50);
  Rectangle Tbox = new Rectangle(106,106,100,50);
  Rectangle vbox2 = new Rectangle(2,260,100,50);
  Rectangle vbox3 = new Rectangle(2,210,100,50); 
  Rectangle vbox4 = new Rectangle(158,2,100,50);
  Rectangle vbox5 = new Rectangle(158,262,150,50);
  Rectangle vbox6 = new Rectangle(2,2,150,50);
  Rectangle hbox1 = new Rectangle(106,158,50,150);
  Rectangle hbox2 = new Rectangle(158,158,50,100);
  Rectangle hbox3 = new Rectangle(262,2 ,50,150);

 
 
  BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB);  //이해안됨

  Graphics2D big;

  int v1x,  v2x,v3x,v4x,v5x,v6x;
  int tx;
  int h1y, h2y ,h3y;
  static boolean i = false;

 
  boolean firstTime = true;

  Rectangle area;

  boolean pressOut1 = false;
  boolean pressOut2 = false;
  boolean pressOut3 = false;
  boolean pressOut4 = false;
  boolean pressOut5 = false;
  boolean pressOut6 = false;
  boolean pressOut7 = false;
  boolean pressOut8 = false;
  boolean pressOut9 = false;
  boolean pressOut10 = false;
 

  public GameStart() {
    setBackground(Color.black);
    addMouseMotionListener(this);
    addMouseListener(this);
  }

 
  public void mousePressed(MouseEvent e) {

 v1x = vbox1.x - e.getX();
 v2x = vbox2.x - e.getX();
 v3x = vbox3.x - e.getX();
 v4x = vbox4.x - e.getX();
 v5x = vbox5.x - e.getX();
 v6x = vbox6.x - e.getX();
    tx = Tbox.x - e.getX();
    h1y = hbox1.y - e.getY();
    h2y = hbox2.y - e.getY();
    h3y = hbox3.y - e.getY();
   
  
    if (vbox1.contains(e.getX(), e.getY())) {
      updateLocation2(e);
    } else {
     pressOut1 = true;
    }
    if (vbox2.contains(e.getX(), e.getY())) {
        updateLocation3(e);
      } else {
       pressOut3 = true;
      }
    if (vbox3.contains(e.getX(), e.getY())) {
        updateLocation4(e);
      } else {
       pressOut4 = true;
      }
    if (vbox4.contains(e.getX(), e.getY())) {
        updateLocation5(e);
      } else {
       pressOut5 = true;
      }
    if (vbox5.contains(e.getX(), e.getY())) {
        updateLocation6(e);
      } else {
       pressOut6 = true;
      }
    if (vbox6.contains(e.getX(), e.getY())) {
        updateLocation7(e);
      } else {
       pressOut7 = true;
      }
    if (hbox1.contains(e.getX(), e.getY())) {
        updateLocation1(e);
      } else {
        pressOut10 = true;
      }
    if (hbox2.contains(e.getX(), e.getY())) {
        updateLocation8(e);
      } else {
        pressOut8 = true;
      }
    if (hbox3.contains(e.getX(), e.getY())) {
        updateLocation8(e);
      } else {
        pressOut9 = true;
      }
    if (Tbox.contains(e.getX(), e.getY())) {
        updateLocation(e);
      } else {
        pressOut2 = true;
      }
  }
 
  public void mouseDragged(MouseEvent e) {

    if (!pressOut1) {
      updateLocation2(e);
    }
    if (!pressOut3) {
        updateLocation3(e);
      }
    if (!pressOut4) {
        updateLocation4(e);
      }
    if (!pressOut5) {
        updateLocation5(e);
      }
    if (!pressOut6) {
        updateLocation6(e);
      }
    if (!pressOut7) {
        updateLocation7(e);
      }
    if (!pressOut8) {
        updateLocation8(e);
      }
    if (!pressOut9) {
        updateLocation9(e);
      }
    if (!pressOut10) {
        updateLocation1(e);
      }
   
    if (!pressOut2) {
      updateLocation(e);
      }
  }

 
  public void mouseReleased(MouseEvent e) {
    if (vbox1.contains(e.getX(), e.getY())) {
      updateLocation2(e);
    }
    else if (Tbox.contains(e.getX(), e.getY())) {
        updateLocation(e);
      }
    else if (vbox2.contains(e.getX(), e.getY())) {
        updateLocation3(e);
      }
    else if (vbox3.contains(e.getX(), e.getY())) {
        updateLocation4(e);
      }
    else if (vbox4.contains(e.getX(), e.getY())) {
        updateLocation5(e);
      }
    else if (vbox5.contains(e.getX(), e.getY())) {
        updateLocation6(e);
      }
    else if (vbox6.contains(e.getX(), e.getY())) {
        updateLocation7(e);
      }
    else if (hbox1.contains(e.getX(), e.getY())) {
        updateLocation1(e);
      }
    else if (hbox2.contains(e.getX(), e.getY())) {
        updateLocation8(e);
      }
    else if (hbox3.contains(e.getX(), e.getY())) {
        updateLocation9(e);
      }
   
  }

  public void mouseMoved(MouseEvent e) {
    pressOut1 = false;
     pressOut2 = false;
     pressOut3 = false;
     pressOut4 = false;
     pressOut5 = false;
     pressOut6 = false;
     pressOut7 = false;
     pressOut8 = false;
     pressOut9 = false;
     pressOut10 = false;
  }

  public void mouseClicked(MouseEvent e) {
  }

  public void mouseExited(MouseEvent e) {
 
  }

  public void mouseEntered(MouseEvent e) {
 
  }
 
  public void updateLocation1(MouseEvent e) {

    hbox1.setLocation(hbox1.x , h1y + e.getY());
    repaint();
  }
  public void updateLocation8(MouseEvent e) {

     hbox2.setLocation(hbox2.x , h2y + e.getY());
     repaint();
   }
  public void updateLocation9(MouseEvent e) {

     hbox3.setLocation(hbox3.x , h3y + e.getY());
     repaint();
   }
  public void updateLocation(MouseEvent e) {

     Tbox.setLocation(tx + e.getX(), Tbox.y) ;
     if( Tbox.x > 260)
      i = true;
     repaint();
   
   }

  public void updateLocation2(MouseEvent e) {

     vbox1.setLocation(v1x + e.getX()  , vbox1.y) ;
     repaint();
   }
  public void updateLocation3(MouseEvent e) {

     vbox2.setLocation(v2x + e.getX()  , vbox2.y) ;
     repaint();
   }
  public void updateLocation4(MouseEvent e) {

     vbox3.setLocation(v3x + e.getX()  , vbox3.y) ;
     repaint();
   }
  public void updateLocation5(MouseEvent e) {

     vbox4.setLocation(v4x + e.getX()  , vbox4.y) ;
     repaint();
   }
  public void updateLocation6(MouseEvent e) {

     vbox5.setLocation(v5x + e.getX()  , vbox5.y) ;
     repaint();
   }
  public void updateLocation7(MouseEvent e) {

     vbox6.setLocation(v6x + e.getX()  , vbox6.y) ;
     repaint();
   }
 
 

  public void paint(Graphics g) {
    update(g);
  
  }

  public void update(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    if (firstTime) {
     int x= 15; int y=10;
      Dimension dim = getSize();
      int w = dim.width;
      int h = dim.height;
      area = new Rectangle(dim);
      bi = (BufferedImage) createImage(w, h);
      big = bi.createGraphics();
      rect.setLocation(x, y);
      vbox1.setLocation(x+2, y+54);
      vbox2.setLocation(x+2, y+262);
      vbox3.setLocation(x+2, y+210);
      vbox4.setLocation(x+158, y+2);
      vbox5.setLocation(x+158, y+262);
      vbox6.setLocation(x+2, y+2);
      hbox1.setLocation(x+106, y+158);
      hbox2.setLocation(x+158, y+158);
      hbox3.setLocation(x+262, y+2);
      Tbox.setLocation(x+106, y+106);
      big.setStroke(new BasicStroke(8.0f));
      firstTime = false;
    }

    big.setColor(Color.black);
    big.clearRect(0, 0, area.width, area.height);

    big.setPaint(Color.white);
    big.draw(rect);
    big.setPaint(Color.gray);
    big.fill(rect);

    big.setPaint(Color.blue);
    big.fill(vbox1);
    big.setPaint(Color.blue);
    big.fill(vbox2);
    big.setPaint(Color.blue);
    big.fill(vbox3);
    big.setPaint(Color.blue);
    big.fill(vbox4);
    big.setPaint(Color.blue);
    big.fill(vbox5);
    big.setPaint(Color.blue);
    big.fill(vbox6);
    big.setPaint(Color.blue);
    big.fill(hbox1);
    big.setPaint(Color.blue);
    big.fill(hbox2);
    big.setPaint(Color.blue);
    big.fill(hbox3);
    big.setPaint(Color.yellow);
    big.fill(Tbox);
   
    g2.drawImage(bi, 0, 0, this);
  }

  public static void main(String s[]) {

    JFrame f = new JFrame("BoxEscape");
    JLabel label;
    f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });
    f.getContentPane().setLayout(new BorderLayout());
    f.getContentPane().add(new GameStart(), "Center");
  
   
    label = new JLabel("Gaming");
    f.getContentPane().add(BorderLayout.SOUTH, label);
   
    if( i == true ){
   
    label.setText("Clear!");
     
    }
    f.pack();
    f.setSize(new Dimension(400, 400));
    f.show();
  }

}

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 이성 보는 눈 없어서 걱정되는 스타는? 운영자 25/11/10 - -
AD 저녁 뭐먹지? 오늘의 메뉴 추천! 운영자 25/10/31 - -
295754 방학을 이용해 보충겸 학원을 2달 다니려고 하는데 추천좀.. [7] ㅇㅇ(125.178) 11.12.23 142 0
295753 형들은 왜,, [3] ㅌㄹㄷㄹ(175.114) 11.12.23 72 0
295750 짐 지하철방송에서 대설주의보? 쿄스케갤로그로 이동합니다. 11.12.23 62 0
295749 야요이 너 새끼 PoRO갤로그로 이동합니다. 11.12.23 33 0
295748 크리스마스 분위기 안난다 ; v ; PoRO갤로그로 이동합니다. 11.12.23 48 0
295747 외국 IT 회사 평균 퇴근 시간 언제임 ?? [2] 야요이갤로그로 이동합니다. 11.12.23 201 0
295746 어쩌다 크리스마스가 섹스 데이가 되었냐... [1] 야요이갤로그로 이동합니다. 11.12.23 166 0
295745 정전인가... 7분전.. [1] 헝그리박갤로그로 이동합니다. 11.12.23 72 0
295744 오오미 크리스마스 때가 되니까 일복 포텐이 터지네 3(121.169) 11.12.23 55 0
295743 퇴근합시다 ! [2] C_Perl갤로그로 이동합니다. 11.12.23 53 0
295742 dicom은 어디서 물어봐야 될까요? 초보(222.100) 11.12.23 62 0
295741 방금 헬겔에 올라온짤.. ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ 19금 [1] 헝그리박갤로그로 이동합니다. 11.12.23 177 0
295740 이 만화봤음 다들? [2] McHello갤로그로 이동합니다. 11.12.23 159 0
295739 줫밥님 제가 닉지적해서 닉바꿧나옄ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ [5] ㅁㄴㅇㄹ(115.137) 11.12.23 79 0
295737 백왕개샠키 [4] 헝그리박갤로그로 이동합니다. 11.12.23 88 0
295736 쿼리의 고수가 되고 싶소 [3] (112.223) 11.12.23 96 0
295735 ㅇㅋ 헝그리박갤로그로 이동합니다. 11.12.23 20 0
295734 줫밥 = 나 닉변함 [1] 헝그리박(122.49) 11.12.23 48 0
295733 프갤 챗방은업나요? 데헷(119.82) 11.12.23 37 0
295732 오늘 11시 40분에 온 우리 신입 퇴근 준비한다 [5] 123(125.7) 11.12.23 156 0
295729 살빼려고 약샀어 [1] 헝그리박(122.49) 11.12.23 73 0
295727 C++ 책 추천좀 [3] 아그브어갤로그로 이동합니다. 11.12.23 175 0
295725 곽노현팀장 elwlwlwk갤로그로 이동합니다. 11.12.23 90 0
295723 늬들아 씨벌 오늘 분위기 왜이러니 ㅇ.ㅇ?? 뽀로 조금 무서워진다. [9] PoRO갤로그로 이동합니다. 11.12.23 107 0
295722 역시 예상대로 중학생놈들 "장난삼아" 했다고 변명하네..... [9] 야요이갤로그로 이동합니다. 11.12.23 220 0
295718 모임? 모임? 왜 오늘 프겔 파이팅 분위기임? ㅇvㅇ??? [2] PoRO갤로그로 이동합니다. 11.12.23 95 0
295714 흔한 퇴사 결정후 주변반응 [3] 므해?갤로그로 이동합니다. 11.12.23 192 0
295712 나 크리스마스 선물받았다 ㅋㅋㅋㅋ ㅇvㅇ 히히히히 [11] PoRO갤로그로 이동합니다. 11.12.23 98 0
295710 분노의 파워코딩 5일차, 작업내용 [2] [성대아싸]갤로그로 이동합니다. 11.12.23 131 0
295706 1월 7일날 비트 자바 교육들을껀데 [1] 헝그리박갤로그로 이동합니다. 11.12.23 138 0
295705 곽노현팀장 저새기는 누굴 못먹어서 안달이냐 [1] elwlwlwk갤로그로 이동합니다. 11.12.23 106 0
295704 자바 실무경험자들에게 질문.. [12] 므해?갤로그로 이동합니다. 11.12.23 187 0
295701 性탄절 [5] iljeomobolt갤로그로 이동합니다. 11.12.23 165 0
295696 100키로이상만 보셈 [2] 줫밥(122.49) 11.12.23 101 0
295694 자바스크립트 쓰다가 갑자기 급궁금증? [1] 개심심(61.73) 11.12.23 121 0
295692 근데 너네 군대는 갔다왔냐? [2] ㅊㄹ(222.112) 11.12.23 82 0
295690 내가 현실보단 이상주의자라서 그런걸까.... [1] 야요이갤로그로 이동합니다. 11.12.23 66 0
295689 서블릿이 웹서버 같은건가요??? 뭐하는 것인지 모르겠어요 ㅠㅠ [1] 외국인(182.211) 11.12.23 89 0
295688 오픈지엘 ES 2.0 좀 아는 횽 있나여? [2] opengl(115.95) 11.12.23 107 0
295686 충++ [1] 천회장(14.52) 11.12.23 78 0
295684 곽 여기 왜오는거임 줫밥(122.49) 11.12.23 56 0
295681 오오미 팀장님 왕따시키는거 보니 프갤벌레들 수준이 뉴스 나올감이네 [2] 곽노현차장(59.13) 11.12.23 124 1
295679 to. ㅡㅡ [1] 줫밥(122.49) 11.12.23 51 0
295678 즷밥님아 ㅡㅡ [1] ㅡㅡ(175.198) 11.12.23 65 0
295677 설마 오늘도 야근하는 횽들은 없겠지??? 거칠게갤로그로 이동합니다. 11.12.23 63 0
295675 이번 대구 중학생 사건 가해자 신상 슬슬 나오던데 [1] 123(125.7) 11.12.23 478 5
295674 SI,솔루션 그 외엔 뭐 임 ?? [6] 야요이갤로그로 이동합니다. 11.12.23 128 0
295673 곽노현팀장 [3] 퓨리님(111.91) 11.12.23 88 0
295672 퇴근 까지 3시간! 직딩들아 지금 뭐하는지 써보랑께 잠깐 휴식하자 [4] ㅊㄹ(222.112) 11.12.23 72 0
295671 횽들 나 파이썬 책 하나만 추천해죠(개왕왕왕왕초보) 꽥꽥꾸르릉꿍갤로그로 이동합니다. 11.12.23 302 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2