⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 model.cpp

📁 俄罗斯方块,带背景音乐,带扩展窗口,操作同qq游戏的疯狂俄罗斯
💻 CPP
字号:
// Model.cpp: implementation of the Model class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TE.h"
#include "Model.h"
#include<time.h>
#include <stdlib.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Model::~Model()
{

}

/*-----------------------copy constructou-------------------*/
Model::Model(const Model &rhs){
	for(int i=0;i<16;i++){
		_Mod[i]=rhs._Mod[i];
	}
	_Creat=rhs._Creat;
}
/*----------------------constructor-----------------------*/
Model::Model(){



	_Creat =((float)rand() / (float)RAND_MAX) * 6 + 0.5	;

	for(int i=0;i<16;i++)
		_Mod[i]=0;
	switch(_Creat){
	case 0:{
			for(int i=0;i<4;i++)                        // @@@@
				_Mod[4*i+1]=1;
			break;
		   }
		case 1:
			_Mod[10]=1;									//   @
			_Mod[12]=1;_Mod[13]=1;_Mod[14]=1;           // @@@
			break;
		case 2:
			_Mod[8]=1;                                  // @
			_Mod[12]=1;_Mod[13]=1;_Mod[14]=1;           // @@@
			break;
		case 3:
			_Mod[9]=1;_Mod[10]=1;                       //  @@
			_Mod[12]=1;_Mod[13]=1;                      // @@
			break;
		case 4:
			_Mod[8]=1;_Mod[9]=1;                        // @@
			_Mod[13]=1;_Mod[14]=1;                      //  @@
			break;
		case 5:
			_Mod[8]=1;_Mod[9]=1;                        //  @@
			_Mod[12]=1;_Mod[13]=1;                      //  @@
			break;
		case 6:
			_Mod[9]=1 ;                                 //  @
			_Mod[12]=1;_Mod[13]=1 ;_Mod[14]=1;          // @@@
			break;
		default:
			exit(0);
	}
}
/*--------------------turn model value(1)ture,value(0)false---------------------*/
int *Model::turn(int value){
	if(_Creat==5)
		return _Mod;
	int Last[16];
	for(int q=0;q<16;q++)
		Last[q]=_Mod[q];
	int LeftLine=0;
	int RightLine=0;
	for(int i=0;i<4;i++){
		LeftLine=Last[i*4]+LeftLine;
		RightLine=Last[i*4+3]+RightLine;
	}
	if(_Creat==0){
		if(LeftLine!=0&&RightLine!=0){
			for(int j=0;j<16;j++){
				Last[j]=0;
			}
			for(int i=0;i<4;i++){
				Last[i*4+1]=1;
			}
		}
		else{
			for(int j=0;j<16;j++){
				Last[j]=0;
			}
			for(int i=0;i<4;i++){
				Last[12+i]=1;
			}
		}
	    LeftLine=1;RightLine=1;
	}
	if(RightLine==0){
		int temp1=Last[4];
		Last[4]=Last[6];
		int temp2=Last[12];
		Last[12]=temp1;
		temp1=Last[14];
		Last[14]=temp2;
		Last[6]=temp1;
		temp1=Last[8];
		Last[8]=Last[5];
		temp2=Last[13];
		Last[13]=temp1;
		temp1=Last[10];
		Last[10]=temp2;
		Last[5]=temp1;
		LeftLine=1;
	}
	if(LeftLine==0){
		int temp1=Last[5];
		Last[5]=Last[7];
		int temp2=Last[13];
		Last[13]=temp1;
		temp1=Last[15];
		Last[15]=temp2;
		Last[7]=temp1;
		temp1=Last[6];
		Last[6]=Last[11];
		temp2=Last[9];
		Last[9]=temp1;
		temp1=Last[14];
		Last[14]=temp2;
		Last[11]=temp1;
	}
	int tmp=Last[12]+Last[13]+Last[14]+Last[15];
	if(tmp==0){
		for(i=0;i<3;i++){
			Last[12-i*4]=Last[8-i*4];
			Last[13-i*4]=Last[9-i*4];
			Last[14-i*4]=Last[10-i*4];
			Last[15-i*4]=Last[11-i*4];
		}
	}
//there:
	if(value!=0){
		for(int q=0;q<16;q++)
			_Mod[q]=Last[q];
	}
	return Last;
}

/*--------------------------------Move Left--------------------------------*/
void Model::MoveLeft(){
	int ed=0;
	for(int c=0;c<4;c++){
		ed=_Mod[c*4];
		if(ed!=0)
			return;
	}
	for(int i=0;i<4;i++){
		int temp=_Mod[i*4];
		_Mod[i*4]=_Mod[1+i*4];
		_Mod[1+i*4]=_Mod[2+i*4];
		_Mod[2+i*4]=_Mod[3+i*4];
		_Mod[3+i*4]=temp;
	}
	return;
}
/*--------------------------------Move Right-------------------------------*/
void Model::MoveRight(){
	int ed=0;
	for(int c=0;c<4;c++){
		ed=_Mod[c*4+3];
		if(ed!=0){return;}
	}
	for(int i=0;i<4;i++){
		int temp=_Mod[i*4+3];
		_Mod[i*4+3]=_Mod[i*4+2];
		_Mod[i*4+2]=_Mod[i*4+1];
		_Mod[i*4+1]=_Mod[i*4];
		_Mod[i*4]=temp;
	}
	return;
}
/*---------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -