디시인사이드 갤러리

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

갤러리 본문 영역

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

초심자(211.211) 2011.12.19 10:52:22
조회 78 추천 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
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 영포티룩도 멋지게 소화할 것 같은 40대 스타는? 운영자 25/10/27 - -
AD 저녁 뭐먹지? 오늘의 메뉴 추천! 운영자 25/10/31 - -
295293 ORM 정확한 약자가 뭘까? [13] 캐ORM닭(115.92) 11.12.21 190 0
295292 sc가 뭐죠? [9] 1(183.104) 11.12.21 99 0
295291 성대아싸님 [3] 질문(61.75) 11.12.21 79 0
295289 프리렌서 프로그램 개발 실력자 찾습니다 [26] PRESA갤로그로 이동합니다. 11.12.21 214 0
295286 점심처먹다 ㅇㅇ갤로그로 이동합니다. 11.12.21 38 0
295283 pc방 키보드 너무 구려 iljeomobolt갤로그로 이동합니다. 11.12.21 86 0
295282 옆에앉은 여자들 둘이 담배 장난 아니다. iljeomobolt갤로그로 이동합니다. 11.12.21 118 0
295280 부산까지 와서 pc 방이라니 ㅋㅋㅋ iljeomobolt갤로그로 이동합니다. 11.12.21 66 0
295279 레드 블랙 트리 어디 설명 잘 되있는 곳 없나요? [3] (218.209) 11.12.21 105 0
295278 형들 모델심 락건거있잖아?? 그거 푸는방법 혹시아는사람?? 토끼(110.13) 11.12.21 49 0
295277 생성자 왜 쓰는건지 개념좀 가르쳐 주셈 [5] 11(118.220) 11.12.21 126 0
295274 야호 내 최초 ios프로젝트가 리젝됨ㅋ !@#ㅇㅇ갤로그로 이동합니다. 11.12.21 75 0
295273 비주얼스튜디오 한글판으로 재설치할려면.. [1] 해피너스갤로그로 이동합니다. 11.12.21 64 0
295272 조금 있으면 뭔날인줄 아시는지? Lover♥갤로그로 이동합니다. 11.12.21 54 0
295269 고수형들아 디코더좀 만들어줄래?? 토끼(110.13) 11.12.21 135 0
295267 내년에 좆문대 컴퓨터정보과가는데 [5] 도와줘(121.165) 11.12.21 148 0
295266 오빠들 스트리밍이 뭔대?ㅠ [8] 히흫양(121.160) 11.12.21 149 0
295265 횽들 내가 고민이 있는데 상담좀 해줘 [9] Mihark(219.239) 11.12.21 90 0
295264 슬프다 진짜 월급 빼고 다오른다 [7] 41(125.7) 11.12.21 141 0
295263 아놔 웃겨죽겠네 ㅋㅋㅋ 초딩6(59.13) 11.12.21 55 0
295262 요즘 애들 다이러냐? [13] 41(125.7) 11.12.21 176 0
295261 npa 파일 압축 질문입니다 [1] 지니레카갤로그로 이동합니다. 11.12.21 91 0
295260 지금 KTX 301Km 로 달리는중 노트북으로 iljeomobolt갤로그로 이동합니다. 11.12.21 85 0
295259 스턴이 한 플그램 아는사람 나좀 갈켜줘봐 줫밥(122.49) 11.12.21 48 0
295257 비주얼C++ 쓸때 국가언어 뭘로 써? [3] 해피너스갤로그로 이동합니다. 11.12.21 83 0
295256 htaccess rewrite 질문점.. 늘모갤로그로 이동합니다. 11.12.21 44 0
295255 발전소에서 일하는 친구가 부럽다 [4] 3(121.169) 11.12.21 168 0
295252 출쵝! 오늘은 또 모하며 시간 때우냐 ㅋ 개심심(61.73) 11.12.21 44 0
295250 아 시발 좆 Adelposs갤로그로 이동합니다. 11.12.21 50 0
295249 곽노현팀장님, 앃넗늓핗몺얳였ㅊㅊ읋업맇엃닇 [7] Stan(220.244) 11.12.21 168 0
295248 아놔 하여튼 2만원 책사라.. 복근키보드갤로그로 이동합니다. 11.12.21 102 0
295245 페이스북 vs 구글 미국 취업 [3] (71.132) 11.12.21 194 0
295244 서버 시작하려면 어떻게 하남용? 책도 추천좀 부탁드리겠습니다 [1] hat갤로그로 이동합니다. 11.12.21 64 0
295241 .. 홈페이지 좀 만들라고 하는데 이게레알(112.151) 11.12.21 67 0
295240 횽들 C++ 하나만 물어볼께 ㅠㅠ [1] ㅇㅇ(124.50) 11.12.21 70 0
295239 난 회사 면접관이 뽑을 넘 없다는 말 정말 웃긴거 같애 [3] ...,(220.88) 11.12.21 214 0
295237 인서울 4년제 컴공졸 -> 6개월 아이티 학원 수료 학생 [3] 1010(58.145) 11.12.21 333 0
295236 형들아 티스토리 블로그 초대권좀 한장만 선물해주면 안되?ㅠㅠㅠ [5] 시그란♬갤로그로 이동합니다. 11.12.21 57 0
295235 형들 암호화 프로그램 만들었는데 앞으로 대화 이걸로할께요.swf [20] Stan(220.244) 11.12.20 219 0
295234 요기 재밌음 [1] 정수정•‿•갤로그로 이동합니다. 11.12.20 113 0
295233 횽들 여쭈어볼께 있는데 말입니다.... 부산시민(110.14) 11.12.20 52 0
295232 ★★★ 알고리즘 과제해주면 2만원 입금해줄께 ★★★ [13] 나를가져요(220.70) 11.12.20 206 0
295231 c++ 에서도 region 쓸수있구나..ㅋ [2] ㅋㄱ(183.96) 11.12.20 85 0
295229 모바일 면접후기 + 조언구걸 [3] 흐잌ㅋ(119.65) 11.12.20 322 0
295228 형들!! 데이터베이스 설계시 질문요!! 조공짤 투척!! [2] 콕찍(166.104) 11.12.20 144 0
295227 (수정)횽들아 이거대체 왜이런거야???ㅠㅠㅠ [3] 3(14.33) 11.12.20 97 0
295225 계절 책값,,,,-_- [3] ㅋㄱ(183.96) 11.12.20 91 0
295224 아 높고 높은 지식을 가지고 계신 컴돌이 분들이여 (은꼴) [4] 제발(211.186) 11.12.20 210 0
295222 성대아싸횽 소환 [13] 캐성대닭(115.92) 11.12.20 145 0
295221 써든어택 여고딩 랩 좀 쩌네 ㅋ [1] 캐서든닭(115.92) 11.12.20 102 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2