수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

테트리스~블럭 주석을 못 찾겠습니다

나봄

2023.04.01



#include windows.h
#include resource.h
lresult callback wndproc(hwnd, uint, wparam, lparam);
lresult callback pausechildproc(hwnd, uint, wparam, lparam);
hinstance g_hinst;
hwnd hwndmain;
lpctstr lpszclass=text(tetris4);
int apientry winmain(hinstance hinstance,hinstance hprevinstance
,lpstr lpszcmdparam,int ncmdshow)
{
hwnd hwnd;
msg message;
wndclass wndclass;
g_hinst=hinstance;

wndclass.cbclsextra=0;
wndclass.cbwndextra=0;
wndclass.hbrbackground=(hbrush)(color_window+1);
wndclass.hcursor=loadcursor(null,idc_arrow);
wndclass.hicon=loadicon(hinstance,makeintresource(idi_icon1));
wndclass.hinstance=hinstance;
wndclass.lpfnwndproc=wndproc;
wndclass.lpszclassname=lpszclass;
wndclass.lpszmenuname=makeintresource(idr_menu1);
wndclass.style=0;
registerclass(&wndclass);
wndclass.lpfnwndproc=pausechildproc;
wndclass.lpszclassname=pausechild;
wndclass.lpszmenuname=null;
wndclass.style=cs_savebits;
registerclass(&wndclass);
hwnd=createwindow(lpszclass,lpszclass, ws_caption | ws_sysmenu | ws_minimizebox,
cw_usedefault,cw_usedefault,0,0,null,(hmenu)null,hinstance,null);
showwindow(hwnd,ncmdshow);

haccel haccel=loadaccelerators(hinstance,makeintresource(idr_accelerator1));
while (getmessage(&message,null,0,0)) {
if (!translateaccelerator(hwnd,haccel,&message)) {
translatemessage(&message);
dispatchmessage(&message);
}
}
return (int)message.wparam;
}
// 함수 원형
void drawscreen(hdc hdc);
void makenewbrick();
bool movedown();
int getaround(int x,int y,int b,int r);
void testfull();
void printtile(hdc hdc,int x,int y,int c);
void drawbitmap(hdc hdc,int x,int y,hbitmap hbit);
void playeffectsound(uint sound);
void adjustmainwindow();
void updateboard();
bool ismovingbrick(int x,int y);
// 매크로 및 전역 변수들
#define random(n) (rand()%n)
#define ts 24
struct point {
int x,y;
};
point shape[][4][4]={
{ {0,0,1,0,2,0,-1,0}, {0,0,0,1,0,-1,0,-2}, {0,0,1,0,2,0,-1,0}, {0,0,0,1,0,-1,0,-2} },
{ {0,0,1,0,0,1,1,1}, {0,0,1,0,0,1,1,1}, {0,0,1,0,0,1,1,1}, {0,0,1,0,0,1,1,1} },
{ {0,0,-1,0,0,-1,1,-1}, {0,0,0,1,-1,0,-1,-1}, {0,0,-1,0,0,-1,1,-1}, {0,0,0,1,-1,0,-1,-1} },
{ {0,0,-1,-1,0,-1,1,0}, {0,0,-1,0,-1,1,0,-1}, {0,0,-1,-1,0,-1,1,0}, {0,0,-1,0,-1,1,0,-1} },
{ {0,0,-1,0,1,0,-1,-1}, {0,0,0,-1,0,1,-1,1}, {0,0,-1,0,1,0,1,1}, {0,0,0,-1,0,1,1,-1} },
{ {0,0,1,0,-1,0,1,-1}, {0,0,0,1,0,-1,-1,-1}, {0,0,1,0,-1,0,-1,1}, {0,0,0,-1,0,1,1,1} },
{ {0,0,-1,0,1,0,0,1}, {0,0,0,-1,0,1,1,0}, {0,0,-1,0,1,0,0,-1}, {0,0,-1,0,0,-1,0,1} },
{ {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0} },
{ {0,0,0,0,0,-1,1,0},{0,0,0,0,-1,0,0,-1},{0,0,0,0,0,1,-1,0},{0,0,0,0,0,1,1,0} },
};
enum { empty, brick, wall=sizeof(shape)/sizeof(shape[0])+1 };
int arbw[]={8,10,12,15,20};
int arbh[]={15,20,25,30,32};
int bw=10;
int bh=20;
int board[22][34];
int nx,ny;
int brick,rot;
int nbrick;
int score;
int bricknum;
enum tag_status { gameover, running, pause };
tag_status gamestatus;
int interval;
hbitmap hbit[11];
bool bshowspace=true;
bool bquiet=false;
hwnd hpausechild;
lresult callback wndproc(hwnd hwnd, uint imessage, wparam wparam, lparam lparam)
{
int i;
int trot;
hdc hdc;
paintstruct ps;
int x,y;
switch (imessage) {
case wm_create:
hwndmain=hwnd;
hpausechild=createwindow(pausechild,null,ws_child | ws_border,
0,0,0,0,hwnd,(hmenu)0,g_hinst,null);
adjustmainwindow();
gamestatus=gameover;
srand(gettickcount());
for (i=0;i11;i++) {
hbit[i]=loadbitmap(g_hinst,makeintresource(idb_bitmap1+i));
}
return 0;
case wm_command:
if (loword(wparam) = idm_game_size1 && loword(wparam) = idm_game_size5) {
if (gamestatus != gameover) {
return 0;
}
bw=arbw[loword(wparam)-idm_game_size1];
bh=arbh[loword(wparam)-idm_game_size1];
adjustmainwindow();
memset(board,0,sizeof(board));
invalidaterect(hwnd,null,true);
}
switch (loword(wparam)) {
case idm_game_start:
if (gamestatus != gameover) {
break;
}
for (x=0;xbw+2;x++) {
for (y=0;ybh+2;y++) {
board[x][y] = (y==0 || y==bh+1 || x==0 || x==bw+1) ? wall:empty;
}
}
score=0;
bricknum=0;
gamestatus=running;
nbrick=random(sizeof(shape)/sizeof(shape[0]));
makenewbrick();
interval=1000;
settimer(hwnd,1,interval,null);
break;
case idm_game_pause:
if (gamestatus == running) {
gamestatus=pause;
settimer(hwnd,1,1000,null);
showwindow(hpausechild,sw_show);
} else if (gamestatus == pause) {
gamestatus=running;
settimer(hwnd,1,interval,null);
showwindow(hpausechild,sw_hide);
}
break;
case idm_game_exit:
destroywindow(hwnd);
break;
case idm_game_viewspace:
bshowspace=!bshowspace;
invalidaterect(hwnd,null,false);
break;
case idm_game_quiet:
bquiet=!bquiet;
break;
}
return 0;
case wm_initmenu:
checkmenuitem((hmenu)wparam,idm_game_viewspace,
mf_bycommand | (bshowspace ? mf_checked:mf_unchecked));
checkmenuitem((hmenu)wparam,idm_game_quiet,
mf_bycommand | (bquiet ? mf_checked:mf_unchecked));
return 0;
case wm_timer:
if (gamestatus == running) {
if (movedown() == true) {
makenewbrick();
}
} else {
if (iswindowvisible(hpausechild)) {
showwindow(hpausechild,sw_hide);
} else {
showwindow(hpausechild,sw_show);
}
}
return 0;
case wm_keydown:
if (gamestatus != running || brick == -1)
return 0;
switch (wparam) {
case vk_left:
if (getaround(nx-1,ny,brick,rot) == empty) {
if ((lparam & 0x40000000) == 0) {
playeffectsound(idr_wave4);
}
nx--;
updateboard();
}
break;
case vk_right:
if (getaround(nx+1,ny,brick,rot) == empty) {
if ((lparam & 0x40000000) == 0) {
playeffectsound(idr_wave4);
}
nx++;
updateboard();
}
break;
case vk_up:
trot=(rot == 3 ? 0:rot+1);
if (getaround(nx,ny,brick,trot) == empty) {
playeffectsound(idr_wave1);bave1);
rot=trot;
updateboard();
}
break;
case vk_down:
if (movedown() == true) {
makenewbrick();
}
break;
case vk_space:
playeffectsound(idr_wave3);
while(movedown()==false) {;}
makenewbrick();
break;
}
return 0;
case wm_paint:
hdc=beginpaint(hwnd, &ps);
drawscreen(hdc);
endpaint(hwnd, &ps);
return 0;
case wm_destroy:
killtimer(hwndmain,1);
for (i=0;i11;i++) {
deleteobject(hbit[i]);
}
postquitmessage(0);
return 0;
}
return(defwindowproc(hwnd,imessage,wparam,lparam));
}
void drawscreen(hdc hdc)
{
int x,y,i;
tchar str[128];
// 테두리 그림
for (x=0;xbw+1;x++) {
printtile(hdc,x,0,wall);
printtile(hdc,x,bh+1,wall);
}
for (y=0;ybh+2;y++) {
printtile(hdc,0,y,wall);
printtile(hdc,bw+1,y,wall);
}
// 게임판과 이동중인 벽돌 그림
for (x=1;xbw+1;x++) {
for (y=1;ybh+1;y++) {
if (ismovingbrick(x,y)) {
printtile(hdc,x,y,brick+1);
} else {
printtile(hdc,x,y,board[x][y]);
}
}
}
// 다음 벽돌 그림
for (x=bw+3;x=bw+11;x++) {
for (y=bh-5;y=bh+1;y++) {
if (x==bw+3 || x==bw+11 || y==bh-5 || y==bh+1) {
printtile(hdc,x,y,wall);
} else {
printtile(hdc,x,y,0);
}
}
}
if (gamestatus != gameover) {
for (i=0;i4;i++) {
printtile(hdc,bw+7+shape[nbrick][0][i].x,bh-2+shape[nbrick][0][i].y,nbrick+1);
}
}
// 정보 출력
lstrcpy(str,tetris ver 1.3);
textout(hdc,(bw+4)*ts,30,str,lstrlen(str));
wsprintf(str,점수 : %d ,score);
textout(hdc,(bw+4)*ts,60,str,lstrlen(str));
wsprintf(str,벽돌 : %d 개 ,bricknum);
textout(hdc,(bw+4)*ts,80,str,lstrlen(str));
}
void makenewbrick()
{
bricknum++;
brick=nbrick;
nbrick=random(sizeof(shape)/sizeof(shape[0]));
nx=bw/2;
ny=3;
rot=0;
invalidaterect(hwndmain,null,false);
if (getaround(nx,ny,brick,rot) != empty) {
killtimer(hwndmain,1);
gamestatus=gameover;
messagebox(hwndmain,게임이 끝났습니다. 다시 시작하려면 게임/시작
항목(s)을 선택해 주십시오.,알림,mb_ok);
}
}
int getaround(int x,int y,int b,int r)
{
int i,k=empty;
for (i=0;i4;i++) {
k=max(k,board[x+shape[b][r][i].x][y+shape[b][r][i].y]);
}
return k;
}
bool movedown()
{
if (getaround(nx,ny+1,brick,rot) != empty) {
testfull();
return true;
}
ny++;
// 즉시 그려서 벽돌이 내려가는 모양을 보여 준다.
updateboard();
updatewindow(hwndmain);
return false;
}
void testfull()
{
int i,x,y,ty;
int count=0;
static int arscoreinc[]={ 0,1,3,8,20 };
for (i=0;i4;i++) {
board[nx+shape[brick][rot][i].x][ny+shape[brick][rot][i].y]=brick+1;// 내려와서 도착하였을때의 블럭값
}
// 이동중인 벽돌이 잠시 없는 상태.
brick=-1;
//오호...여기서 부터는 블럭이 없애주는 기능의 함수를 가지고 있다...여기를 잘 고치면...돈을 갚을수 있는 골드 점수를 획득 하는 함수를 추가
for (y=1;ybh+1;y++) {
for (x=1;xbw+1;x++) {
if (board[x][y] == empty) break;
}
if (x == bw+1) {
playeffectsound(idr_wave2);
count++;
for (ty=y;ty1;ty--) {
for (x=1;xbw+1;x++) {
board[x][ty]=board[x][ty-1];
}
}
updateboard();
updatewindow(hwndmain);
sleep(150);
}
}
score += arscoreinc[count];
if (score % 20 == 3 && interval 200) {
killtimer(hwndmain,1);
gamestatus=gameover;
messagebox(hwndmain,게임이 끝났습니다. 다시 시작하려면 게임/시작
항목(s)을 선택해 주십시오.,알림,mb_ok);
}
if (bricknum % 10 == 0 && interval 200) {
interval -= 50;
settimer(hwndmain,1,interval,null);
}
}
void drawbitmap(hdc hdc,int x,int y,hbitmap hbit)//여기는 테두리와 블럭을 보여주는 함수
{
hdc memdc;
hbitmap oldbitmap;
int bx,by;
bitmap bit;
memdc=createcompatibledc(hdc);
oldbitmap=(hbitmap)selectobject(memdc, hbit);
getobject(hbit,sizeof(bitmap),&bit);
bx=bit.bmwidth;
by=bit.bmheight;
bitblt(hdc,x,y,bx,by,memdc,0,0,srccopy); //블럭의 테두리가 약간 수정이 된다
selectobject(memdc,oldbitmap);
deletedc(memdc);
}
void printtile(hdc hdc,int x,int y,int c)//여기는... 벽돌수가 있고 점수가 쌓여지는 곳
{
drawbitmap(hdc,x*ts,y*ts,hbit[c]);
if (c==empty && bshowspace)
rectangle(hdc,x*ts+ts/2-1,y*ts+ts/2-1,x*ts+ts/2+1,y*ts+ts/2+1);
return;
}
void playeffectsound(uint sound)//소리겠지
{
if (!bquiet) {
playsound(makeintresource(sound),g_hinst,snd_resource | snd_async);
}
}
void adjustmainwindow()//여기는 어...윈도우 맵 자체를 관리한다...숫자를 바꾸면 병신이 될수 있다
{
rect crt;
setrect(&crt,0,0,(bw+12)*ts,(bh+2)*ts);
adjustwindowrect(&crt,ws_caption | ws_sysmenu | ws_minimizebox,true);
setwindowpos(hwndmain,null,0,0,crt.right-crt.left,crt.bottom-crt.top,
swp_nomove | swp_nozorder);
setwindowpos(hpausechild,null,(bw+12)*ts/2-100,
(bh+2)*ts/2-50,200,100,swp_nozorder);
}
lresult callback pausechildproc(hwnd hwnd, uint imessage, wparam wparam, lparam lparam)
{
hdc hdc;
paintstruct ps;
rect crt;
textmetric tm;
switch (imessage) {
case wm_paint:
hdc=beginpaint(hwnd, &ps);
getclientrect(hwnd,&crt);
settextalign(hdc,ta_center);
gettextmetrics(hdc,&tm);
textout(hdc,crt.right/2,crt.bottom/2-tm.tmheight/2,pause,5);
endpaint(hwnd, &ps);
return 0;
}
return(defwindowproc(hwnd,imessage,wparam,lparam));
}
void updateboard()
{
rect rt;
setrect(&rt,ts,ts,(bw+1)*ts,(bh+1)*ts); //이동중인 블럭을 병신 만들수 잇는 기능
invalidaterect(hwndmain,&rt,false);
}
bool ismovingbrick(int x,int y)
{
int i;
if (gamestatus == gameover || brick == -1) {
return false;
}
for (i=0;i4;i++) {
if (x == nx+shape[brick][rot][i].x && y == ny+shape[brick][rot][i].y) //나오는 블럭이 이상하게 나온다
return true;
}
return false;
}오류는 없는데...

여기까지가 제가 책에 있는데로 작업을 한 겁니다 근데...여기서 또 다른 모양의 블럭을 추가시키고 싶은데 그 주석을 못찾겠습니다

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

번호 제 목 글쓴이 날짜
2694724 코딩시 폰트 문제; ㅠ 후력 2025-05-13
2694696 텍스트박스 입력에 관한 문제입니다. 딥공감 2025-05-13
2694668 [질문] 페이퍼비전 PointLight 관련 질문 드려요.. 두바다찬솔 2025-05-13
2694611 Flash Lite 2.1에서 BitmapData와 Matrix 지원안하나요? (3) 이플 2025-05-12
2694582 IE & 파이어폭스 (2) 흙이랑 2025-05-12
2694553 무비클립안의 duplicate 발동이 안돼네요; 딥보라 2025-05-12
2694523 자바 애플릿 질문좀 ^^ (6) 동이 2025-05-12
2694494 [질문] JAVA 또는 C++ 로 프로그램 개발시.. 레지스터리 등록 관련 의문점? (3) 우람늘 2025-05-11
2694469 익스6에서 css버그 나오는것 해결방법좀요 !!!! (6) 원술 2025-05-11
2694442 로컬에선 잘 나오는데 운영에 반영하면 이상하게 나와요. (8) 목화 2025-05-11
2694412 [질문] 이미지 로딩후 사이즈 조절할때 (1) 아담 2025-05-11
2694391 설치형 블로그 쓰시는 분들 어떤거 쓰세요?? (7) AngelsTears 2025-05-10
2694362 Microsoft SQL Server에서 서버만드는법 어둠 2025-05-10
2694333 for문으로 돌린 이름의 제어 (4) 레이 2025-05-10
2694308 이미지 css 도와주세요 ㅠㅠ (2) 애기 2025-05-10
2694223 [급질문]스크롤스파이의 offset값 진나 2025-05-09
2694195 li에 이미지 넣고 세로로 메뉴 구성하는 경우 (1) 예님 2025-05-09
2694167 canvas 질문요. (4) 찬늘봄 2025-05-08
2694136 왜 이렇게 나오는지 이해가 잘 가지 않네요. 부탁드리겠습니다... (2) 세련 2025-05-08
2694111 div , css 공부하고있는데요 잘모르겠어요.. 도와주세요 ㅠ_ㅠ (10) 모람 2025-05-08
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com