디시인사이드 갤러리

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

갤러리 본문 영역

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

초심자(211.211) 2011.12.19 10:52:22
조회 91 추천 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/10 - -
AD 저녁 뭐먹지? 오늘의 메뉴 추천! 운영자 25/10/31 - -
295566 나 대학 정보통신과인데 주언좀부탁해요 형들 [6] ㅁㄴㅇ(116.47) 11.12.22 102 0
295564 프로그래밍왜배움? [1] 신비의섬죶도갤로그로 이동합니다. 11.12.22 78 0
295562 내 생각에 웹개발은 말야.. [2] ㅌㄹ(59.26) 11.12.22 117 0
295561 형들 코딩용 노트북 추천점여... [8] (121.137) 11.12.22 274 0
295560 안녕하세요 원서쓰는 고3인데요 컴공 전망이 어떤가요? [24] 컴공안좋음?(119.64) 11.12.22 523 0
295559 거의 2달만에 다시하네 이힝(121.177) 11.12.22 43 0
295558 문자열비교 ? 숫자비교 ? [1] 애슐리_그린갤로그로 이동합니다. 11.12.22 73 0
295556 나도 이제 윈도우 7을 씀니당ㅋ [3] y녀6디리(220.118) 11.12.22 116 0
295555 문득 지난 프로그래밍 기말고사 생각이나는군요. [3] HaCh갤로그로 이동합니다. 11.12.22 80 0
295554 c에서 int arr[len]이 어디서 됨? [3] 이힝(121.177) 11.12.22 80 0
295551 토익 700 딸려면 시간 얼마나 걸림 [2] 므해?갤로그로 이동합니다. 11.12.22 177 0
295549 분홍색 동원 종이 나도 받음..ㅋ [4] ㅋㄱ(183.96) 11.12.22 78 0
295548 집에서 출퇴근 하는 것도 감사한 줄 알아야지 ㅇㅇ(61.43) 11.12.22 65 0
295546 정말 컴공 미래가 그렇게 어두운가요 ㅠ.ㅠ [3] 어떡해갤로그로 이동합니다. 11.12.22 215 0
295545 IT 족같다 족같다 하지만... 기회도 많은것 같은데... [3] .3(36.38) 11.12.22 186 0
295541 뒤로가기할때 페이지 갱신은 어떻게 시키는거여유? [3] (112.154) 11.12.22 104 0
295540 컴공 미래가 그렇게 어두운가요 ㅠㅠ [7] 컴공갈끄야ㅠ(175.121) 11.12.22 305 0
295539 복합대입연산자로 몫 나머지 구하는 방법좀 제발요 [1] 123123(118.36) 11.12.22 151 0
295538 오늘도 멋진 게이가 되기 위해 운동을 다녀오겠습니다. [2] Lover♥갤로그로 이동합니다. 11.12.22 85 0
295537 쿄스케형 [3] Lover♥갤로그로 이동합니다. 11.12.22 88 0
295535 아 ㅆㅂ 2호선 [1] 쿄스케갤로그로 이동합니다. 11.12.22 85 0
295534 참나 ㅡㅡ 크리스마스라고 자꾸 여기저기서 연락오네 ㅡㅡ [1] ㅁㄴㅇㄹ(115.137) 11.12.22 110 0
295533 할거없는 게이들 양재로 모여 친목질좀하자 [12] 줫밥(122.49) 11.12.22 178 0
295531 자바 뭐 문법이나 이런건 이제 알겠는데 함수를 몰겠네 [7] 줫밥(122.49) 11.12.22 132 0
295530 야 좆됐닼ㅋㅋ 총동원 소집통지서 옴ㅋㅋㅋ [22] y녀6디리(220.118) 11.12.22 244 0
295529 오늘 양재 번개함 올 새끼 와라 [6] 줫밥(122.49) 11.12.22 89 0
295528 웹하는 횽들 이미지를 순서대로 로드할 수 있을까? [11] 111(115.93) 11.12.22 112 0
295526 슈ㅣ발....줫밥한테 바람맞구...쿄스케는 오늘 피곤하구... [6] 캐바람닭(115.92) 11.12.22 103 0
295524 으악 엑셀로 점수 통계내는것 좀 도와주세여ㅛ [1] 학생뉴비(110.11) 11.12.22 122 0
295523 간지어는 봅니다. [17] 좋은아버지갤로그로 이동합니다. 11.12.22 168 0
295520 퇴쵝! 오늘 주식으로 20만원 벌어서 기분이 좋다. [5] 개심심(61.73) 11.12.22 111 0
295519 오예 나 오늘 칼퇴근 예정 [2] 캐튀근닭(115.92) 11.12.22 95 0
295516 횽들 넷프레임워크 프로그램 질문점.. [1] ㅁㄴㅇㄹ(112.158) 11.12.22 74 0
295515 보안공부하려는 컴공학생입니다. 리눅스를 공부하려는데.. [6] 형님들(175.127) 11.12.22 172 0
295513 쿄스케 술먹자고 [5] 줫밥(122.49) 11.12.22 78 0
295511 방금 글 삭제했는데 [1] 좋은아버지갤로그로 이동합니다. 11.12.22 104 0
295510 자바스크립트 공부하는 사람? [2] Mihark(219.239) 11.12.22 92 0
295508 인하대 컴공, 아주대 컴공 [3] W(175.121) 11.12.22 209 0
295507 오늘 나랑 술빨 사람? 쿄스케 시발놈아 답장 보내라 [2] 줫밥(122.49) 11.12.22 68 0
295506 xe 엔진(제로보드) VS 구글 사이트 도구 안숭(211.197) 11.12.22 85 0
295503 형들 webcash란 회사대해 잘 알고 있는 사람 있어? 일광면(119.198) 11.12.22 140 0
295499 두꺼비 능욕 [4] iljeomobolt갤로그로 이동합니다. 11.12.22 110 0
295498 java.lang.NoSuchMethodError: main [3] 줫밥(122.49) 11.12.22 71 0
295497 나 어제 그만둔다 말했음 [3] 므해?갤로그로 이동합니다. 11.12.22 149 0
295496 헐 이거 심각하네 232(125.7) 11.12.22 60 0
295495 print spooler 에 대해 좀 아는 사람? [2] 232(125.7) 11.12.22 54 0
295494 왜 인터넷으로 책사면 싼거죠? [6] 리눅슽(121.186) 11.12.22 133 0
295493 나 폰디씨인데 여기 뜨는 배너광고중에 밀레니엄:여자를 증오한 남자들 [1] 싴보이갤로그로 이동합니다. 11.12.22 67 0
295492 char *a="\x02""014041\x03"; 핫식스(14.52) 11.12.22 81 0
295491 나 오늘부터 양재천 존나 뛸려고 [6] 줫밥(122.49) 11.12.22 96 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2