자바 테트리스 오늘 두번째 질문입니다.. 막혀서;;;
잠팅이
//아이템 시작셋팅
this.currentitem = itemlist.get(rnd.nextint(itemlist.size()));
//아이템리스트 크기 반환한다음 크기만큼 나눈거 중 랜덤으로 가져온다.
//즉, 아이템리스트의 개수는 7개 이다.. 7/1 해서 하나를 박스로 가져온다.
//이것을 currentitem에 저장한다. 현재나올것
this.currentitem.setcolor(this.colorlist.get(this.rnd.nextint(this.colorlist.size())));
//색상도 종류별로 해서 나눠서 그것을 현재 나오는 블럭에 색깔 적용한다.
this.currentitem.setdefaultlocation();
//setdefaultlocation()로 이동
setnextitem(); //setnextitem() 메소드로 이동
this.setdefaultcloseoperation(jframe.exit_on_close);
this.setvisible(true);
//this.setresizable(false);
t = new thread(this);
t.start();///////////////////setdefaultlocation() 메소드 시작/////////////////////////////////////////////////////////
//시작위치조정
public void setdefaultlocation(){
for (int i=0; ipanel.length; i++){ //패널개수는 테트리스 전부 같이 4개 입니다..
int x = block[i].getx() + (int)(xcnt/2-2);
// 블럭은 변환가지수 입니다.. 예를 들어 ㄱ 자블럭이 면 변환이 4이니 4이고 ㅁ블릭이면 변환이 1이니 1 이런거입니다.
int y = block[i].gety() +2;
panel[i].setlocation(x * area, y * area);
}
this.currentxy.setxy((int)(xcnt/2-2),2);//////////////////setnextitem() 메소드로 시작/////////////////////////////////////////////////////////////
public void setnextitem(){
item temp;
do{
temp = itemlist.get(rnd.nextint(itemlist.size())); //아이템 개수 만큼으로 나눠서 하나
}
while (temp==this.currentitem);//현재아이템과 중복x 현재와 나중의 것이 같다면
this.nextitem = temp;
this.nextitem.setcolor(this.colorlist.get(this.rnd.nextint(this.colorlist.size())));
this.nextitem.setnextlocation();//위치셋팅
////////////////////////////////////블럭클래스///////////////////////////////////////////
class block
{
private int x;
private int y;
//생성자
public block(){
}
public block(int x, int y){
this.x = x;
this.y = y;
}
//해당 포인트맛큼 감산
public void move(int xplus, int yplus){
this.x += xplus;
this.y += yplus;
}
//x포인트 반환
public int getx(){
return this.x;
}
//y포인트 반환
public int gety(){
return this.y;
}
//자신 반환
public block getblock(){
return this;
}
//xy셋팅
public void setxy(int x, int y){
this.x = x;
this.y = y;
}
}
////////////////블럭의 함수////////////////////////////////////////////
아이템 시작 세팅에서 궁금한게 처음에 this.currentitem.setdefaultlocation(); 입니다.
this.currentitem은 현재 나올 모양의 블럭을 가지고 잇습니다.. ㄴ,ㅁ,ㅣ, ㄹ 자 등등이 랜덤입니다.
this.currentitem.setdefaultlocation(); 함수에서..
int x = block[i].getx() + (int)(xcnt/2-2);
// 블럭은 변환가지수 입니다.. 예를 들어 ㄱ 자블럭이 면 변환이 4이니 4이고 ㅁ블릭이면 변환이 1이니 1 이런거입니다.
int y = block[i].gety() +2;
panel[i].setlocation(x * area, y * area);
}
this.currentxy.setxy((int)(xcnt/2-2),2);
부분이 이해를 잘못하겠습니다.. 블럭 [i].getx() 하라는데.. 뭐 어떻게 하는건지 잘 모르겠습니다..
블럭클래스부분 적어놨습니다..ㅜㅜ
setlocation 가 무슨 메소드인지;;;
여튼 xy 나오는건 모르겠습니다..ㅜㅜ
그리고 넥스트 아이템에서 문제는..
public void setnextitem(){
item temp;
do{
temp = itemlist.get(rnd.nextint(itemlist.size())); //아이템 개수 만큼으로 나눠서 하나
}
while (temp==this.currentitem);//현재아이템과 중복x
this.nextitem = temp;
this.nextitem.setcolor(this.colorlist.get(this.rnd.nextint(this.colorlist.size())));
this.nextitem.setnextlocation();//위치셋팅
입니다.. 세번쨰 라인이.. 문제인데.. 랜덤해서 나오는것을 temp에 저장한다음..
와일문 ==은 같다라는 뜻인데.. 현재 아이템과 temp가 같다면 이라고 해석이 되는데..
왜 코딩 했는 작성자는 현재아이템과 중복x 라고 주석을 달아놨더라고요...
이해가 잘안되네요...
그리고 마지막..this.setdefaultcloseoperation(jframe.exit_on_close);
this.setvisible(true);
//this.setresizable(false);
t = new thread(this);
t.start();
인데.. 만약 꺼지면 꺼진다는거고... 쓰레드를 시작 start()메서드를 실행해서
run 이라는 메서드로 실행된다는걸 알겠습니다..
너무 넓게 알아서.. 제대로 안다 라고는 할수는 없는데...
혹시 무심코 클릭하시다가 본인이 아시는 부분이 나왔다 하면 좀 짚어서 틀린부분이나 추가 설명같은거 좀 적어주세요..
부탁드립니다.. 누구한테 물어볼때도 없고..ㅠㅠ 답답하네요..