BASIC4MCU | 질문게시판 | 또 코드해석입니다 마지막입니다 ㅠㅠ(주석)
페이지 정보
작성자 인간현수막 작성일2018-12-09 23:50 조회27,738회 댓글9건본문
테트리스 나머지꺼는 다해결됫는데
이거 블럭에서 또 막히네여 ㅠ 해석좀 도와주세요!!
http://m.blog.daum.net/rockjjy99/2613?np_nil_b=-2 여기서 가져온 소스코드입니다.
#include "Display.h"
#define TE_WIDTH (DP_WIDTH - 2)
#define TE_HEIGHT (DP_HEIGHT - 2)
enum Stone_Type {
TStone = 0,
LStone = 1,
IStone = 2,
SStone = 3,
ZStone = 5,
OStone = 4,
};
struct Stone {
byte field[4];
char x = TE_WIDTH / 2 - 1;
char y = 1;
char rot = 0;
Stone_Type type;
};
Stone St_InitStone();
bool St_HitTest(Stone st)
{
for(char x = 0; x < 5; x++) // Zeilen eines Steins
{
for(char y = 0; y < 4; y++) // Spalten eines Steins
{
if(bitRead(st.field[y],x) == 1) // Ist der aktuelle Stein Pixel gesetzt?
{
char xT = st.x + x; // Absolute x Position
char yT = st.y + y; // Absolute y Position
if(xT < 1 || xT > TE_WIDTH || yT < 1 || yT > TE_HEIGHT) // Aktueller Stein Pixel aus dem Fenster.
{
Serial.print("HIT OUTWINDOW xT=");
Serial.print(xT, DEC);
Serial.print(" yT=");
Serial.println(yT, DEC);
return true;
}
if(Dp_GetPixel(xT,yT)) // Aktueller Stein Pixel auf dem Display ist belegt.
{
Serial.print("HIT Pixel xT=");
Serial.print(xT, DEC);
Serial.print(" yT=");
Serial.println(yT, DEC);
return true;
}
}
}
}
return false;
}
void St_Print(Stone st, bool printIt)
{
for(char x = 0; x < 5; x++)
{
for(char y = 0; y < 4; y++)
{
if(bitRead(st.field[y],x) == 1)
{
char xT = st.x + x;
char yT = st.y + y;
if(xT < 1 || xT > TE_WIDTH || yT < 1 || yT > TE_HEIGHT) // Aktueller Stein Pixel aus dem Fenster.
continue;
Dp_SetPixel(xT, yT, printIt);
}
}
}
}
void St_SetRot(Stone *st, char rot)
{
(*st).rot = rot;
switch((*st).type)
{
case TStone:
{
switch(rot)
{
case 0:
{
(*st).field[0] = B00000;
(*st).field[1] = B00100;
(*st).field[2] = B01110;
(*st).field[3] = B00000;
} break;
case 1:
{
(*st).field[0] = B00000;
(*st).field[1] = B00100;
(*st).field[2] = B00110;
(*st).field[3] = B00100;
} break;
case 2:
{
(*st).field[0] = B00000;
(*st).field[1] = B00000;
(*st).field[2] = B01110;
(*st).field[3] = B00100;
} break;
case 3:
{
(*st).field[0] = B00000;
(*st).field[1] = B00100;
(*st).field[2] = B01100;
(*st).field[3] = B00100;
} break;
}
} break;
case LStone:
{
switch(rot)
{
case 0:
{
(*st).field[0] = B00000;
(*st).field[1] = B00010;
(*st).field[2] = B01110;
(*st).field[3] = B00000;
} break;
case 1:
{
(*st).field[0] = B00000;
(*st).field[1] = B00100;
(*st).field[2] = B00100;
(*st).field[3] = B00110;
} break;
case 2:
{
(*st).field[0] = B00000;
(*st).field[1] = B00000;
(*st).field[2] = B01110;
(*st).field[3] = B01000;
} break;
case 3:
{
(*st).field[0] = B00000;
(*st).field[1] = B01100;
(*st).field[2] = B00100;
(*st).field[3] = B00100;
} break;
}
} break;
case IStone:
{
switch(rot)
{
case 0:
case 2:
{
(*st).field[0] = B00100;
(*st).field[1] = B00100;
(*st).field[2] = B00100;
(*st).field[3] = B00100;
} break;
case 1:
case 3:
{
(*st).field[0] = B00000;
(*st).field[1] = B00000;
(*st).field[2] = B01111;
(*st).field[3] = B00000;
} break;
}
} break;
case SStone:
{
switch(rot)
{
case 0:
{
(*st).field[0] = B00000;
(*st).field[1] = B01100;
(*st).field[2] = B00110;
(*st).field[3] = B00000;
} break;
case 1:
{
(*st).field[0] = B00000;
(*st).field[1] = B00100;
(*st).field[2] = B01100;
(*st).field[3] = B01000;
} break;
case 2:
{
(*st).field[0] = B00000;
(*st).field[1] = B01100;
(*st).field[2] = B00110;
(*st).field[3] = B00000;
} break;
case 3:
{
(*st).field[0] = B00000;
(*st).field[1] = B00010;
(*st).field[2] = B00110;
(*st).field[3] = B00100;
} break;
}
} break;
case OStone:
{
switch(rot)
{
case 0:
case 1:
case 2:
case 3:
{
(*st).field[0] = B00000;
(*st).field[1] = B01100;
(*st).field[2] = B01100;
(*st).field[3] = B00000;
} break;
}
} break;
default: break;
}
}
void St_Rotate(Stone *st)
{
St_SetRot(st, ((*st).rot+1)%4);
}
void St_BackRotate(Stone *st)
{
char rot = (*st).rot - 1;
if(rot == -1)
rot = 3;
St_SetRot(st, rot);
}
Stone St_InitStone()
{
Stone st;
st.type = (Stone_Type)random(0,5);
St_SetRot(&st, 0);
return st;
}
댓글 9
조회수 27,738master님의 댓글
master 작성일
아두이노는 디버깅 기능이 거의 없습니다.
VC++ 같은 프로그램에 알고 싶은 코드를 넣어서 디버깅해보세요
인간현수막님의 댓글
인간현수막
죄송한데..디버깅이 뭐죠???
master님의 댓글
master
https://www.google.co.kr/search?q=c%2B%2B+debugging&oq=c%2B%2B+Debuggin&aqs=chrome.1.69i57j0l5.12745j0j7&sourceid=chrome&ie=UTF-8
프로그램을 한 라인씩 실행 시키면서 변수 값을 체크할 수 있습니다.
함수 단위로 실행도 가능합니다.
디버깅 tool을 잘 선택하면 타인의 도움을 받지 않고도 혼자서 버그를 찾고 해결하기 쉽습니다.
인간현수막님의 댓글
인간현수막
코드 해석좀 해주시면 안될까여?
master님의 댓글
master
동작 시켜가면서 코드를 함께 봐야지 분석이 쉽습니다.
물건이 없는 사람은 분석하기 어렵다는 뜻입니다.
직접 할 수 밖에 없습니다.
인간현수막님의 댓글
인간현수막 작성일대충 맞춰가면서 하고있는데 너무 어려워서 그래요ㅠ
master님의 댓글
master
원래 공부가 늘 어렵습니다.^^
인간현수막님의 댓글
인간현수막
코드 주석좀 부탁드립니다.
master님의 댓글
master
동작하는 물건 이리로 보내줄 수 있으면 시간날 때 동작시켜가면서 분석해보죠