以下代码能显示两个方块下落。
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <conio.h>
using namespace std;
//Tetris
class point
{
private:
int (*a)[10];
public:
point()
{}
void at(int (*a)[10])
{
this->a=a;
}
void move(int& k,int &t)
{
if(k==0)
{
a[k][0]=0; //开始时第一格变黑
a[k+1][0]=0;//开始时第二格变黑
}
if(k!=0 && k<20)
{
a[t][0]=1; //上一格变空白
a[k][0]=0; //当前格变黑
a[k+1][0]=0;//下一格变黑
}
}
};
class cdown
{
private:
point m_p;
public:
cdown(int (*a)[10])
{
m_p.at(a);
}
void begin(int& k,int &t)
{
m_p.move(k,t);
}
void end(int& k,int& t)
{
if(k<20)
{
printf("%d\n",k);
t=k;
k=k+1;
}
}
void shape(int& k,int& t)
{
}
~cdown()
{}
};
int main(int argc, char** argv)
{
int i=0;
int j=0;
int k=0;
int t=0;
int a[20][10];
for(i=0; i<20; i++)
{
for(int j=0; j<10; j++)
{
a[i][j]=1;
}
}
cdown down((a));
while(1)
{
down.begin(k,t);
for(i=0; i<20; i++)
{
for(j=0; j<10; j++)
{
if(a[i][j]==0)
{
printf("■");
}
else
{
printf("□");
}
}
printf("\n");
}
down.end(k,t);
sleep(1);
clrscr();
}
return 0;
}