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, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
};
//画出地图
void drawMap()
{
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 18; j++)
switch (map[i][j])
{
case 0:
cout << " ";
break;
case 1:
cout << "□";
break;
case 2:
cout << "■";
break;
}
cout << endl;
}
}
//形状类
class Shape
{
public:
int a0, a1, a2, a3, b0, b1, b2, b3;
//初始化
virtual void init()
{
map[a0][b0] = 2; map[a1][b1] = 2; map[a2][b2] = 2; map[a3][b3] = 2;
}
//清除形状
virtual void clean()
{
map[a0][b0] = 0; map[a1][b1] = 0; map[a2][b2] = 0; map[a3][b3] = 0;
}
//点击
virtual void click(char ch){};
//下落
virtual void fall(){};
//判断形状是否到底
virtual bool shape_is_botton_adjacent(){ return true; };
//判断形状是否可向下移动
bool fall_moveable();
//判断形状是否可向左移动
bool laft_moveable();
//判断形状是否可向右移动
bool right_moveable();
//判断方块是否着陆
bool is_block_adjacent(int a, int b)
{
if (map[a][b] != 0)
return true;
else return false;
}
};
//“田”形状类
class Tian :public Shape
{
public:
Tian(int a_0 = 1, int a_1 = 1, int a_2 = 2, int a_3 = 2, int b_0 = 8, int b_1 = 9, int b_2 = 8, int b_3 = 9)
{ a0 = a_0, a1 = a_1, a2 = a_2, a3 = a_3, b0 = b_0, b1 = b_1, b2 = b_2, b3 = b_3; }
void click(char ch)
{
switch (ch)
{
case'a':
{
if (laft_moveable() == true)
{
clean();
b0--; b1--; b2--; b3--;
}
break;
}
case'd':
{
if (right_moveable() == true)
{
clean();
b0++; b1++; b2++; b3++;
}
break;
}
case's':
{
if (fall_moveable() == true)
{
clean();
a0++; a1++; a2++; a3++;
}
break;
}
}
}
void fall()
{
if (fall_moveable() == true)
{
clean();
a0++; a1++; a2++; a3++;
}
}
bool fall_moveable()
{
if (map[a2 + 1][b2] == 0 && map[a3 + 1][b3] == 0)
return true;
else return false;
}
bool laft_moveable()
{
if (map[a0][b0-1] == 0 && map[a2][b2-1] == 0)
return true;
else return false;
}
bool right_moveable()
{
if (map[a1][b1 + 1] == 0 && map[a3][b3 + 1] == 0)
return true;
else return false;
}
bool shape_is_botton_adjacent()
{
if (is_block_adjacent(a2, b2) || is_block_adjacent(a3, b3))
return true;
else return false;
}
};
//“|”形状类
class Shu :public Shape
{
public:
Shu(int a_0 = 1, int a_1 = 2, int a_2 = 3, int a_3 = 4, int b_0 = 9, int b_1 = 9, int b_2 = 9, int b_3 = 9)
{
a0 = a_0, a1 = a_1, a2 = a_2, a3 = a_3, b0 = b_0, b1 = b_1, b2 = b_2, b3 = b_3;
}
void click(char ch)
{
switch (ch)
{
case'a':
{
if (laft_moveable() == true)
{
clean();
b0--; b1--; b2--; b3--;
}
break;
}
case'd':
{
if (right_moveable() == true)
{
clean();
b0++; b1++; b2++; b3++;
}
break;
}
case's':
{
if (fall_moveable() == true)
{
clean();
a0++; a1++; a2++; a3++;
}
break;
}
}
}
void fall()
{
if (fall_moveable() == true)
{
clean();
a0++; a1++; a2++; a3++;
}
}
bool fall_moveable()
{
if (map[a3 + 1][b3] == 0 )
return true;
else return false;
}
bool laft_moveable()
{
if (map[a0][b0 - 1] == 0 && map[a2][b2 - 1] == 0 && map[a1][b1 - 1] == 0 && map[a3][b3 - 1] == 0)
return true;
else return false;
}
bool right_moveable()
{
if (map[a1][b1 + 1] == 0 && map[a3][b3 + 1] == 0 && map[a0][b0 + 1] == 0 && map[a2][b2 + 1] == 0)
return true;
else return false;
}
bool shape_is_botton_adjacent()
{
if (is_block_adjacent(a3, b3))
return true;
else return false;
}
};
//“——”形状类
class Heng :public Shape
{
public:
Heng(int a_0 = 1, int a_1 = 1, int a_2 = 1, int a_3 = 1, int b_0 = 7, int b_1 = 8, int b_2 = 9, int b_3 = 10)
{
a0 = a_0, a1 = a_1, a2 = a_2, a3 = a_3, b0 = b_0, b1 = b_1, b2 = b_2, b3 = b_3;
}
void click(char ch)
{
switch (ch)
{
case'a':
{
if (laft_moveable() == true)
{
clean();
b0--; b1--; b2--; b3--;
}
break;
}
case'd':
{
if (right_moveable() == true)
{
clean();
b0++; b1++; b2++; b3++;
}
break;
}
case's':
{
if (fall_moveable() == true)
{
clean();
a0++; a1++; a2++; a3++;
}
break;
}
}
}
void fall()
{
if (fall_moveable() == true)
{
clean();
a0++; a1++; a2++; a3++;
}
}
bool fall_moveable()
{
if (map[a0 + 1][b0] == 0 && map[a2 + 1][b2] == 0 && map[a1 + 1][b1] == 0 && map[a3 + 1][b3] == 0)
return true;
else return false;
}
bool laft_moveable()
{
if (map[a0][b0 - 1] == 0)
return true;
else return false;
}
bool right_moveable()
{
if (map[a3][b3 + 1] == 0 )
return true;
else return false;
}
bool shape_is_botton_adjacent()//判断形状是否可以移动
{
if (is_block_adjacent(a0, b0) || is_block_adjacent(a1, b1) || is_block_adjacent(a2, b2) || is_block_adjacent(a3, b3))
return true;
else return false;
}
};
//"“L”形状的四种形态"
class L_shape1 :public Shape
{
public:
L_shape1(int a_0 = 1, int a_1 = 2, int a_2 = 3, int a_3 = 3, int b_0 = 9, int b_1 = 9, int b_2 = 9, int b_3 = 10)
{
a0 = a_0, a1 = a_1, a2 = a_2, a3 = a_3, b0 = b_0, b1 = b_1, b2 = b_2, b3 = b_3;
}
void click(char ch)
{
switch (ch)
{
case'a':
{
if (laft_moveable() == true)
{
clean();
b0--; b1--; b2--; b3--;
}
break;
}
case'd':
{
if (right_moveable() == true)
{
clean();
b0++; b1++; b2++; b3++;
}
break;
}
case's':
{
if (fall_moveable() == true)
{
clean();
a0++; a1++; a2++; a3++;
}
break;
}
}
}
void fall()
{
if (fall_moveable() == true)
{
clean();
a0++; a1++; a2++; a3++;
}
}
bool fall_moveable()
{
if (map[a2 + 1][b2] == 0&&map[a3+1][b3]==0)
return true;
else return false;
}
bool laft_moveable()
{
if (map[a0][b0 - 1] == 0 && map[a2][b2 - 1] == 0 && map[a1][b1 - 1] == 0)
return true;
else return false;
}
bool right_moveable()
{
if (map[a1][b1 + 1] == 0 && map[a3][b3 + 1] == 0 && map[a0][b0 + 1] == 0 )
return true;
else return false;
}
bool shape_is_botton_adjacent()
{
if (is_block_adjacent(a2, b2) || is_block_adjacent(a3, b3))
return true;
else return false;
}
};
class L_sha