디시인사이드 갤러리

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

갤러리 본문 영역

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

초심자(211.211) 2011.12.19 10:52:22
조회 74 추천 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 - -
295252 출쵝! 오늘은 또 모하며 시간 때우냐 ㅋ 개심심(61.73) 11.12.21 42 0
295250 아 시발 좆 Adelposs갤로그로 이동합니다. 11.12.21 48 0
295249 곽노현팀장님, 앃넗늓핗몺얳였ㅊㅊ읋업맇엃닇 [7] Stan(220.244) 11.12.21 166 0
295248 아놔 하여튼 2만원 책사라.. 복근키보드갤로그로 이동합니다. 11.12.21 99 0
295245 페이스북 vs 구글 미국 취업 [3] (71.132) 11.12.21 191 0
295244 서버 시작하려면 어떻게 하남용? 책도 추천좀 부탁드리겠습니다 [1] hat갤로그로 이동합니다. 11.12.21 59 0
295241 .. 홈페이지 좀 만들라고 하는데 이게레알(112.151) 11.12.21 64 0
295240 횽들 C++ 하나만 물어볼께 ㅠㅠ [1] ㅇㅇ(124.50) 11.12.21 69 0
295239 난 회사 면접관이 뽑을 넘 없다는 말 정말 웃긴거 같애 [3] ...,(220.88) 11.12.21 213 0
295237 인서울 4년제 컴공졸 -> 6개월 아이티 학원 수료 학생 [3] 1010(58.145) 11.12.21 332 0
295236 형들아 티스토리 블로그 초대권좀 한장만 선물해주면 안되?ㅠㅠㅠ [5] 시그란♬갤로그로 이동합니다. 11.12.21 56 0
295235 형들 암호화 프로그램 만들었는데 앞으로 대화 이걸로할께요.swf [20] Stan(220.244) 11.12.20 216 0
295234 요기 재밌음 [1] 정수정•‿•갤로그로 이동합니다. 11.12.20 112 0
295233 횽들 여쭈어볼께 있는데 말입니다.... 부산시민(110.14) 11.12.20 50 0
295232 ★★★ 알고리즘 과제해주면 2만원 입금해줄께 ★★★ [13] 나를가져요(220.70) 11.12.20 206 0
295231 c++ 에서도 region 쓸수있구나..ㅋ [2] ㅋㄱ(183.96) 11.12.20 83 0
295229 모바일 면접후기 + 조언구걸 [3] 흐잌ㅋ(119.65) 11.12.20 322 0
295228 형들!! 데이터베이스 설계시 질문요!! 조공짤 투척!! [2] 콕찍(166.104) 11.12.20 141 0
295227 (수정)횽들아 이거대체 왜이런거야???ㅠㅠㅠ [3] 3(14.33) 11.12.20 97 0
295225 계절 책값,,,,-_- [3] ㅋㄱ(183.96) 11.12.20 90 0
295224 아 높고 높은 지식을 가지고 계신 컴돌이 분들이여 (은꼴) [4] 제발(211.186) 11.12.20 210 0
295222 성대아싸횽 소환 [13] 캐성대닭(115.92) 11.12.20 143 0
295221 써든어택 여고딩 랩 좀 쩌네 ㅋ [1] 캐서든닭(115.92) 11.12.20 100 0
295220 형들!! DB 설계에서 하나만 여쭤볼께 + (은꼴) [3] 콕찍(166.104) 11.12.20 182 0
295219 이거 건즈2 물리엔진인데 이런 수준 물리엔진 구현하기 힘듬? [1] 1(121.146) 11.12.20 122 0
295218 간단한 프로그램 만들려는데;;; SoLeaf(59.15) 11.12.20 62 0
295217 취미로 할수있는 프로그래밍 알려줄께 클릭해 취미생활(116.125) 11.12.20 82 0
295216 알고리즘 과제 해줌 2만원 입금해드림! [8] 나를가져요(220.70) 11.12.20 176 0
295215 아 내 취미가 프로그래밍 이었으면 좋겠다 [1] 1(121.146) 11.12.20 72 0
295214 그나저나 Mr. Doob 횽 데모중 GLSL Sandbox는 저도 만들려 [1] [성대아싸]갤로그로 이동합니다. 11.12.20 78 0
295211 분노의 파워코딩 2일차 , 작업내용 [1] [성대아싸]갤로그로 이동합니다. 11.12.20 152 0
295210 형님들 불쌍한 중생 한마리만 구제해주세요 ㅠㅠ [1] 간절소년(203.227) 11.12.20 107 0
295209 횽들 웹프로그래밍은 원래 좀 무시당하는 경향이라도 있어? [17] ㄷㄱ(118.37) 11.12.20 372 0
295208 아....슈ㅣ발...ㅋㅋㅋㅋㅋㅋㅋㅋㅋ 제기랄 [2] 캐시풋닭(115.92) 11.12.20 68 0
295207 프로그래머들아 야상좀 그만 입어 [1] 123(125.7) 11.12.20 112 0
295205 자바 게이들 보라 [11] 줫밥(122.49) 11.12.20 206 0
295204 캐꼬랑 쿄스케 소환 [1] 프갤했(115.90) 11.12.20 48 0
295203 게임 프로그래머가 되려면 뭐부터 시작해야 하나요..??;; [5] Otiel(121.157) 11.12.20 197 0
295202 근대 신입 초봉 4년제 나오면 왜 더 쳐주는거냐 [11] 줫밥(122.49) 11.12.20 263 0
295201 파견나오셨다가 복귀하신 분에게 대화걸었는데... [2] 9m(203.236) 11.12.20 94 0
295198 드림위버, php 질문요~ [15] ㅁㄴㅇㄹ(213.55) 11.12.20 175 0
295197 횽들 저물어볼께잇는데요 ㅜㅜ [7] 잉여잉간이양(116.40) 11.12.20 94 0
295196 기사 자격증 졸업 후에도 딸 수 있는거?? [5] 에이시아(203.90) 11.12.20 110 0
295195 야호 ! 서류 통과 됌 [2] 좋은아버지갤로그로 이동합니다. 11.12.20 163 0
295194 성님들 ㅠㅠ 정말 기초 하나만 질문할게요. [4] 가을월식(203.253) 11.12.20 61 0
295193 반지갑 살꺼임.. 어떤게 젤 캐간지임? [9] 이문동쮸쮸바갤로그로 이동합니다. 11.12.20 137 0
295192 soap통신 관련 질문합니다. [1] 버릇없다갤로그로 이동합니다. 11.12.20 130 0
295190 안드로이드하까 ios하까.. [4] 차도컴공남갤로그로 이동합니다. 11.12.20 118 0
295189 데이터베이스랑 서버 보안 배우려면 [4] ㅇㅇ(210.90) 11.12.20 103 0
295188 우리 회사 직원이 나 포함 2명이야.. 내년 목표는 [1] iljeomobolt갤로그로 이동합니다. 11.12.20 141 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2