[c++ 프로그래밍] 테트리스 (tetris) 프로그램 입니다.
*기*
다운로드
장바구니
소개글
씨로 짠 테트리스 입니다.컴파일 실행환경
visual c++본문내용
#pragma once#include <stdlib.h>
#include <time.h>
#include "console.hpp"
#include "tetris_data.hpp"
enum { CANOT_ROT = -1, CAN_BE = 0, CANOT_DOWN = 1 };
struct tetris
{
int score;
int lines;
int level;
int block_no;
int block_ro;
point block_xy;
point map_xy;
public:
tetris();
tetris(int x, int y);
void set_map(int x, int y);
void init();
void gen_block();
bool canbe_block(int r, int x, int y);
bool canbe_block();
bool rotate_block(int r=1);
bool move_block(int rx, int ry);
void hide_block();
void show_block();
void del_completed();
int key_wait(int d);
};
inline tetris::tetris()
: score(0),lines(0),level(0),map_xy(0,0)
{
srand( time(NULL));
}
inline tetris::tetris(int x, int y)
: score(0),lines(0),level(1),map_xy(x,y)
{
srand( time(NULL));
}
inline void tetris::init()
{
score = 0;
lines = 0;
level = 0;
memset(map,0,sizeof(map));
}
inline void tetris::gen_block()
{
block_no = rand() % 7;
block_ro = 0;
block_xy.x = (MAP_W-4)/2;
block_xy.y = 0;
}
inline bool tetris::canbe_block(int r, int x, int y)
{
BYTE (*block)[4] = blocks[block_no][r];
int i,j;
for(i=0; i < 4; i++) {
for(j=0; j < 4; j++) {
if(block[i][j]) { // 블럭의 모양부분이면
if(y+i < 0 || x+j < 0) return false;
if(y+i >= MAP_H || x+j >= MAP_W) return false;
if(map[y+i][x+j] != 0) { // 맵에 공간이 없으면
return false;
}
}
}
}
return true;
}
압축파일 내 파일목록
tetris001/console.cpp
tetris001/console.hpp
tetris001/main.cpp
tetris001/tetris.cpp
tetris001/tetris.hpp
tetris001/tetris001.cbp
tetris001/tetris001.depend
tetris001/tetris001.layout
tetris001/tetris_data.cpp
tetris001/tetris_data.hpp
tetris001/window.cpp
tetris001/window.hpp
tetris001/스샷.bmp
tetris001/console.hpp
tetris001/main.cpp
tetris001/tetris.cpp
tetris001/tetris.hpp
tetris001/tetris001.cbp
tetris001/tetris001.depend
tetris001/tetris001.layout
tetris001/tetris_data.cpp
tetris001/tetris_data.hpp
tetris001/window.cpp
tetris001/window.hpp
tetris001/스샷.bmp