디시인사이드 갤러리

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

갤러리 본문 영역

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

초심자(211.211) 2011.12.19 10:52:22
조회 81 추천 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/03 - -
AD 저녁 뭐먹지? 오늘의 메뉴 추천! 운영자 25/10/31 - -
294980 to. 쿄스케 [3] 줫밥(122.49) 11.12.19 54 0
294979 내 머리가 나빠서..아이디어 좀 주세요.. [2] 케이갤로그로 이동합니다. 11.12.19 90 0
294977 전문대에서숭실대 컴쏘갤로그로 이동합니다. 11.12.19 97 0
294976 이번달 프로젝트만 끝나면 드디어 여름휴가간다 junon갤로그로 이동합니다. 11.12.19 37 0
294974 아 줫밥인데 금요일날 갤탭 잊어버림.. [2] 헝그리박갤로그로 이동합니다. 11.12.19 93 0
294973 대학교 [1] 컴쏘갤로그로 이동합니다. 11.12.19 56 0
294971 수학이딸리면어캄 [1] 컴쏘갤로그로 이동합니다. 11.12.19 92 0
294970 월요일이다,,, [1] 나우 로딩갤로그로 이동합니다. 11.12.19 42 1
294969 내일이 두렵다. ㅋㅋ [3] 좋은아버지갤로그로 이동합니다. 11.12.19 73 0
294968 형들, 쉐이더 언어라고 따로 존재하는거야? [21] Aven갤로그로 이동합니다. 11.12.19 202 0
294967 이거 한번 봐주세요~쓰래드!!!ㅠㅠㅠㅠㅠ [1] 뵤뵤구(221.163) 11.12.19 72 0
294966 그럼 어떤식으로 해야지 입력받는식으로 할수있을까요? [2] 1234(218.237) 11.12.19 68 0
294965 다시 질문 드립니다 [5] 1234(218.237) 11.12.19 79 0
294964 아 시발 진로 존나 잘못잡은거냐? [2] 뿡뿡뿡뿡(39.112) 11.12.19 109 0
294963 웹게임에서 소스 추출하려는데 [12] 나무아비(114.200) 11.12.19 699 0
294962 c언어 질문 [5] 1234(218.237) 11.12.19 90 0
294961 파트타임 학원 강사 하기 힘듬? 급질(221.147) 11.12.19 113 0
294959 가장 생각나는 허무한 삽질이 뭐였어? [1] ㅌㄹ(59.26) 11.12.19 94 0
294958 소프트웨어 테스팅 프로그램은 어떻게 테스팅 하는거야? [1] 해물(14.51) 11.12.19 61 0
294957 지금 누구 계신가요? html 질문인데; [1] 홈페이징(122.40) 11.12.19 80 0
294956 Java , JSP 질문 좀 받아줘 형들 [3] `-'갤로그로 이동합니다. 11.12.19 67 0
294955 스타1 mpq를 풀어봤는데 [2] DevilCruiser갤로그로 이동합니다. 11.12.19 110 0
294954 자소서를 엄청 오래쓰고 나서 읽어봤는데 ㅠㅠ [1] ㅁㄴㅇㄹ(115.137) 11.12.18 99 0
294953 DB SQL명령어 질문 [3] income갤로그로 이동합니다. 11.12.18 135 0
294952 MFC 질문 [4] 토끼나븨(118.221) 11.12.18 72 0
294951 이바닥 정년 솔직히 몇으로 보냐? [4] ㅇㅇ(112.148) 11.12.18 185 0
294949 스타1이나 2깔려있는횽들 [6] DevilCruiser갤로그로 이동합니다. 11.12.18 84 0
294948 횽들 c언어 공부하는데 모르는거좀 물어볼게 [5] 123(219.249) 11.12.18 100 0
294947 요즘 MFC 배우고 있는데, 실제 실무에서 가장 많이 쓰는 건 뭔가요? [2] 까꼬이(121.174) 11.12.18 110 0
294946 밑에 포인터 물어봤었는데.. [1] 형들(221.155) 11.12.18 61 0
294945 프로그래머 만큼 안정적인 직업도 없는 것 같다.jpg [2] ㅇㅇ(121.133) 11.12.18 216 0
294944 형들 *p++ *(p++)랑 같은거임? [2] 형들(221.155) 11.12.18 95 0
294943 오빠들 자바 getRemoteAddr() 왜 ipv6로 가져올까요? [2] 자바(211.187) 11.12.18 146 1
294942 학교에서 교수가 여자라서 짱 좋음 [4] ㅇㅇ(121.133) 11.12.18 196 1
294941 혹시 너무 무료하고 심심해서 mfc 한번 mfc 우앙ㅠ(221.163) 11.12.18 52 0
294940 이런 병신같은 인사담당자 들 왜이렇게 많냐?? [1] 이메지네이션(114.205) 11.12.18 98 0
294939 나의 퇴사 썰. [1] 이런개새끼갤로그로 이동합니다. 11.12.18 120 0
294938 모 일케 갈켜주는 사람이 읍냐ㅇㅇ C 공부좀 할래면 어떠카냐고 묻는데 [4] 미케닠갤로그로 이동합니다. 11.12.18 103 0
294937 어떤 os가 가장 전망성 높을까 [1] 전망(115.41) 11.12.18 98 0
294936 html 질문좀.. 1111(124.195) 11.12.18 41 0
294935 형들 이거쉬운건데 제발알려주세요 ㅠㅠㅠㅠㅠ [1] ㄴㅇㄹㄴㅇ(125.129) 11.12.18 55 0
294934 내가 봤을 때 물어보는 놈들은 존나게 맞아야 한다. [1] ㅇㅇ(61.43) 11.12.18 98 0
294933 프로그램좀 짜주세요. 급함 ㅠ 사례함 [7] 라면사리(110.14) 11.12.18 152 0
294932 일본 스마트폰 개발자 '몸값=금값' [5] ㅁㄴㅇㄹ(14.42) 11.12.18 225 0
294931 프통령하고 스터디 하구 왔심 [3] 9m(58.140) 11.12.18 87 0
294929 InputStream 과 BufferedReader [6] 케이갤로그로 이동합니다. 11.12.18 79 0
294928 면접볼때 주량이랑 여친있냐고 물어보던데 [8] 123(211.48) 11.12.18 235 0
294927 횽들 전자공학 1학년인데 C언어 공부좀 해보려고하는데 어케해야됨? 학원다 미케닠갤로그로 이동합니다. 11.12.18 65 0
294926 형들 이 사이트 알아? 임베디드쪽 무료강의해주는곳인데 [2] ㅇㅇ(112.148) 11.12.18 130 0
294925 엄청 간단한 html인데 해결좀 도와주세요 ㅠ [3] 홈페이징(122.40) 11.12.18 80 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2