这个作业属于哪个课程 | 2020面向对象程序设计 |
---|---|
这个作业要求在哪里 | https://edu.cnblogs.com/campus/fzu/2020OOP/homework/10759 |
这个作业的目标 | 1.初步设计方块 2.初始界面 |
小组成员 | 031902231 郑霖睿 031902220 汪鸿宇 031902212 林炳灿 |
这次初步设计了方块的设计 |
include "block.h"
#include<string.h>
#include <stdlib.h>
#include <time.h>
#include <cstdlib>
block::block(){ //初始化方块
//数轴 [x][y]
//[x]
// 0 1 2 3 [y]
// 1
// 2
// 3
memset(Block_1 ,0 , sizeof(Block_1[4][4][4]));
Block_1[0][2][0] = 0; //0 0 0 0
Block_1[0][2][1] = 0; //0 0 0 0
Block_1[0][3][0] = 0; //1 1 0 0
Block_1[0][3][1] = 0; //1 1 0 0
Block_1[1][2][0] = 0; //0 0 0 0
Block_1[1][2][1] = 0; //0 0 0 0
Block_1[1][3][0] = 0; //1 1 0 0
Block_1[1][3][1] = 0; //1 1 0 0
Block_1[2][2][0] = 0; //0 0 0 0
Block_1[2][2][1] = 0; //0 0 0 0
Block_1[2][3][0] = 0; //1 1 0 0
Block_1[2][3][1] = 0; //1 1 0 0
Block_1[3][2][0] = 0; //0 0 0 0
Block_1[3][2][1] = 0; //0 0 0 0
Block_1[3][3][0] = 0; //1 1 0 0
Block_1[3][3][1] = 0; //1 1 0 0
memset(Block_2 ,0 , sizeof(Block_2[4][4][4]));
Block_2[0][0][0] = 1; //1 0 0 0
Block_2[0][1][0] = 1; //1 0 0 0
Block_2[0][2][0] = 1; //1 0 0 0
Block_2[0][3][0] = 1; //1 0 0 0
Block_2[1][0][0] = 1; //1 1 1 1
Block_2[1][0][1] = 1; //0 0 0 0
Block_2[1][0][2] = 1; //0 0 0 0
Block_2[1][0][3] = 1; //0 0 0 0
Block_2[2][0][0] = 1; //1 0 0 0
Block_2[2][1][0] = 1; //1 0 0 0
Block_2[2][2][0] = 1; //1 0 0 0
Block_2[2][3][0] = 1; //1 0 0 0
Block_2[3][0][0] = 1; //1 1 1 1
Block_2[3][0][1] = 1; //0 0 0 0
Block_2[3][0][2] = 1; //0 0 0 0
Block_2[3][0][3] = 1; //0 0 0 0
memset(Block_3 ,0 , sizeof(Block_3[4][4][4]));
Block_3[0][1][0] = 1; //0 0 0 0
Block_3[0][2][0] = 1; //1 0 0 0
Block_3[0][3][0] = 1; //1 0 0 0
Block_3[0][3][1] = 1; //1 1 0 0
Block_3[1][2][0] = 1; //0 0 0 0
Block_3[1][2][1] = 1; //0 0 0 0
Block_3[1][2][2] = 1; //1 1 1 0
Block_3[1][3][0] = 1; //1 0 0 0
Block_3[2][1][0] = 1; //0 0 0 0
Block_3[2][1][1] = 1; //1 1 0 0
Block_3[2][2][1] = 1; //0 1 0 0
Block_3[2][3][1] = 1; //0 1 0 0
Block_3[3][2][0] = 1; //0 0 0 0
Block_3[3][3][0] = 1; //0 0 0 0
Block_3[3][3][1] = 1; //1 0 0 0
Block_3[3][3][2] = 1; //1 1 1 0
memset(Block_4 ,0 , sizeof(Block_4[4][4][4]));
Block_4[0][2][0] = 1; //0 0 0 0
Block_4[0][2][0] = 1; //0 1 0 0
Block_4[0][2][0] = 1; //0 1 0 0
Block_4[0][2][0] = 1; //1 1 0 0
Block_4[1][2][0] = 1; //0 0 0 0
Block_4[1][3][0] = 1; //0 0 0 0
Block_4[1][3][1] = 1; //1 0 0 0
Block_4[1][3][2] = 1; //1 1 1 0
Block_4[2][1][0] = 1; //0 0 0 0
Block_4[2][1][1] = 1; //1 1 0 0
Block_4[2][2][0] = 1; //1 0 0 0
Block_4[2][3][0] = 1; //1 0 0 0
Block_4[3][1][0] = 1; //0 0 0 0
Block_4[3][1][0] = 1; //0 0 0 0
Block_4[3][1][0] = 1; //1 1 1 0
Block_4[3][1][0] = 1; //0 0 1 0
memset(Block_5 ,0 , sizeof(Block_5[4][4][4]));
Block_5[0][2][1] = 1; //0 0 0 0
Block_5[0][3][0] = 1; //0 0 0 0
Block_5[0][3][1] = 1; //0 1 0 0
Block_5[0][3][2] = 1; //1 1 1 0
Block_5[1][1][1] = 1; //0 0 0 0
Block_5[1][2][1] = 1; //0 1 0 0
Block_5[1][2][2] = 1; //0 1 1 0
Block_5[1][3][1] = 1; //0 1 0 0
Block_5[2][2][0] = 1; //0 0 0 0
Block_5[2][2][1] = 1; //0 0 0 0
Block_5[2][2][2] = 1; //1 1 1 0
Block_5[2][3][1] = 1; //0 1 0 0
Block_5[3][1][1] = 1; //0 0 0 0
Block_5[3][2][0] = 1; //0 1 0 0
Block_5[3][2][1] = 1; //1 1 0 0
Block_5[3][3][1] = 1; //0 1 0 0
memset(Block_6 ,0 , sizeof(Block_6[4][4][4]));
Block_6[0][2][0] = 1; //0 0 0 0
Block_6[0][2][1] = 1; //0 0 0 0
Block_6[0][3][1] = 1; //1 1 0 0
Block_6[0][3][2] = 1; //0 1 1 0
Block_6[1][2][0] = 1; //0 0 0 0
Block_6[1][2][1] = 1; //0 1 0 0
Block_6[1][3][1] = 1; //1 1 0 0
Block_6[1][3][2] = 1; //1 0 0 0
Block_6[2][2][0] = 1; //0 0 0 0
Block_6[2][2][1] = 1; //0 0 0 0
Block_6[2][3][1] = 1; //1 1 0 0
Block_6[2][3][2] = 1; //0 1 1 0
Block_6[3][2][0] = 1; //0 0 0 0
Block_6[3][2][1] = 1; //0 1 0 0
Block_6[3][3][1] = 1; //1 1 0 0
Block_6[3][3][2] = 1; //1 0 0 0
memset(Block_7 ,0 , sizeof(Block_7[4][4][4]));
Block_7[0][2][0] = 1; //0 0 0 0
Block_7[0][2][1] = 1; //0 0 0 0
Block_7[0][3][1] = 1; //0 1 1 0
Block_7[0][3][2] = 1; //1 1 0 0
Block_7[1][2][0] = 1; //0 0 0 0
Block_7[1][2][1] = 1; //1 0 0 0
Block_7[1][3][1] = 1; //1 1 0 0
Block_7[1][3][2] = 1; //0 1 0 0
Block_7[2][2][0] = 1; //0 0 0 0
Block_7[2][2][1] = 1; //0 0 0 0
Block_7[2][3][1] = 1; //0 1 1 0
Block_7[2][3][2] = 1; //1 1 0 0
Block_7[3][2][0] = 1; //0 0 0 0
Block_7[3][2][1] = 1; //1 0 0 0
Block_7[3][3][1] = 1; //1 1 0 0
Block_7[3][3][2] = 1; //0 1 0 0
}
void block::Create_Block(){ //创建新方块
srand((unsigned)time(NULL)); //初始化随机数
switch (rand()%7)
{
case 0:{
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
BlockNext[i][j]=Block_1[0][i][j];
}
}
}
case 1:{
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
BlockNext[i][j]=Block_2[0][i][j];
}
}
}
case 2:{
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
BlockNext[i][j]=Block_3[0][i][j];
}
}
}
case 3:{
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
BlockNext[i][j]=Block_4[0][i][j];
}
}
}
case 4:{
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
BlockNext[i][j]=Block_5[0][i][j];
}
}
}
case 5:{
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
BlockNext[i][j]=Block_6[0][i][j];
}
}
}
case 6:{
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
BlockNext[i][j]=Block_7[0][i][j];
}
}
}
}
}
void block::Change_Block(){
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
BlockNow[i][j]=BlockNext[i][j];
}
}
Create_Block();
}
void block::Start_Block(){
Create_Block();
Change_Block();
}
还有了解到了 SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
使光标 (xy)位置函数.
调用 COORD 需要#include<windows.h>
void inter_face()//界面
{ int i,j;
for(i=0;i<FACE_X;i++)
{ for(j=0;j<FACE_Y+10;j++)
{ if(j==0 || j==FACE_Y-1 || j==FACE_Y+9)
{ face.data[i][j]=Wall;
gotoxy(i,2*j);
printf("■");
}
else if(i==FACE_X-1)
{ face.data[i][j]=Box;
gotoxy(i,2*j);
printf("■");
}
else
face.data[i][j]=Kong;
}
}
gotoxy(FACE_X-18,2*FACE_Y+2);
printf("左移:←");
gotoxy(FACE_X-16,2*FACE_Y+2);
printf("右移:→");
gotoxy(FACE_X-14,2*FACE_Y+2);
printf("旋转:space");
gotoxy(FACE_X-12,2*FACE_Y+2);
printf("暂停: S");
gotoxy(FACE_X-10,2*FACE_Y+2);
printf("退出: ESC");
gotoxy(FACE_X-8,2*FACE_Y+2);
printf("重新开始:R");
}
暂时实现到这里,接下来就是设计两个玩家的页面
还有对于方块如何下落
方块下落速度的控制
如何才能够消去行数。