디시인사이드 갤러리

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

갤러리 본문 영역

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

초심자(211.211) 2011.12.19 10:52:22
조회 93 추천 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/17 - -
AD 대학생 필수템! What's in my Bag 운영자 25/11/21 - -
295188 우리 회사 직원이 나 포함 2명이야.. 내년 목표는 [1] iljeomobolt갤로그로 이동합니다. 11.12.20 163 0
295187 운동이나 할까나 [4] 이문동쮸쮸바갤로그로 이동합니다. 11.12.20 134 0
295186 인사하는것도 일인듯 9m(203.236) 11.12.20 64 0
295185 mybatis 거참 희안하다..커넥션 타임아웃...현상 겪으신분? [5] 캐자바닭(115.92) 11.12.20 157 0
295184 애용하는 키보드 [4] ㄱㄷㅈ(210.178) 11.12.20 154 0
295183 듀얼코어 노트북 + ssd [3] 123(125.7) 11.12.20 145 0
295182 이거 정확한 이유가 뭔지 아는횽 [11] McHello갤로그로 이동합니다. 11.12.20 209 0
295180 신입때 면접을 본적이있었는데.. [3] .3(36.38) 11.12.20 210 0
295179 헐 뻘끌쌋더니 삭제되네 [1] 지스(121.177) 11.12.20 61 0
295178 투. 줫밥 [1] 개심심(61.73) 11.12.20 70 0
295177 취업한지 반년이 지난 시점 [2] 미역c갤로그로 이동합니다. 11.12.20 170 0
295175 온라인 게임은 말야.... [1] 프갤했(115.90) 11.12.20 90 0
295174 학교로 면접관이 왔는데.. [2] 부끄곰갤로그로 이동합니다. 11.12.20 114 0
295173 아! 내가 면접 본다! [2] 부끄곰갤로그로 이동합니다. 11.12.20 106 0
295172 어디좋은사이트없나? [5] ㅇㅇ갤로그로 이동합니다. 11.12.20 97 0
295171 와 춥다 [1] 9m(203.236) 11.12.20 53 0
295169 asp.net 좀 할줄 아는 사람? Mihark(219.239) 11.12.20 63 0
295168 프로그래밍 [2] ㅇㅇ갤로그로 이동합니다. 11.12.20 78 0
295167 이번꺼 끝나면 진짜 퍼즐관련 게임은 만들고 싶지 않다.. [5] McHello갤로그로 이동합니다. 11.12.20 201 0
295165 언니들 [3] 해일리갤로그로 이동합니다. 11.12.20 98 0
295162 세상을 중독시킨 3명의 천재.swf [6] Stan(220.244) 11.12.20 211 0
295161 숙제갤 시즌은 아니지 [11] Dawnwalkre갤로그로 이동합니다. 11.12.20 142 0
295159 C언어 독학.... 도와주세요.... [3] C언어(123.130) 11.12.20 185 0
295158 이제 종강 시즌이라서 숙제갤 아니지 않아? [2] 해일리갤로그로 이동합니다. 11.12.20 82 0
295154 to. 곽노현 줫밥(122.49) 11.12.20 72 0
295148 어흑 ㅅㅂ json(존슨?) [3] ㅅㄱㅅㄱㅅㄱ갤로그로 이동합니다. 11.12.20 127 0
295147 어제 셤에 나온 손코딩 문제 한마음택배(114.202) 11.12.20 86 0
295144 게임회사 들어가서 따로 인디게임 만들면 [3] bbbb(210.90) 11.12.20 154 0
295143 프갤로 과제물어보는 아가들 [10] Dawnwalkre갤로그로 이동합니다. 11.12.20 179 0
295141 고화질 바탕화면 좀 올려주라. [4] iljeomobolt갤로그로 이동합니다. 11.12.20 153 0
295140 한국에 웹개발하려면 어느 회사가 좋아? [8] Mihark(219.239) 11.12.20 205 0
295138 분노의 파워코딩 2일차 [5] [성대아싸]갤로그로 이동합니다. 11.12.20 196 0
295137 eclipse에서 갤럭시 노트는 세팅 어케 해야합니깡.. [11] 부끄곰갤로그로 이동합니다. 11.12.20 150 0
295136 재밌는 면접 후기 [6] 좋은아버지갤로그로 이동합니다. 11.12.20 290 0
295135 wagle로그인 저거 머냐 ㅋㅋ [1] !@#ㅇㅇ갤로그로 이동합니다. 11.12.20 70 0
295134 나의 내년 목표는 박찬호 보다 연봉을 1원이라도 더 받는걸로 정했어 [4] iljeomobolt갤로그로 이동합니다. 11.12.20 117 0
295132 프갤형님들.. C언어 개초본데요. 이거 힌트좀 주세요. [17] 살코춤(166.104) 11.12.20 181 0
295129 smarty에 대해 잘아시는분? [4] 니 코 가 뭐갤로그로 이동합니다. 11.12.20 79 0
295128 예전에 갑회사에 가서 프리젠테이션 했는데 [6] 3(121.169) 11.12.20 158 0
295127 회사에서 얼마만큼 일을 해야하냐? [3] ㄴㅇㄹ(125.7) 11.12.20 109 0
295125 프갤러 들에게 자격증이란 뭐냐? [6] ㄴㅇㄹ(125.7) 11.12.20 166 0
295124 이거 존나 사고 싶다............... [14] 캐노곤닭(115.92) 11.12.20 200 1
295122 아씨발 [1] 컴쏘갤로그로 이동합니다. 11.12.20 89 0
295121 혼자사는 프갤러들 아침밥 먹고 출근함? [3] ㄴㅇㄹ(125.7) 11.12.20 93 0
295120 보드 메모리 꼽는거 질문.. 2 [3] iljeomobolt갤로그로 이동합니다. 11.12.20 101 0
295119 노트북 사고 싶다 ㄴㅇㄹ(125.7) 11.12.20 46 0
295118 [급구]C만 써서 간단한거 하나 짜고, 계좌로 한장 쏴줄게 [1] 씨는개쁠(1.230) 11.12.20 121 0
295117 가가라이브 쌌다 입장바람 줫밥(122.49) 11.12.20 54 0
295116 to. 쿄스케 가가라이브 방 만들어줭 [1] 줫밥(122.49) 11.12.20 65 0
295115 아 진짜 발로텔리 존나 호감이야 ㅋㅋㅋㅋ [2] 쿄스케갤로그로 이동합니다. 11.12.20 91 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2