#ifndef _C_TETRIS_H
#define _C_TETRIS_H
#include<graphics.h>
#include "f_tetris.h"
const int maxX=800;
const int maxY=800;
using namespace std;
class figure{
public:
int left;
int top;
int width;
figure_type type;
figure_position position;
colors color;
int deep3d;
// const
figure(int _left,int _top, int _width, figure_type _type,figure_position _position, colors _color, int _deep3d);
// dest
~figure();
void drawMe();
void eraseMe();
private:
void drawSquare();
void drawLine();
void drawLeftL();
void drawRightL();
void drawRightB();
void move(int mov);
public: void play();
};
figure::figure(int _left,int _top, int _width, figure_type _type,figure_position _position, colors _color, int _deep3d){
left=_left;
top=_top;
width=_width;
type=_type;
position=_position;
color=_color;
deep3d=_deep3d;
}
figure::~figure(){
// destroy delete this
}
void figure::eraseMe(){
colors tmp=color;
color=BLACK;
drawMe();
color=tmp;
}
void figure::drawMe(){
switch (type){
case SQUARE:
{
drawSquare();
break;
}
case LINE:
{
drawLine();
break;
}
case LEFTL:
{
drawLeftL();
break;
}
case RIGHTL:
{
drawRightL();
break;
}
}
}
void figure::drawSquare(){
setfillstyle(LINE_FILL, color);
setcolor(color);
bar3d(left, top, left+width,top+width, deep3d, 1);
}
void figure::drawLine(){
setfillstyle(LINE_FILL, color);
setcolor(color);
int top_flag=1;
switch (position){
case VERTICAL: V_OPOSITE:{
for (int i=0; i<4; i++){
if (i!=0) top_flag=0;
bar3d(left, (top+width*i), left+width,(top+width*i)+width, deep3d, top_flag);
}
break;
}
case HORIZONTAL: H_OPOSITE:{
for (int i=0; i<4; i++){
bar3d(left+width*i, top, (left+width*i)+width,top+width, deep3d, 1);
}
break;
}
}
}
void figure::drawLeftL(){
setfillstyle(LINE_FILL, color);
setcolor(color);
int top_flag=1;
switch (position){
case VERTICAL:{
int i;
for (i=0; i<4; i++){
if (i!=0) top_flag=0;
bar3d(left, (top+width*i), left+width,(top+width*i)+width, deep3d, top_flag);
}
top_flag=1;
i--;
bar3d(left-width, (top+width*i), left,(top+width*i)+width, deep3d, top_flag);
break;
}
case V_OPOSITE:{
int i;
for (i=0; i<4; i++){
if (i!=0) top_flag=0;
bar3d(left, (top+width*i), left+width,(top+width*i)+width, deep3d, top_flag);
}
top_flag=1;
//i--;
bar3d(left+width, top, left+2*width,top+width, deep3d, top_flag);
break;
}
case HORIZONTAL:{
int i;
for (i=0; i<4; i++){
bar3d(left+width*i, top, (left+width*i)+width,top+width, deep3d, 1);
}
bar3d(left, top-width, left+width,top, deep3d, top_flag);
break;
}
case H_OPOSITE:{
int i;
for (i=0; i<4; i++){
bar3d(left+width*i, top, (left+width*i)+width,top+width, deep3d, 1);
}
i--;
bar3d(left+width*i, top+width, (left+width*i)+width,top+2*width, deep3d, 1);
break;
}
}//end switch
}
void figure::drawRightL(){
setfillstyle(LINE_FILL, color);
setcolor(color);
int top_flag=1;
switch (position){
case VERTICAL:{
int i;
for (i=0; i<4; i++){
if (i!=0) top_flag=0;
bar3d(left, (top+width*i), left+width,(top+width*i)+width, deep3d, top_flag);
}
top_flag=1;
i--;
bar3d(left+width, (top+width*i), left+2*width,(top+width*i)+width, deep3d, top_flag);
break;
}
case V_OPOSITE:{
int i;
for (i=0; i<4; i++){
if (i!=0) top_flag=0;
bar3d(left, (top+width*i), left+width,(top+width*i)+width, deep3d, top_flag);
}
top_flag=1;
//i--;
bar3d(left-width, top, left,top+width, deep3d, top_flag);
break;
}
case HORIZONTAL:{
int i;
for (i=0; i<4; i++){
bar3d(left+width*i, top, (left+width*i)+width,top+width, deep3d, 1);
}
top_flag=0;
bar3d(left, top+width, left+width,top+2*width, deep3d, top_flag);
break;
}
case H_OPOSITE:{
int i;
for (i=0; i<4; i++){
bar3d(left+width*i, top, (left+width*i)+width,top+width, deep3d, 1);
}
i--;
bar3d(left+width*i, top-width, (left+width*i)+width,top, deep3d, 1);
break;
}
}//end switch
}
void figure::drawRightB(){
setfillstyle(LINE_FILL, color);
setcolor(color);
int top_flag=1;
switch (position){
case VERTICAL:{
int i;
for (i=0; i<4; i++){
if (i!=0) top_flag=0;
bar3d(left, (top+width*i), left+width,(top+width*i)+width, deep3d, top_flag);
}
top_flag=1;
i--;
bar3d(left+width, (top+width*i), left+2*width,(top+width*i)+width, deep3d, top_flag);
break;
}
case V_OPOSITE:{
int i;
for (i=0; i<4; i++){
if (i!=0) top_flag=0;
bar3d(left, (top+width*i), left+width,(top+width*i)+width, deep3d, top_flag);
}
top_flag=1;
//i--;
bar3d(left-width, top, left,top+width, deep3d, top_flag);
break;
}
case HORIZONTAL:{
int i;
for (i=0; i<4; i++){
bar3d(left+width*i, top, (left+width*i)+width,top+width, deep3d, 1);
}
top_flag=0;
bar3d(left, top+width, left+width,top+2*width, deep3d, top_flag);
break;
}
case H_OPOSITE:{
int i;
for (i=0; i<4; i++){
bar3d(left+width*i, top, (left+width*i)+width,top+width, deep3d, 1);
}
i--;
bar3d(left+width*i, top-width, (left+width*i)+width,top, deep3d, 1);
break;
}
}//end switch
}
void figure::move(int mov){
int tmp;
eraseMe(); // erase figure
switch (mov){
case KEY_LEFT:{
tmp=left-width;
if (tmp>=0) left=tmp;
break;
}
case KEY_RIGHT:{
tmp=left+width;
if (tmp<=screenMaxX) left=tmp;
break;
}
case KEY_UP:{
tmp=top-width;
if (tmp>=0) top=tmp;
break;
}
case KEY_DOWN:{
tmp=top+width;
if (tmp<=screenMaxY) top=tmp;
break;
}
case SPACE:{
tmp=position+1;
if (tmp>3) tmp=0;
position=(figure_position) tmp;
break;
}
}//esw
drawMe(); // draw figure
}
void figure::play(){
char c='w';
while (c!='q'){
if (kbhit()){
c=getch();
if (c=='q') exit(0);
move((int)c);
char txt[20];
//sprintf(txt,"Vocke:%f",seconds);
sprintf(txt,"znak:%d",c);
outtextxy(20,20,txt);
}
}
}
#endif // _C_TETRIS_H
No comments:
Post a Comment