디시인사이드 갤러리

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

갤러리 본문 영역

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

초심자(211.211) 2011.12.19 10:52:22
조회 73 추천 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/23 - -
295053 조는거 딴짓하는거에 머 그리 예민하게 구는지 모르겠다...? [3] ㅅㄱㅅㄱㅅㄱ갤로그로 이동합니다. 11.12.19 81 0
295052 오늘 평소랑 좀 다르게 출근했는데 [1] McHello갤로그로 이동합니다. 11.12.19 83 0
295051 미국에서 [5] 컴쏘갤로그로 이동합니다. 11.12.19 89 0
295047 자바 코드 좀 봤는데 어렵네;; [7] 줫밥(122.49) 11.12.19 123 0
295046 난 목표가 연봉 5000인데 [3] ㅇㅇ(125.182) 11.12.19 195 0
295045 공부 할게 산더미인데 김정일 죽어서 일하기 싫다 [1] 개심심(61.73) 11.12.19 77 0
295044 C언어에서는 디폴트 매개변수 어떻게 쓰나요; [3] 치킨맛맛폰갤로그로 이동합니다. 11.12.19 97 0
295043 카톡 닉네임 김센스 게이있냐? 줫밥(122.49) 11.12.19 53 0
295039 어깨가 아프고... [2] 9m(203.236) 11.12.19 45 0
295035 연봉 얼마 받고 싶냐. [7] ㅂㅎㅅ(124.35) 11.12.19 157 0
295034 환급 100만원 이야? [1] 신입사원갤로그로 이동합니다. 11.12.19 58 0
295032 to. 케닭 [11] 줫밥(122.49) 11.12.19 155 0
295031 레알 OpenGL 아는 횽 하나도 업음?? [2] 신입사원갤로그로 이동합니다. 11.12.19 90 0
295030 야 이거좀 갈켜줘 [25] 줫밥(122.49) 11.12.19 180 0
295029 소스입니다. [1] 대한민국코더갤로그로 이동합니다. 11.12.19 54 0
295028 선배님들 질문있습니다. [1] 대한민국코더갤로그로 이동합니다. 11.12.19 75 0
295026 대한민국코더 인사드립니다. [1] 대한민국코더갤로그로 이동합니다. 11.12.19 61 0
295024 주식 박살났다 ㅋㅋㅋ 김정일 시발년 뒤져도 씨발년 살아도 씨발년 [2] 개심심(61.73) 11.12.19 121 0
295023 양재동쪽에 스포츠 가르쳐주는 곳 없나? 배드민턴이라던지 뭐든지.. [5] 초딩6(59.13) 11.12.19 301 3
295022 입사한 이후로 공휴일이 없다 3(121.169) 11.12.19 54 0
295021 김정일 죽었는데 [1] Adelposs갤로그로 이동합니다. 11.12.19 89 0
295018 안드로이드 면접 질문 구걸좀용 ^^; [13] 흐잌ㅋ(119.65) 11.12.19 612 0
295015 이번주 정모하자 [2] 줫밥(122.49) 11.12.19 87 0
295012 윈도우 xp 발매전 마소 직원의 대담함.jpg Stan(220.244) 11.12.19 169 0
295011 유용한 글이니 잘 읽어보고 GC를 쓰도록 하자 [1] 퓨리님(111.91) 11.12.19 70 0
295010 손들어!! 움직이지마 그리고 가진돈 다내놔!.jpg Stan(220.244) 11.12.19 56 0
295009 횽아들.올만이내요 저ㅜ내일임대합니다 [5] 푸른명월갤로그로 이동합니다. 11.12.19 60 1
295008 아까 질문했던 사람인데염 초보자(211.211) 11.12.19 31 0
295007 똒똒똒!~!! 계세요? 똑똒! [2] Stan(220.244) 11.12.19 48 0
295006 흔한 웹디자이너.jpg Stan(220.244) 11.12.19 128 0
295003 가장 훌륭한 디버거는 [1] 천회장(14.52) 11.12.19 72 0
295000 살이 찌긴 존나 많이 쪘네 [1] 줫밥(122.49) 11.12.19 76 0
294995 이산수학 공부하려는데 책 추천좀 해줘요 [4] ㅁㄴㅇ(119.201) 11.12.19 165 0
294994 내일 말해야하는데 그만둬야 한다고..근데 타이밍이 안 좋다.. [4] 므해?갤로그로 이동합니다. 11.12.19 95 0
294993 키위다! [3] 9m(203.236) 11.12.19 67 0
294992 찾았다!!!!!!!!!!! [3] 줫밥(122.49) 11.12.19 66 0
안녕하세여 자바 과제중인데 해결이 안돼서 ㅜㅜ.. [1] 초심자(211.211) 11.12.19 73 0
294989 . _ . 할게 없음 [4] 9m(203.236) 11.12.19 70 0
294988 dk tnlㄴㄹ흐ㅏㄴㄹ아ㅡㅇㄴ라ㅡ 슈발!!!!!!!!!!!!!!!!!!! [3] 줫밥(122.49) 11.12.19 60 0
294986 코딩중 오타의심이 판단되면 비프음이 울리는 에디터 [6] ㅂㅈㄷ(210.178) 11.12.19 131 0
294985 인턴은 원래 빡세게 시킴? [12] Mihark(219.239) 11.12.19 197 1
294983 웹 접근성 프로젝트 해본사람???? [8] 개심심(61.73) 11.12.19 98 1
294982 첫출근을 했는데 [8] ㅇㅇㅋ(121.140) 11.12.19 104 1
294981 횽들 질문 하나만 할께 인턴갤로그로 이동합니다. 11.12.19 40 0
294980 to. 쿄스케 [3] 줫밥(122.49) 11.12.19 48 0
294979 내 머리가 나빠서..아이디어 좀 주세요.. [2] 케이갤로그로 이동합니다. 11.12.19 85 0
294977 전문대에서숭실대 컴쏘갤로그로 이동합니다. 11.12.19 90 0
294976 이번달 프로젝트만 끝나면 드디어 여름휴가간다 junon갤로그로 이동합니다. 11.12.19 32 0
294974 아 줫밥인데 금요일날 갤탭 잊어버림.. [2] 헝그리박갤로그로 이동합니다. 11.12.19 87 0
294973 대학교 [1] 컴쏘갤로그로 이동합니다. 11.12.19 51 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2