디시인사이드 갤러리

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

갤러리 본문 영역

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

초심자(211.211) 2011.12.19 10:52:22
조회 76 추천 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 - -
295147 어제 셤에 나온 손코딩 문제 한마음택배(114.202) 11.12.20 66 0
295144 게임회사 들어가서 따로 인디게임 만들면 [3] bbbb(210.90) 11.12.20 135 0
295143 프갤로 과제물어보는 아가들 [10] Dawnwalkre갤로그로 이동합니다. 11.12.20 162 0
295141 고화질 바탕화면 좀 올려주라. [4] iljeomobolt갤로그로 이동합니다. 11.12.20 138 0
295140 한국에 웹개발하려면 어느 회사가 좋아? [8] Mihark(219.239) 11.12.20 188 0
295138 분노의 파워코딩 2일차 [5] [성대아싸]갤로그로 이동합니다. 11.12.20 182 0
295137 eclipse에서 갤럭시 노트는 세팅 어케 해야합니깡.. [11] 부끄곰갤로그로 이동합니다. 11.12.20 134 0
295136 재밌는 면접 후기 [6] 좋은아버지갤로그로 이동합니다. 11.12.20 271 0
295135 wagle로그인 저거 머냐 ㅋㅋ [1] !@#ㅇㅇ갤로그로 이동합니다. 11.12.20 54 0
295134 나의 내년 목표는 박찬호 보다 연봉을 1원이라도 더 받는걸로 정했어 [4] iljeomobolt갤로그로 이동합니다. 11.12.20 103 0
295132 프갤형님들.. C언어 개초본데요. 이거 힌트좀 주세요. [17] 살코춤(166.104) 11.12.20 164 0
295129 smarty에 대해 잘아시는분? [4] 니 코 가 뭐갤로그로 이동합니다. 11.12.20 62 0
295128 예전에 갑회사에 가서 프리젠테이션 했는데 [6] 3(121.169) 11.12.20 145 0
295127 회사에서 얼마만큼 일을 해야하냐? [3] ㄴㅇㄹ(125.7) 11.12.20 90 0
295125 프갤러 들에게 자격증이란 뭐냐? [6] ㄴㅇㄹ(125.7) 11.12.20 151 0
295124 이거 존나 사고 싶다............... [14] 캐노곤닭(115.92) 11.12.20 178 1
295122 아씨발 [1] 컴쏘갤로그로 이동합니다. 11.12.20 70 0
295121 혼자사는 프갤러들 아침밥 먹고 출근함? [3] ㄴㅇㄹ(125.7) 11.12.20 74 0
295120 보드 메모리 꼽는거 질문.. 2 [3] iljeomobolt갤로그로 이동합니다. 11.12.20 82 0
295119 노트북 사고 싶다 ㄴㅇㄹ(125.7) 11.12.20 44 0
295118 [급구]C만 써서 간단한거 하나 짜고, 계좌로 한장 쏴줄게 [1] 씨는개쁠(1.230) 11.12.20 106 0
295117 가가라이브 쌌다 입장바람 줫밥(122.49) 11.12.20 39 0
295116 to. 쿄스케 가가라이브 방 만들어줭 [1] 줫밥(122.49) 11.12.20 45 0
295115 아 진짜 발로텔리 존나 호감이야 ㅋㅋㅋㅋ [2] 쿄스케갤로그로 이동합니다. 11.12.20 70 0
295114 크리스마스에 할것도 없고 Dawnwalkre갤로그로 이동합니다. 11.12.20 56 0
295113 html5 공부하려면 선행으로 어떤것들 공부해야하나요? [1] 치킨맛맛폰갤로그로 이동합니다. 11.12.20 80 0
295112 컴 메모리를 늘리려고 하고 있어 질문좀.. [7] iljeomobolt갤로그로 이동합니다. 11.12.20 174 0
295107 어제 처음으로 회사에서 내 코드를 SVN에 올렸어 [2] +어게인갤로그로 이동합니다. 11.12.20 101 0
295106 (자바) setValue 감 좀 잡아주세요! [4] 케이갤로그로 이동합니다. 11.12.20 71 0
295105 이제 10분뒤면 준비를 하고 피티면접을 하러 가야 하는데 말이지 [5] 좋은아버지갤로그로 이동합니다. 11.12.20 214 0
295104 유릿패짤 원본... [1] 땡칠도사갤로그로 이동합니다. 11.12.20 100 0
295102 와 나 오늘 밤샛어 ㅋ 좋은아버지갤로그로 이동합니다. 11.12.20 72 0
295099 프갤님들 C언어 진짜 쉬운건데 해결좀 부탁드려요 [13] 도와주시계(116.123) 11.12.20 189 0
295098 하루가 24시간이었으면 좋겠다 ^_^ [1] ㅁㄴㄻㄹ갤로그로 이동합니다. 11.12.20 108 0
295096 power 프갤했(115.90) 11.12.20 24 0
295094 자살춤갤로그로 이동합니다. 11.12.20 143 1
295093 진짜 학교 재미없다... [3] 아....(178.217) 11.12.20 90 0
295092 이제 들어와지네??? [1] ㅋㄱ(183.96) 11.12.20 36 0
295091 안녕하세요 훃들 좁늅이가 질문하나 하려고 왔어요 [10] ☃-갤로그로 이동합니다. 11.12.19 116 0
295090 면접코딩은 손코딩임???? [2] ㅁㄴㅇㄹ(115.137) 11.12.19 197 0
295089 형들에게 작은 시계선물 하나할께 [5] 하얀사람갤로그로 이동합니다. 11.12.19 91 0
295088 크리스마스 때까지 분노의 코딩 1일차 [2] [성대아싸]갤로그로 이동합니다. 11.12.19 120 0
295087 지금 라디오 스타 김용만 김수용편 보는데 [2] 좋은아버지갤로그로 이동합니다. 11.12.19 98 0
295085 아오 쉬펄 여기 온지 2달째인데 단 하루도 야근이란 없다 [3] 개심심(121.140) 11.12.19 161 0
295084 형들 머해? [11] Stan(220.244) 11.12.19 126 0
295083 전테일의 공개장(여러가지 생각이 드네요) 흠흠흠(116.36) 11.12.19 57 0
295082 자바 과제 대행 구합니다 [1] 정글쥬스(1.210) 11.12.19 130 0
295081 회사에 보낼 ppt 다 만들었어. [5] 좋은아버지갤로그로 이동합니다. 11.12.19 120 0
295077 처음 파이썬 공부 할려고 하는데 책 어떤게 좋을까요?? [7] 파이선(175.116) 11.12.19 217 0
295076 위로 받고 싶은 형들에게... [1] Lover♥갤로그로 이동합니다. 11.12.19 56 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2