我罗斯方块

这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzu/2020OOP
这个作业要求在哪里 https://edu.cnblogs.com/campus/fzu/2020OOP/homework/10729
这个作业的目标 实现游戏我罗斯方块,熟悉面向对象编程方法
作业正文  https://www.cnblogs.com/miaohengming/p/12838433.html
其他参考文献  
小组成员 031902614缪恒铭 031902620夏豪杰

一.游戏内容

基础内容与俄罗斯方块一样。
俄罗斯方块
区别在于,我罗斯方块是同屏幕,双人对战游戏,双方一人使用 wasd ,一人使用上下左右控制,当一名玩家消去一行,就会让另一名玩家最底下增加随机一行。
详细
以玩家一为例,AD 控制方块左右移动,W 转换方块朝向,S 快速下落,使得方块落到底端。当玩家方块填满一整行时,会消除这行方块,然后使得玩家二的方块底部随机增加一行带空格的。玩家二同理。当一名玩家方块高度达到一个高度时就会结束游戏,该玩家失败。

二.设计

玩家部分

1     bool check,check1;//检查方块还能不能下落
2     char key,key1;//用来存储按键
3     int val,val1;//用来控制下落速度
4     int fraction,fraction1;//用来存储得分
5     int checkpoint,checkpoint1;//用来存储关卡
6     int times,times1;

函数部分

包括:背景的生成,方块的生成移动消去,分数关卡更新,游戏暂停等函数

 1 void initialWindow();//初始化窗口
 2 void initialPrint();//初始化界面
 3 void gotoXY();//移动光标
 4 void nextBlock();//随机生成方块并打印到“下一个方块”位置
 5 bool collisionDetection();//检测碰撞
 6 void printBlock();//打印方块
 7 void clearBlock();//消除方块
 8 void toLeft();//左移
 9 void toRight();//右移
10 void toUp();//顺时针旋转90度
11 int toDown();//加速下落
12 void toStop();//游戏暂停
13 void gameOver();//游戏结束
14 void eliminateRow();//判断是否能消行并更新分值

方块部分

累计7种方块,19种形态,用4*4的二维数组表示

 1 int block00[4][4] = { { 10,0,0,0 },{ 1,1,1,1 },{ 0,0,0,0 },{ 0,0,0,0 } };
 2 int block01[4][4] = { { 11,0,1,0 },{ 0,0,1,0 },{ 0,0,1,0 },{ 0,0,1,0 } };
 3 int block02[4][4] = { { 12,0,0,0 },{ 0,0,0,0 },{ 1,1,1,0 },{ 0,1,0,0 } };
 4 int block03[4][4] = { { 13,0,0,0 },{ 0,1,0,0 },{ 1,1,0,0 },{ 0,1,0,0 } };
 5 int block04[4][4] = { { 14,0,0,0 },{ 0,0,0,0 },{ 0,1,0,0 },{ 1,1,1,0 } };
 6 int block05[4][4] = { { 15,0,0,0 },{ 0,1,0,0 },{ 0,1,1,0 },{ 0,1,0,0 } };
 7 int block06[4][4] = { { 16,0,0,0 },{ 0,0,0,0 },{ 1,1,1,0 },{ 1,0,0,0 } };
 8 int block07[4][4] = { { 17,0,0,0 },{ 1,1,0,0 },{ 0,1,0,0 },{ 0,1,0,0 } };
 9 int block08[4][4] = { { 18,0,0,0 },{ 0,0,0,0 },{ 0,0,1,0 },{ 1,1,1,0 } };
10 int block09[4][4] = { { 19,0,0,0 },{ 0,1,0,0 },{ 0,1,0,0 },{ 0,1,1,0 } };
11 int block10[4][4] = { { 20,0,0,0 },{ 0,0,0,0 },{ 1,1,1,0 },{ 0,0,1,0 } };
12 int block11[4][4] = { { 21,0,0,0 },{ 0,1,0,0 },{ 0,1,0,0 },{ 1,1,0,0 } };
13 int block12[4][4] = { { 22,0,0,0 },{ 0,0,0,0 },{ 1,0,0,0 },{ 1,1,1,0 } };
14 int block13[4][4] = { { 23,0,0,0 },{ 0,1,1,0 },{ 0,1,0,0 },{ 0,1,0,0 } };
15 int block14[4][4] = { { 24,0,0,0 },{ 0,0,0,0 },{ 0,1,1,0 },{ 1,1,0,0 } };
16 int block15[4][4] = { { 25,0,0,0 },{ 1,0,0,0 },{ 1,1,0,0 },{ 0,1,0,0 } };
17 int block16[4][4] = { { 26,0,0,0 },{ 0,0,0,0 },{ 1,1,0,0 },{ 0,1,1,0 } };
18 int block17[4][4] = { { 27,0,0,0 },{ 0,0,1,0 },{ 0,1,1,0 },{ 0,1,0,0 } };
19 int block18[4][4] = { { 28,0,0,0 },{ 0,0,0,0 },{ 1,1,0,0 },{ 1,1,0,0 } };

背景部分

void initialPrint()函数,利用gotoXY函数让光标在特定位置打印背景图案;

 1 HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);//获取标准输出设备句柄
 2 void initialPrint(HANDLE hOut)
 3 {
 4     SetConsoleTextAttribute(hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
 5     for (int i = 0; i < 20; ++i)
 6     cout << "■                    ■☆                            ☆■                    ■" << endl;
 7     gotoXY(hOut, 26, 0);
 8     cout << "☆☆☆☆☆☆☆☆☆☆☆☆☆☆";
 9     gotoXY(hOut, 0, 20);
10     cout << "■■■■■■■■■■■■☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆■■■■■■■■■■■■";
11     gotoXY(hOut, 26, 2);
12     cout << "分  数:      ";
13     gotoXY(hOut, 26, 3);
14     cout << "关  卡:      ";
15     gotoXY(hOut, 40, 2);
16     cout << "分  数:      ";
17     gotoXY(hOut, 40, 3);
18     cout << "关  卡:      ";
19     gotoXY(hOut, 26, 4);
20     cout << "下一方块:";
21     gotoXY(hOut, 40, 4);
22     cout << "下一方块:";
23     gotoXY(hOut, 26, 9);
24     cout << "操作方法:";
25     gotoXY(hOut, 30, 11);
26     cout << "玩家 1:↑←↓→";
27     gotoXY(hOut, 30, 12);
28     cout << "玩家 2:w a s d ";
29     gotoXY(hOut, 30, 13);
30     cout << "空格键:开始/暂停";
31     gotoXY(hOut, 30, 14);
32     cout << "Esc 键:退出";
33     gotoXY(hOut, 26, 16);
34     /*cout << "作者:031902614缪恒铭";
35     gotoXY(hOut, 32, 17);
36     cout << "031902620夏豪杰";*/
37     SetConsoleTextAttribute(hOut, FOREGROUND_GREEN);
38     gotoXY(hOut, 26, 1);
39     cout << "玩  家1";
40     SetConsoleTextAttribute(hOut, FOREGROUND_RED);
41     gotoXY(hOut, 40, 1);
42     cout << "玩  家2";
43 }
1 void gotoXY(HANDLE hOut, int x, int y)
2 {
3     COORD pos;
4     pos.X = x;
5     pos.Y = y;
6     SetConsoleCursorPosition(hOut, pos);
7 }

三.游戏界面示意图

 

原文地址:https://www.cnblogs.com/miaohengming/p/12838433.html