cocos3.10俄罗斯方块规则核心源码

来源:互联网 发布:apache cgi bin 编辑:程序博客网 时间:2024/06/09 19:43

源码和apk地址:http://download.csdn.net/download/u012942555/10050955

网盘地址:https://pan.baidu.com/s/1pKROKmn

#include "GameRule.h"

#include "GlobalDefine.h"


USING_NS_CC;


GameRule* GameRule::_gameRuleInstance = nullptr;


GameRule::GameRule(){}


GameRule::~GameRule(){}


GameRule* GameRule::getInstance()

{

if (!_gameRuleInstance)

{

_gameRuleInstance = new (std::nothrow) GameRule();

CCASSERT(_gameRuleInstance, "FATAL: Not enough memory");

//_gameRuleInstance->autorelease();

_gameRuleInstance->init();

}

return _gameRuleInstance;

}



bool GameRule::init()

{

if (!Node::init())

{

returnfalse;

}


for (int i =0; i < MAXROWS; i++)

{

_bIsOccupy[i].isEmpty = MAP_STATUS_EMPTY;

_bIsOccupy[i].rectType = ONE;

}


returntrue;

}


int GameRule::randomCustom(int number)

{

return rand() % number +1;//≤˙…˙Àʪ˙ ˝

}


//∏flº∂ƒ£ Ωœ¬£∫1-5(1-8)  6-10(1-9) 11-15(1-10) 15-20(1-12)

int GameRule::randomCustom(bool isHigh,int level,bool &isFirstDown,int number)

{

// srand((unsigned)time(NULL));//≤øœ¬Àʪ˙÷÷◊”

if (isHigh)//»Áπ˚ «∏flº∂ƒ£ Ω

{

//»Áπ˚ «µ⁄“ª¥ŒµÙ¬‰≤ªª·≥ˆœ÷∫Û5÷÷«Èøˆ

if (isFirstDown)

{

isFirstDown = false

return randomCustom(number); 

}

else

{

//∏˘æ›tempªÆ∑÷≥ˆœ÷µƒ∏≈¬ 

int tempPercent = randomCustom(100);

if (tempPercent <95)

return randomCustom(number); 

}

else

{

if (level<=5)

return 8

}

else if (level>=6 && level<=10)

{

return randomCustom(2) +7;//8\9

}

else if (level >= 11 && level <= 15)

{

return randomCustom(3) +7;//8\9\10

}

else if (level >= 16)

{

int temp = randomCustom(5) +7;//8\9\10\11\12

if (temp !=11) {return temp; }

else {return111; }//»Áπ˚ «11£¨∑µªÿ111£¨±‹√‚∫Õ11≥ÂÕª

}

}

}

}

else

return randomCustom(number); 

}


return randomCustom(number);

}


//∆’Õ®ƒ£ Ω∫Õ∏flº∂ƒ£ Ω∂ºÀʪ˙…˙≥…∑ΩøÈ1-5(0-2) 5-10(3-5) 11-15(6-8) 16-20(9-10)£¨√ø“ª––Àʪ˙…˙≥…4-8∏ˆŒª÷√

void GameRule::initRandomRect(int level, MapStatus mapStatus[MAXROWS][COLS])

{

srand((unsigned)time(NULL));//≤øœ¬Àʪ˙÷÷◊”

int rows =0;int cols = randomCustom(4) +4;

if (level <=5)

{

rows = randomCustom(3) -1;

for (int i =0; i <= rows; i++)

{

for (int j =0; j <= cols; j++)

{

int col = randomCustom(10) -1;

mapStatus[i][col].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[i][col].rectType = (RectType)randomCustom(7);

}

}

}

else if (level >= 6 && level <= 10)

{

rows = randomCustom(3) +2;

for (int i =0; i <= rows; i++)

{

for (int j =0; j <= cols; j++)

{

int col = randomCustom(10) -1;

mapStatus[i][col].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[i][col].rectType = (RectType)randomCustom(7);

}

}

}

else if (level >= 11 && level <= 15)

{

rows = randomCustom(3) +5;

for (int i =0; i <= rows; i++)

{

for (int j =0; j <= cols; j++)

{

int col = randomCustom(10) -1;

mapStatus[i][col].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[i][col].rectType = (RectType)randomCustom(7);

}

}

}

else if (level >= 16)

{

rows = randomCustom(2) +8;

for (int i =0; i <= rows; i++)

{

for (int j =0; j <= cols; j++)

{

int col = randomCustom(10) -1;

mapStatus[i][col].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[i][col].rectType = (RectType)randomCustom(7);

}

}

}

}


void GameRule::bonus()

{


}


void GameRule::initVariables(int iInterFace[INTERFACE_ROW][4], MapStatus mapStatus[MAXROWS][COLS])

{

//∏≥≥ı÷µ

for (int i =0; i < MAXROWS; i++)

{

for (int j =0; j < COLS; j++)

{

mapStatus[i][j].isEmpty = MAP_STATUS_EMPTY;

mapStatus[i][j].rectType = ONE;

}

}

//∏˜÷÷–Œ◊¥∑ΩøȵƒΩ”¥•√Ê ˝æ›,»Áπ˚ƒ≥÷÷–Œ◊¥µƒ∑ΩøÈ√ª”–4∏ˆΩ”¥•√Ê£¨‘Ú∫Û√ʵƒ ˝æ›ÃÓ-1

for (int i =0; i < INTERFACE_ROW; i++)

{

for (int j =0; j <4; j++)

{

iInterFace[i][j] = -1;

}

}

/*1----*/

iInterFace[1][0] =3;// ˙|

iInterFace[11][0] =0;iInterFace[11][1] =1;iInterFace[11][2] =2;iInterFace[11][3] =3;//∫·----

/*2’˝∑Ω–Œ*/

iInterFace[2][0] =1;iInterFace[2][1] =3;

/*3Õ¡*/

iInterFace[3][0] =0;iInterFace[3][1] =2;iInterFace[3][2] =3;

iInterFace[31][0] =2;iInterFace[31][1] =3;

iInterFace[32][0] =0;iInterFace[32][1] =2;iInterFace[32][2] =3;

iInterFace[33][0] =0;iInterFace[33][1] =3;

/*4*/

iInterFace[4][0] =1;iInterFace[4][1] =3;

iInterFace[41][0] =0;iInterFace[41][1] =2;iInterFace[41][2] =3;

/*5*/

iInterFace[5][0] =1;iInterFace[5][1] =3;

iInterFace[51][0] =0;iInterFace[51][1] =2;iInterFace[51][2] =3;

/*6*/

iInterFace[6][0] =0;iInterFace[6][1] =3;

iInterFace[61][0] =0;iInterFace[61][1] =1;iInterFace[61][2] =3;

iInterFace[62][0] =2;iInterFace[62][1] =3;

iInterFace[63][0] =1;iInterFace[63][1] =2;iInterFace[63][2] =3;

/*7*/

iInterFace[7][0] =2;iInterFace[7][1] =3;

iInterFace[71][0] =0;iInterFace[71][1] =1;iInterFace[71][2] =3;

iInterFace[72][0] =0;iInterFace[72][1] =3;

iInterFace[73][0] =1;iInterFace[73][1] =2;iInterFace[73][2] =3;


/*8*/

iInterFace[8][0] =0;

/*9*/

iInterFace[9][0] =1;

/*10*/

iInterFace[10][0] =2;

/*11*/

iInterFace[111][0] =0;

/*12*/

iInterFace[12][0] =0;

}


/* * * * * * * * * * * * * * * * * * * * * *

* ƒ⁄≤ø∫Ø ˝£∫≥ı ºµÙ¬‰ ±£¨Ω´∏˘æ›∑Ωøȵƒ—˘ Ωæˆ∂®µ±«∞∂Øè ˝◊ȵƒ÷µ

*

* ◊Ó∫Û–fi∏ƒ»’∆⁄£∫2016.1.1

* * * * * * * * * * * * * * * * * * * * * */

void GameRule::rectStatusToActiveStatus(int type,int activeStatus[4][2])

{

switch (type)

{

case1:// ˝◊È¥Ê∑≈œ»y––∫Ûx¡– »Á£®5,19£©

activeStatus[0][0] = ROWS -1 +3;activeStatus[0][1] =5;activeStatus[1][0] = ROWS -2 +3;activeStatus[1][1] =5;

activeStatus[2][0] = ROWS -3 +3;activeStatus[2][1] =5;activeStatus[3][0] = ROWS -4 +3;activeStatus[3][1] =5;

break;

case2:

activeStatus[0][0] = ROWS -1 +1;activeStatus[0][1] =5;activeStatus[1][0] = ROWS -2 +1;activeStatus[1][1] =5;

activeStatus[2][0] = ROWS -1 +1;activeStatus[2][1] =6;activeStatus[3][0] = ROWS -2 +1;activeStatus[3][1] =6;

break;

case3:

activeStatus[0][0] = ROWS -2 +1;activeStatus[0][1] =4;activeStatus[1][0] = ROWS -1 +1;activeStatus[1][1] =5;

activeStatus[2][0] = ROWS -2 +1;activeStatus[2][1] =5;activeStatus[3][0] = ROWS -2 +1;activeStatus[3][1] =6;

break;

case4:

activeStatus[0][0] = ROWS -1 +2;activeStatus[0][1] =5;activeStatus[1][0] = ROWS -2 +2;activeStatus[1][1] =5;

activeStatus[2][0] = ROWS -2 +2;activeStatus[2][1] =6;activeStatus[3][0] = ROWS -3 +2;activeStatus[3][1] =6;

break;

case5:

activeStatus[0][0] = ROWS -2 +2;activeStatus[0][1] =5;activeStatus[1][0] = ROWS -3 +2;activeStatus[1][1] =5;

activeStatus[2][0] = ROWS -1 +2;activeStatus[2][1] =6;activeStatus[3][0] = ROWS -2 +2;activeStatus[3][1] =6;

break;

case6:

activeStatus[0][0] = ROWS -1 +2;activeStatus[0][1] =5;activeStatus[1][0] = ROWS -1 +2;activeStatus[1][1] =6;

activeStatus[2][0] = ROWS -2 +2;activeStatus[2][1] =6;activeStatus[3][0] = ROWS -3 +2;activeStatus[3][1] =6;

break;

case7:

activeStatus[0][0] = ROWS -1 +2;activeStatus[0][1] =5;activeStatus[1][0] = ROWS -2 +2;activeStatus[1][1] =5;

activeStatus[2][0] = ROWS -3 +2;activeStatus[2][1] =5;activeStatus[3][0] = ROWS -1 +2;activeStatus[3][1] =6;

break;

//∫Û5÷÷ƒ£ Ω

case8:

activeStatus[0][0] = ROWS -1;activeStatus[0][1] =5;activeStatus[1][0] = ROWS -1;activeStatus[1][1] =5;

activeStatus[2][0] = ROWS -1;activeStatus[2][1] =5;activeStatus[3][0] = ROWS -1;activeStatus[3][1] =5;

break;

case9:

activeStatus[0][0] = ROWS -1 +1; activeStatus[0][1] =5;activeStatus[1][0] = ROWS -2 +1; activeStatus[1][1] =5;

activeStatus[2][0] = ROWS -2 +1; activeStatus[2][1] =5;activeStatus[3][0] = ROWS -2 +1; activeStatus[3][1] =5;

break;

case10:

activeStatus[0][0] = ROWS -1 +2; activeStatus[0][1] =5; activeStatus[1][0] = ROWS -2 + 2; activeStatus[1][1] =5;

activeStatus[2][0] = ROWS -3 +2; activeStatus[2][1] =5; activeStatus[3][0] = ROWS -3 + 2; activeStatus[3][1] =5;

break;

case111:

activeStatus[0][0] = ROWS -1;activeStatus[0][1] =5;activeStatus[1][0] = ROWS -1;activeStatus[1][1] =5;

activeStatus[2][0] = ROWS -1;activeStatus[2][1] =5;activeStatus[3][0] = ROWS -1;activeStatus[3][1] =5;

break;

case12:

activeStatus[0][0] = ROWS -1;activeStatus[0][1] =5;activeStatus[1][0] = ROWS -1;activeStatus[1][1] =5;

activeStatus[2][0] = ROWS -1;activeStatus[2][1] =5;activeStatus[3][0] = ROWS -1;activeStatus[3][1] =5;

break;

default:

break;

}

}


int GameRule::convertStatus(int currentStatus)

{

if (1 == currentStatus ||11 == currentStatus){return 1; }

else if (2 == currentStatus){ return 2; }

else if (3 == currentStatus || 31 == currentStatus || 32 == currentStatus ||33 == currentStatus){return 3; }

else if (4 == currentStatus || 41 == currentStatus){ return 4; }

else if (5 == currentStatus || 51 == currentStatus){ return 5; }

else if (6 == currentStatus || 61 == currentStatus || 62 == currentStatus ||63 == currentStatus){return 6; }

else if (7 == currentStatus || 71 == currentStatus || 72 == currentStatus ||73 == currentStatus){return 7; }

else if (8 == currentStatus) { return 8; }

else if (9 == currentStatus){ return 9; }

else if (10 == currentStatus) { return 10; }

else if (111 == currentStatus){ return 11; }

else if (12 == currentStatus){ return 12; }

else{return1; }

}


/* * * * * * * * * * * * * * * * * * * * * *

* ƒ⁄≤ø∫Ø ˝£∫Ω´µ±«∞œ¬◊πŒÔµƒŒª÷√”≥…‰µΩ”Œœ∑«¯”ÚµÿÕº ˝◊È÷–»•

*

* ◊Ó∫Û–fi∏ƒ»’∆⁄£∫2016.1.1

* * * * * * * * * * * * * * * * * * * * * */

void GameRule::activeStatusToMapStatus(int currentStatus,int activeStatus[4][2], MapStatus mapStatus[MAXROWS][COLS])

{

int x1, x2, x3, x4, y1, y2, y3, y4;

x1 = activeStatus[0][0]; y1 = activeStatus[0][1];

x2 = activeStatus[1][0]; y2 = activeStatus[1][1];

x3 = activeStatus[2][0]; y3 = activeStatus[2][1];

x4 = activeStatus[3][0]; y4 = activeStatus[3][1];

int tempStatus = convertStatus(currentStatus);

mapStatus[x1][y1].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x1][y1].rectType = (RectType)tempStatus;

mapStatus[x2][y2].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x2][y2].rectType = (RectType)tempStatus;

mapStatus[x3][y3].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x3][y3].rectType = (RectType)tempStatus;

mapStatus[x4][y4].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x4][y4].rectType = (RectType)tempStatus;


if (8 == currentStatus)

{

recordColumn(activeStatus, mapStatus);

}

}


void GameRule::recordColumn(int activeStatus[4][2], MapStatus mapStatus[MAXROWS][COLS])

{

int x1 = activeStatus[0][0];int y1 = activeStatus[0][1];

for (int i =0; i < MAXROWS; i++)

{

_bIsOccupy[i].isEmpty = MAP_STATUS_EMPTY;

_bIsOccupy[i].rectType = ONE;

}


for (int i =0; i < MAXROWS; i++)

{

if (mapStatus[i][y1].isEmpty == MAP_STATUS_NOT_EMPTY && (i != x1))

{

_bIsOccupy[i].isEmpty = MAP_STATUS_NOT_EMPTY;

_bIsOccupy[i].rectType = mapStatus[i][y1].rectType;

}

}

}


void GameRule::onLeft(int activeStatus[4][2], MapStatus mapStatus[MAXROWS][COLS],int currentStatus, bool bIsBottom)

{

//ªÒ»°µ±«∞œ¬◊πŒÔ4∏ˆ–°∑ΩøȵƒŒª÷√◊¯±Í

int x1, x2, x3, x4, y1, y2, y3, y4;

x1 = activeStatus[0][0]; y1 = activeStatus[0][1];//19,5

x2 = activeStatus[1][0]; y2 = activeStatus[1][1];

x3 = activeStatus[2][0]; y3 = activeStatus[2][1];

x4 = activeStatus[3][0]; y4 = activeStatus[3][1];

if ((activeStatus[0][1] >0) && isLeftLimit(activeStatus, mapStatus, currentStatus) && !bIsBottom)

{

//«Â‘≠¿¥µƒ∑ΩøÈ

mapStatus[x1][y1].isEmpty = MAP_STATUS_EMPTY;

mapStatus[x2][y2].isEmpty = MAP_STATUS_EMPTY;

mapStatus[x3][y3].isEmpty = MAP_STATUS_EMPTY;

mapStatus[x4][y4].isEmpty = MAP_STATUS_EMPTY;

//“∆∂Ø∫Û ˝æ›◊¥Ã¨

activeStatus[0][1] -=1;

activeStatus[1][1] -=1;

activeStatus[2][1] -=1;

activeStatus[3][1] -=1;

mapStatus[x4][y4 - 1].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x4][y4 - 1].rectType = mapStatus[x4][y4].rectType;

mapStatus[x3][y3 - 1].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x3][y3 - 1].rectType = mapStatus[x3][y3].rectType;

mapStatus[x2][y2 - 1].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x2][y2 - 1].rectType = mapStatus[x2][y2].rectType;

mapStatus[x1][y1 - 1].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x1][y1 - 1].rectType = mapStatus[x1][y1].rectType;

if (8 == currentStatus)

{

recordColumn(activeStatus, mapStatus);

}

}

}


//œÚ”““∆∂Ø

void GameRule::onRight(int activeStatus[4][2], MapStatus mapStatus[MAXROWS][COLS],int currentStatus, bool bIsBottom)

{

//ªÒ»°µ±«∞œ¬◊πŒÔ4∏ˆ–°∑ΩøȵƒŒª÷√◊¯±Í

int x1, x2, x3, x4, y1, y2, y3, y4;

x1 = activeStatus[0][0]; y1 = activeStatus[0][1];

x2 = activeStatus[1][0]; y2 = activeStatus[1][1];

x3 = activeStatus[2][0]; y3 = activeStatus[2][1];

x4 = activeStatus[3][0]; y4 = activeStatus[3][1];

if ((activeStatus[3][1] < COLS -1) && isRightLimit(activeStatus, mapStatus, currentStatus) && !bIsBottom)

{

//«Â‘≠¿¥µƒ∑ΩøÈ

mapStatus[x1][y1].isEmpty = MAP_STATUS_EMPTY;

mapStatus[x2][y2].isEmpty = MAP_STATUS_EMPTY;

mapStatus[x3][y3].isEmpty = MAP_STATUS_EMPTY;

mapStatus[x4][y4].isEmpty = MAP_STATUS_EMPTY;

//Ã̺”–¬µƒ“∆∂Ø∫Û ˝æ›◊¥Ã¨

activeStatus[0][1] +=1;

activeStatus[1][1] +=1;

activeStatus[2][1] +=1;

activeStatus[3][1] +=1;

mapStatus[x4][y4 + 1].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x4][y4 + 1].rectType = mapStatus[x4][y4].rectType;

mapStatus[x3][y3 + 1].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x3][y3 + 1].rectType = mapStatus[x3][y3].rectType;

mapStatus[x2][y2 + 1].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x2][y2 + 1].rectType = mapStatus[x2][y2].rectType;

mapStatus[x1][y1 + 1].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x1][y1 + 1].rectType = mapStatus[x1][y1].rectType;

if (8 == currentStatus)

{

recordColumn(activeStatus, mapStatus);

}

}

}


/* * * * * * * * * * * * * * * * * * * * * *

* ƒ⁄≤ø∫Ø ˝£∫∑ΩøÈ «∑Òªπø…“‘◊Û“∆

*

* ◊Ó∫Û–fi∏ƒ»’∆⁄£∫2016.1.1

* * * * * * * * * * * * * * * * * * * * * */

bool GameRule::isLeftLimit(int activeStatus[4][2], MapStatus mapStatus[MAXROWS][COLS],int currentStatus)

{

int x1, x2, x3, x4, y1, y2, y3, y4;

x1 = activeStatus[0][0]; y1 = activeStatus[0][1];

x2 = activeStatus[1][0]; y2 = activeStatus[1][1];

x3 = activeStatus[2][0]; y3 = activeStatus[2][1];

x4 = activeStatus[3][0]; y4 = activeStatus[3][1];

//∏˘æ›µ±«∞œ¬◊πŒÔµƒæfl֌裨∑÷Œˆ≈–∂œ∆‰ «∑Ò”–œÚ◊Û“∆∂صƒø’º‰

switch (currentStatus)

{

/*"1"◊÷–Œ–ŒÃ¨¿‡–Õ£¨≈–∂œ∆‰Àƒ∏ˆ∑Ωøȵƒ’˝◊Û±fl∂º√ª”–»Œ∫ŒŒÔº˛£®ø’º‰√ª”–±ª’ºæ›)*/

case1:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y2 -1].isEmpty || mapStatus[x3][y3 - 1].isEmpty || mapStatus[x4][y4 -1].isEmpty)

returnfalse;

break;

case11:

if (mapStatus[x1][y1 -1].isEmpty)

returnfalse;

break;

case2:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y2 -1].isEmpty)

returnfalse;

break;

case3:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y2 -1].isEmpty)

returnfalse;

break;

case31:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y2 -1].isEmpty || mapStatus[x3][y3 - 1].isEmpty)

returnfalse;

break;

case32:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x3][y3 -1].isEmpty)

returnfalse;

break;

case33:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y2 -1].isEmpty || mapStatus[x4][y4 - 1].isEmpty)

returnfalse;

break;

case4:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y2 -1].isEmpty || mapStatus[x4][y4 - 1].isEmpty)

returnfalse;

break;

case41:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y2 -1].isEmpty)

returnfalse;

break;

case5:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y2 -1].isEmpty || mapStatus[x3][y3 - 1].isEmpty)

returnfalse;

break;

case51:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x3][y3 -1].isEmpty)

returnfalse;

break;

case6:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x3][y3 -1].isEmpty || mapStatus[x4][y4 - 1].isEmpty)

returnfalse;

break;

case61:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x3][y3 -1].isEmpty)

returnfalse;

break;

case62:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y2 -1].isEmpty || mapStatus[x3][y3 - 1].isEmpty)

returnfalse;

break;

case63:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y2 -1].isEmpty)

returnfalse;

break;

case7:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y2 -1].isEmpty || mapStatus[x3][y3 - 1].isEmpty)

returnfalse;

break;

case71:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x4][y4 -1].isEmpty)

returnfalse;

break;

case72:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y2 -1].isEmpty || mapStatus[x3][y3 - 1].isEmpty)

returnfalse;

break;

case73:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y2 -1].isEmpty)

returnfalse;

break;

case8:

if (mapStatus[x1][y1 -1].isEmpty)

returnfalse;

break;

case9:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y1 -1].isEmpty)

returnfalse;

break;

case10:

if (mapStatus[x1][y1 -1].isEmpty || mapStatus[x2][y1 -1].isEmpty || mapStatus[x3][y1 - 1].isEmpty)

returnfalse;

break;

case111:

if (mapStatus[x1][y1 -1].isEmpty)

returnfalse;

break;

case12:

if (mapStatus[x1][y1 -1].isEmpty)

returnfalse;

break;

}

returntrue;

}



/* * * * * * * * * * * * * * * * * * * * * *

* ƒ⁄≤ø∫Ø ˝£∫∑ΩøÈ «∑Òªπø…“‘”““∆

*

* ◊Ó∫Û–fi∏ƒ»’∆⁄£∫2016.1.1

* * * * * * * * * * * * * * * * * * * * * */

bool GameRule::isRightLimit(int activeStatus[4][2], MapStatus mapStatus[MAXROWS][COLS],int currentStatus)

{

int x1, x2, x3, x4, y1, y2, y3, y4;

x1 = activeStatus[0][0]; y1 = activeStatus[0][1];

x2 = activeStatus[1][0]; y2 = activeStatus[1][1];

x3 = activeStatus[2][0]; y3 = activeStatus[2][1];

x4 = activeStatus[3][0]; y4 = activeStatus[3][1];

switch (currentStatus)

{

case1:

if (mapStatus[x1][y1 +1].isEmpty || mapStatus[x2][y2 +1].isEmpty || mapStatus[x3][y3 + 1].isEmpty || mapStatus[x4][y4 +1].isEmpty)

returnfalse;

break;

case11:

if (mapStatus[x4][y4 +1].isEmpty)

returnfalse;

break;

case2:

if (mapStatus[x3][y3 +1].isEmpty || mapStatus[x4][y4 +1].isEmpty)

returnfalse;

break;

case3:

if (mapStatus[x2][y2 +1].isEmpty || mapStatus[x4][y4 +1].isEmpty)

returnfalse;

break;

case31:

if (mapStatus[x1][y1 +1].isEmpty || mapStatus[x3][y3 +1].isEmpty || mapStatus[x4][y4 + 1].isEmpty)

returnfalse;

break;

case32:

if (mapStatus[x3][y3 +1].isEmpty || mapStatus[x4][y4 +1].isEmpty)

returnfalse;

break;

case33:

if (mapStatus[x2][y2 +1].isEmpty || mapStatus[x3][y3 +1].isEmpty || mapStatus[x4][y4 + 1].isEmpty)

returnfalse;

break;

case4:

if (mapStatus[x1][y1 +1].isEmpty || mapStatus[x3][y3 +1].isEmpty || mapStatus[x4][y4 + 1].isEmpty)

returnfalse;

break;

case41:

if (mapStatus[x3][y3 +1].isEmpty || mapStatus[x4][y4 +1].isEmpty)

returnfalse;

break;

case5:

if (mapStatus[x2][y2 +1].isEmpty || mapStatus[x3][y3 +1].isEmpty || mapStatus[x4][y4 + 1].isEmpty)

returnfalse;

break;

case51:

if (mapStatus[x2][y2 +1].isEmpty || mapStatus[x4][y4 +1].isEmpty)

returnfalse;

break;

case6:

if (mapStatus[x2][y2 +1].isEmpty || mapStatus[x3][y3 +1].isEmpty || mapStatus[x4][y4 + 1].isEmpty)

returnfalse;

break;

case61:

if (mapStatus[x3][y3 +1].isEmpty || mapStatus[x4][y4 +1].isEmpty)

returnfalse;

break;

case62:

if (mapStatus[x1][y1 +1].isEmpty || mapStatus[x2][y2 +1].isEmpty || mapStatus[x4][y4 + 1].isEmpty)

returnfalse;

break;

case63:

if (mapStatus[x2][y2 +1].isEmpty || mapStatus[x4][y4 +1].isEmpty)

returnfalse;

break;

case7:

if (mapStatus[x2][y2 +1].isEmpty || mapStatus[x3][y3 +1].isEmpty || mapStatus[x4][y4 + 1].isEmpty)

returnfalse;

break;

case71:

if (mapStatus[x3][y3 +1].isEmpty || mapStatus[x4][y4 +1].isEmpty)

returnfalse;

break;

case72:

if (mapStatus[x2][y2 +1].isEmpty || mapStatus[x3][y3 +1].isEmpty || mapStatus[x4][y4 + 1].isEmpty)

returnfalse;

break;

case73:

if (mapStatus[x1][y1 +1].isEmpty || mapStatus[x4][y4 +1].isEmpty)

returnfalse;

break;

case8:

if (mapStatus[x1][y1 +1].isEmpty)

returnfalse;

break;

case9:

if (mapStatus[x1][y1 +1].isEmpty || mapStatus[x2][y1 +1].isEmpty)

returnfalse;

break;

case10:

if (mapStatus[x1][y1 +1].isEmpty || mapStatus[x2][y1 +1].isEmpty || mapStatus[x3][y1 + 1].isEmpty)

returnfalse;

break;

case111:

if (mapStatus[x1][y1 +1].isEmpty)

returnfalse;

break;

case12:

if (mapStatus[x1][y1 +1].isEmpty)

returnfalse;

break;

}

returntrue;

}


//–˝◊™

void GameRule::onRotate(bool& bIsBottom,int activeStatus[4][2],int iInterFace[INTERFACE_ROW][4],

MapStatus mapStatus[MAXROWS][COLS], int& currentStatus)

{

//œ»‘§œ»±‰–Œ£¨»ª∫Û≈–∂œ±‰–Œ∫Ûµƒ∑ΩøÈ «∑Ò”–ø’º‰£¨»Á”–◊„πªø’º‰£¨‘ÚΩ¯–– µº ±‰–Œ£¨∑Ò‘Ú≤ª±‰

int xx1, xx2, xx3, xx4, yy1, yy2, yy3, yy4;

int x1, x2, x3, x4, y1, y2, y3, y4;

int tempStatus;

x1 = activeStatus[0][0]; y1 = activeStatus[0][1];

x2 = activeStatus[1][0]; y2 = activeStatus[1][1];

x3 = activeStatus[2][0]; y3 = activeStatus[2][1];

x4 = activeStatus[3][0]; y4 = activeStatus[3][1];

//±‰–Œ∫ÛŒª÷√‘⁄ ˝◊È÷–µƒ¥Ê∑≈À≥–Ú»‘–Ë◊Ò—≠œ»◊Û∫Û”“£¨‘⁄Õ¨“ª¡–÷–œ»…œ∫Ûœ¬

xx1 = x1; xx2 = x2; xx3 = x3; xx4 = x4;

yy1 = y1; yy2 = y2; yy3 = y3; yy4 = y4;

if (8 != currentStatus &&9 != currentStatus &&10 != currentStatus && 111 != currentStatus &&12 != currentStatus)

{

switch (currentStatus)

{

case1:

xx1 = x1 - 1; yy1 = y1 -1; xx3 = x3 +1; yy3 = y3 +1; xx4 = x4 +2; yy4 = y4 +2;

if (yy1 <0) { yy1++; yy2++; yy3++; yy4++; }

if (COLS == yy4){ yy1--; yy2--; yy3--; yy4--; }

if (COLS +1 == yy4) { yy1 -=2; yy2 -= 2; yy3 -=2; yy4 -= 2; }

//‘⁄◊Ó∏fl¥¶±‰ªª ±ª·ø¥≤ªµΩ£¨”¶∏√xx1 = ROWS - 1; xx2 = ROWS - 1; xx3 = ROWS - 1; xx4 = ROWS - 1;

if (xx1 > ROWS -1 && xx2 > ROWS -1 && xx3 > ROWS - 1 && xx4 > ROWS - 1)

{

xx1 = ROWS - 1; xx2 = ROWS -1; xx3 = ROWS -1; xx4 = ROWS -1;

}

tempStatus = 11;

break;

case11:

xx1 = x1 + 1; yy1 = y1 +1; xx3 = x3 -1; yy3 = y3 -1; xx4 = x4 -2; yy4 = y4 -2;

tempStatus = 1;

break;

case2:

tempStatus = 2;

break;

case3://xŒ™––yŒ™¡–

xx1 = x1 + 2; yy1 = y1 +1; xx4 = x4 +1;

tempStatus = 31;

break;

case31:

xx1 = x1 - 1; yy1 = y1 -1;

if (yy1 <0){ yy1++; yy2++; yy3++; yy4++; }

if (COLS == yy4){ yy1--; yy2--; yy3--; yy4--; }

tempStatus = 32;

break;

case32:

xx1 = x1 - 1; xx4 = x4 -1; xx4 = x4 -2; yy4 = y4 -1;

tempStatus = 33;

break;

case33:

xx4 = x4 + 1; yy4 = y4 +1;

if (yy1 <0){ yy1++; yy2++; yy3++; yy4++; }

if (COLS == yy4){ yy1--; yy2--; yy3--; yy4--; }

tempStatus = 3;

break;

case4:

xx1 = x1 - 2; yy1 = y1 -1; xx3 = x3 -1; yy3 = y3 -1;  xx4 = x4 +1;

if (yy1 <0){ yy1++; yy2++; yy3++; yy4++; }

tempStatus = 41;

break;

case41:

xx1 = x1 + 2; yy1 = y1 +1; xx3 = x3 +1; yy3 = y3 +1; xx4 = x4 -1;

tempStatus = 4;

break;

case5:

xx1 = x1 + 1; xx2 = x2 +2; yy2 = y2 +1; xx3 = x3 -1; yy4 = y4 +1;

if (COLS == yy4){ yy1--; yy2--; yy3--; yy4--; }

tempStatus = 51;

break;

case51:

xx1 = x1 - 1; xx2 = x2 -2; yy2 = y2 -1; xx3 = x3 +1; yy4 = y4 -1;

tempStatus = 5;

break;

case6:

xx1 = x1 - 1; xx2 = x2 -1; xx3 = x3 +1; yy3 = y3 +1; xx4 = x4 +1; yy4 = y4 +1;

if (COLS == yy4){ yy1--; yy2--; yy3--; yy4--; }

tempStatus = 61;

break;

case61:

xx1 = x1 + 1; yy1 = y1 +1; xx3 = x3 -2; yy3 = y3 -1; xx4 = x4 -1;

tempStatus = 62;

break;

case62:

xx1 = x1 - 1; yy1 = y1 -1; xx2 = x2 -1; yy2 = y2 -1; xx3 = x3 +1; xx4 = x4 +1;

if (yy1 <0){ yy1++; yy2++; yy3++; yy4++; }

tempStatus = 63;

break;

case63:

xx1 = x1 + 1; xx2 = x2 +2; yy2 = y2 +1; xx4 = x4 -1; yy4 = y4 -1;

tempStatus = 6;

break;

case7:

xx1 = x1 - 1; yy1 = y1 -1; xx3 = x3 +1; yy3 = y3 +1; xx4 = x4 -2;

if (yy1 <0){ yy1++; yy2++; yy3++; yy4++; }

tempStatus = 71;

break;

case71:

xx1 = x1 - 1; xx2 = x2 +1; yy3 = y3 -1; yy4 = y4 -1;

tempStatus = 72;

break;

case72:

xx1 = x1 + 2; xx2 = x2 -1; yy2 = y2 -1; xx4 = x4 +1; yy4 = y4 +1;

if (COLS == yy4){ yy1--; yy2--; yy3--; yy4--; }

tempStatus = 73;

break;

case73:

yy1 = y1 + 1; yy2 = y2 +1; xx3 = x3 -1; xx4 = x4 +1;

tempStatus = 7;

break;

}

//»Áπ˚±‰–Œ∫ÛÀ˘‘⁄µƒ«¯”Úƒ⁄Œfi∆‰À˚∑ΩøÈ£¨‘ڱ̠攖◊„πªø’º‰£¨ø…“‘±‰–Œ,«“≤ªƒ‹≥¨‘Ω±flΩÁ

mapStatus[x1][y1].isEmpty = MAP_STATUS_EMPTY;

mapStatus[x2][y2].isEmpty = MAP_STATUS_EMPTY;

mapStatus[x3][y3].isEmpty = MAP_STATUS_EMPTY;

mapStatus[x4][y4].isEmpty = MAP_STATUS_EMPTY;

//–˝◊™ ±”¶∏√√ª”–µΩµ◊&& !bIsBottom∫ÛÃ̺”//÷±œ¬ ±µΩµ◊ªπƒ‹–˝◊™£¨”¶∏√≤ªƒ‹–˝◊™

if (mapStatus[xx1][yy1].isEmpty == MAP_STATUS_EMPTY && mapStatus[xx2][yy2].isEmpty == MAP_STATUS_EMPTY &&

mapStatus[xx3][yy3].isEmpty == MAP_STATUS_EMPTY && mapStatus[xx4][yy4].isEmpty == MAP_STATUS_EMPTY &&

yy1 >= 0 && yy4 <= COLS -1 && !(xx1<0 || xx2<0 || xx3<0 || xx4<0) &&

!(xx1>MAXROWS - 1 || xx2>MAXROWS - 1 || xx3>MAXROWS - 1 || xx4>MAXROWS - 1) /*&& !bIsBottom*/)

{

activeStatus[0][0] = xx1; activeStatus[0][1] = yy1;

activeStatus[1][0] = xx2; activeStatus[1][1] = yy2;

activeStatus[2][0] = xx3; activeStatus[2][1] = yy3;

activeStatus[3][0] = xx4; activeStatus[3][1] = yy4;

mapStatus[xx1][yy1].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[xx1][yy1].rectType = mapStatus[x1][y1].rectType;

mapStatus[xx2][yy2].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[xx2][yy2].rectType = mapStatus[x2][y2].rectType;

mapStatus[xx3][yy3].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[xx3][yy3].rectType = mapStatus[x3][y3].rectType;

mapStatus[xx4][yy4].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[xx4][yy4].rectType = mapStatus[x4][y4].rectType;

currentStatus = tempStatus;//∏ƒ±‰–Œ◊¥

}

else

{

//ª÷∏¥‘≠¿¥◊¥Ã¨

mapStatus[x1][y1].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x2][y2].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x3][y3].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x4][y4].isEmpty = MAP_STATUS_NOT_EMPTY;

}

//≈–∂œ «∑Ò“—µΩµ◊/////////////////////////////////

isBottom(bIsBottom, activeStatus, iInterFace, mapStatus, currentStatus);

}

else if (9 == currentStatus)//œ˚ºı

{

for (int i = x4 -1; i >=0; i--)

{

if (MAP_STATUS_NOT_EMPTY == mapStatus[i][y4].isEmpty)

{

mapStatus[i][y4].isEmpty = MAP_STATUS_EMPTY; mapStatus[i][y4].rectType = ONE;

break;

}

}

}

elseif (10 == currentStatus)//Ã̺”,¿‰»¥ ±º‰(8◊Í∫Õ10‘ˆº”12◊•∫Û£¨”¶≈–∂œ «∑Òø…“‘œ˚––)

{

bool isEmpty =true;

for (int i = x4 -1; i >=0; i--)//µ±x4œ¬∑Ωæ˘ø’ ±“™≈–∂œ

{

if (MAP_STATUS_NOT_EMPTY == mapStatus[i][y4].isEmpty)

{

isEmpty = false;

break;

}

}

if (isEmpty)//¥À«Èøˆ∞¸∫¨x4 = 1

{

if (x4>=2)

{

mapStatus[0][y4].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[0][y4].rectType = ONE;

}

}

else

{

for (int i = x4 -1; i >=0; i--)

{

if (MAP_STATUS_NOT_EMPTY == mapStatus[i][y4].isEmpty)

{

if (x4 >= i+3)

{

mapStatus[i + 1][y4].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[i + 1][y4].rectType = mapStatus[i][y4].rectType;

break;

}

}

}

}

}

}


/* * * * * * * * * * * * * * * * * * * * * *

* ƒ⁄≤ø∫Ø ˝£∫≈–∂œµ±«∞∑ΩøÈ «∑Ò“—µΩµ◊£¨≤¢«“œ˙––µ»œ‡πÿµƒπ§◊˜

*

* ◊Ó∫Û–fi∏ƒ»’∆⁄£∫2016.1.1

* * * * * * * * * * * * * * * * * * * * * */

void GameRule::isBottom(bool& bIsBottom,int activeStatus[4][2],

int iInterFace[INTERFACE_ROW][4], MapStatus mapStatus[MAXROWS][COLS],int currentStatus)

{

bIsBottom = false;//

//µΩµ◊”–¡Ω÷÷∏≈ƒÓ£∫1 «“—µΩµ◊≤ø£¨2 «œ¬√Ê≈ˆµΩ¡À¡ÌÕ‚µƒ∑ΩøÈ

int x1, x2, x3, x4, x, xx, yy;

x1 = activeStatus[0][0]; x2 = activeStatus[1][0]; x3 = activeStatus[2][0]; x4 = activeStatus[3][0];

//1µΩ¥Ô”Œœ∑«¯”Úµƒµ◊≤ø2”ÎΩ”¥•√Ê’˝œ¬∑Ωµƒ–°∑ΩøÈ«¯”ÚŒ™±ª’º”√◊¥Ã¨

if (x1 <=0 || x2 <=0 || x3 <=0 || x4 <=0)

{

bIsBottom = true;

handleNTETBottom(bIsBottom, activeStatus, currentStatus, mapStatus);

return;

}

else

{

if (8 != currentStatus)

{

for (int i =0; i<4; i++)

{

if (iInterFace[currentStatus][i] > -1)

{

//»°µ±«∞œ¬◊πŒÔ”–Ω”¥•√ʵƒ∑ΩøÈ,ªÒ»°”–Ω”¥•√ʵƒ–°∑Ωøȵƒ±‡∫≈

x = iInterFace[currentStatus][i];

//∏˘æ›±‡∫≈ªÒ»°activeStatus÷–∏√–°∑Ωøȵƒ’˝œ¬∑Ωµƒ◊¯±Í

xx = activeStatus[x][0] -1;

yy = activeStatus[x][1];

//≈–∂œ∏√Ω”¥•√Ê’˝œ¬∑Ωµƒ–°∑ΩøÈ«¯”Ú «∑ÒŒ™±ª’º”√◊¥Ã¨

if (mapStatus[xx][yy].isEmpty == MAP_STATUS_NOT_EMPTY)

{

bIsBottom = true;

handleNTETBottom(bIsBottom, activeStatus, currentStatus, mapStatus);

return;

}

}

}

}

else//8Ãÿ ‚£¨ø…“‘◊Í

{

//∏˘æ›±‡∫≈ªÒ»°activeStatus÷–∏√–°∑Ωøȵƒ’˝œ¬∑Ωµƒ◊¯±Í

xx = activeStatus[0][0]; yy = activeStatus[0][1];

for (int i =0; i < xx; i++)

{

if (mapStatus[i][yy].isEmpty == MAP_STATUS_EMPTY)

{

return;

}

}

bIsBottom = true;

handleNTETBottom(bIsBottom, activeStatus, currentStatus, mapStatus);

}

}

}


void GameRule::handleNTETBottom(bool bIsBottom,int iActiveStatus[4][2],int iCurrentStatus, 

MapStatus mapStatus[MAXROWS][COLS])

{

if (bIsBottom)

{

int x1, x2, x3, x4, y1, y2, y3, y4;

x1 = iActiveStatus[0][0]; y1 = iActiveStatus[0][1];

x2 = iActiveStatus[1][0]; y2 = iActiveStatus[1][1];

x3 = iActiveStatus[2][0]; y3 = iActiveStatus[2][1];

x4 = iActiveStatus[3][0]; y4 = iActiveStatus[3][1];

if (9 == iCurrentStatus ||10 == iCurrentStatus ||12 == iCurrentStatus)

{

mapStatus[x1][y1].isEmpty = MAP_STATUS_EMPTY; mapStatus[x1][y1].rectType = ONE;

mapStatus[x2][y2].isEmpty = MAP_STATUS_EMPTY; mapStatus[x2][y2].rectType = ONE;

mapStatus[x3][y3].isEmpty = MAP_STATUS_EMPTY; mapStatus[x3][y3].rectType = ONE;

mapStatus[x4][y4].isEmpty = MAP_STATUS_EMPTY; mapStatus[x4][y4].rectType = ONE;

}

else if (111 == iCurrentStatus)//’®µÙ…œœ¬◊Û”“

{

mapStatus[x1][y1].isEmpty = MAP_STATUS_EMPTY; mapStatus[x1][y1].rectType = ONE;

mapStatus[x2][y2].isEmpty = MAP_STATUS_EMPTY; mapStatus[x2][y2].rectType = ONE;

mapStatus[x3][y3].isEmpty = MAP_STATUS_EMPTY; mapStatus[x3][y3].rectType = ONE;

mapStatus[x4][y4].isEmpty = MAP_STATUS_EMPTY; mapStatus[x4][y4].rectType = ONE;

if (x4 + 1 <= ROWS - 1)

{

mapStatus[x4 + 1][y4].isEmpty = MAP_STATUS_EMPTY; mapStatus[x4 +1][y4].rectType = ONE;//…œ

}

if (x4 - 1 >= 0)

{

mapStatus[x4 - 1][y4].isEmpty = MAP_STATUS_EMPTY; mapStatus[x4 -1][y4].rectType = ONE;//œ¬

}

if (y4 - 1 >= 0)

{

mapStatus[x4][y4 - 1].isEmpty = MAP_STATUS_EMPTY; mapStatus[x4][y4 - 1].rectType = ONE;//◊Û

}

if (y4 + 1 <= COLS-1)

{

mapStatus[x4][y4 + 1].isEmpty = MAP_STATUS_EMPTY; mapStatus[x4][y4 + 1].rectType = ONE;//”“

}

}

}

}


void GameRule::rectDownNotice()

{

//isBottom(bIsBottom, activeStatus, iInterFace, mapStatus, currentStatus);

//int x1, x2, x3, x4, y1, y2, y3, y4;

//x1 = activeStatus[0][0]; y1 = activeStatus[0][1];

//x2 = activeStatus[1][0]; y2 = activeStatus[1][1];

//x3 = activeStatus[2][0]; y3 = activeStatus[2][1];

//x4 = activeStatus[3][0]; y4 = activeStatus[3][1];

//if (!bIsBottom)//√ªµΩµ◊

//{

//mapStatus[x1][y1].isEmpty = MAP_STATUS_EMPTY;

//mapStatus[x2][y2].isEmpty = MAP_STATUS_EMPTY;

//mapStatus[x3][y3].isEmpty = MAP_STATUS_EMPTY;

//mapStatus[x4][y4].isEmpty = MAP_STATUS_EMPTY;

////∑ΩøÈœ¬¬‰

//activeStatus[0][0] -= 1;

//activeStatus[1][0] -= 1;

//activeStatus[2][0] -= 1;

//activeStatus[3][0] -= 1;

//mapStatus[x1 - 1][y1].isEmpty = MAP_STATUS_NOT_EMPTY;

//mapStatus[x1 - 1][y1].rectType = mapStatus[x1][y1].rectType;

//mapStatus[x2 - 1][y2].isEmpty = MAP_STATUS_NOT_EMPTY;

//mapStatus[x2 - 1][y2].rectType = mapStatus[x2][y2].rectType;

//mapStatus[x3 - 1][y3].isEmpty = MAP_STATUS_NOT_EMPTY;

//mapStatus[x3 - 1][y3].rectType = mapStatus[x3][y3].rectType;

//mapStatus[x4 - 1][y4].isEmpty = MAP_STATUS_NOT_EMPTY;

//mapStatus[x4 - 1][y4].rectType = mapStatus[x4][y4].rectType;

//}

}


/* * * * * * * * * * * * * * * * * * * * * *

* ƒ⁄≤ø∫Ø ˝£∫µ±«∞∑ΩøÈœ¬Ωµ

* ◊Ó∫Û–fi∏ƒ»’∆⁄£∫2016.1.1

* * * * * * * * * * * * * * * * * * * * * */

void GameRule::rectDown(bool& bIsBottom,int activeStatus[4][2],int iInterFace[INTERFACE_ROW][4],

MapStatus mapStatus[MAXROWS][COLS], int currentStatus)

{

isBottom(bIsBottom, activeStatus, iInterFace, mapStatus, currentStatus);//»ÙŒfi¥À––£¨ª·≤˙…˙¥©Õ∏

int x1, x2, x3, x4, y1, y2, y3, y4;

x1 = activeStatus[0][0]; y1 = activeStatus[0][1];

x2 = activeStatus[1][0]; y2 = activeStatus[1][1];

x3 = activeStatus[2][0]; y3 = activeStatus[2][1];

x4 = activeStatus[3][0]; y4 = activeStatus[3][1];

if (!bIsBottom)//√ªµΩµ◊

{

mapStatus[x1][y1].isEmpty = MAP_STATUS_EMPTY;

mapStatus[x2][y2].isEmpty = MAP_STATUS_EMPTY;

mapStatus[x3][y3].isEmpty = MAP_STATUS_EMPTY;

mapStatus[x4][y4].isEmpty = MAP_STATUS_EMPTY;

//∑ΩøÈœ¬¬‰

activeStatus[0][0] -=1;

activeStatus[1][0] -=1;

activeStatus[2][0] -=1;

activeStatus[3][0] -=1;

mapStatus[x1 - 1][y1].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x1 - 1][y1].rectType = mapStatus[x1][y1].rectType;

mapStatus[x2 - 1][y2].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x2 - 1][y2].rectType = mapStatus[x2][y2].rectType;

mapStatus[x3 - 1][y3].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x3 - 1][y3].rectType = mapStatus[x3][y3].rectType;

mapStatus[x4 - 1][y4].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[x4 - 1][y4].rectType = mapStatus[x4][y4].rectType;


if (8 == currentStatus)

{

for (int i =0; i < MAXROWS; i++)

{

if (_bIsOccupy[i].isEmpty == MAP_STATUS_NOT_EMPTY && (i != (x1 -1)))

{

mapStatus[i][y1].isEmpty = MAP_STATUS_NOT_EMPTY;

mapStatus[i][y1].rectType = _bIsOccupy[i].rectType;

}

}

}

}

}


void GameRule::isGameOver(bool& bIsBottom,bool& bIsGameOver, MapStatus mapStatus[MAXROWS][COLS])

{

//≈–∂œ”Œœ∑ «∑Ò“—Ω· ¯: ≈ˆ¡Àµ◊£¨«“µ⁄1––”––°∑ΩøÈ

//»Áπ˚◊Ó∫Û“ª∏ˆ∑ΩøÈµΩµ◊ ±£¨◊Ó…œ≤„«°∫√‘⁄20––£¨≈–∂œ”–Œ Ã‚£¨”¶∏√‘⁄√ø¥ŒµΩµ◊∫Û≈–∂œ20–– «∑Ò∑«ø’£¨ «æÕΩ· ¯£¨∑ґںÖ¯

if (bIsBottom)

{

for (int i =0; i < COLS; i++)

{

if (mapStatus[ROWS -1][i].isEmpty == MAP_STATUS_NOT_EMPTY)//∂•––”–»Œ∫Œ“ª¡–∑«ø’£¨º¥Œ™¬˙

{

bIsGameOver = true;

break;

}

}

}

}


原创粉丝点击