00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "tpiece.h"
00023 #include "qstring.h"
00024 #include <stdlib.h>
00025 #include <time.h>
00026
00027 void TetrixPiece::rotateLeft()
00028 {
00029 if ( pieceType == 5 )
00030 return;
00031 int tmp;
00032 for (int i = 0 ; i < 4 ; i++) {
00033 tmp = getXCoord(i);
00034 setXCoord(i,getYCoord(i));
00035 setYCoord(i,-tmp);
00036 }
00037 }
00038
00039 void TetrixPiece::rotateRight()
00040 {
00041 if ( pieceType == 5 )
00042 return;
00043 int tmp;
00044 for (int i = 0 ; i < 4 ; i++) {
00045 tmp = getXCoord(i);
00046 setXCoord(i,-getYCoord(i));
00047 setYCoord(i,tmp);
00048 }
00049 }
00050
00051 int TetrixPiece::getMinX()
00052 {
00053 int tmp = coordinates[0][0];
00054 for(int i = 1 ; i < 4 ; i++)
00055 if (tmp > coordinates[i][0])
00056 tmp = coordinates[i][0];
00057 return tmp;
00058 }
00059
00060 int TetrixPiece::getMaxX()
00061 {
00062 int tmp = coordinates[0][0];
00063 for(int i = 1 ; i < 4 ; i++)
00064 if (tmp < coordinates[i][0])
00065 tmp = coordinates[i][0];
00066 return tmp;
00067
00068 }
00069
00070 int TetrixPiece::getMinY()
00071 {
00072 int tmp = coordinates[0][1];
00073 for(int i = 1 ; i < 4 ; i++)
00074 if (tmp > coordinates[i][1])
00075 tmp = coordinates[i][1];
00076 return tmp;
00077 }
00078
00079 int TetrixPiece::getMaxY()
00080 {
00081 int tmp = coordinates[0][1];
00082 for(int i = 1 ; i < 4 ; i++)
00083 if (tmp < coordinates[i][1])
00084 tmp = coordinates[i][1];
00085 return tmp;
00086 }
00087
00088 void TetrixPiece::initialize(int type)
00089 {
00090 static int pieceTypes[7][4][2] = {{{ 0,-1},
00091 { 0, 0},
00092 {-1, 0},
00093 {-1, 1}},
00094
00095 {{ 0,-1},
00096 { 0, 0},
00097 { 1, 0},
00098 { 1, 1}},
00099
00100 {{ 0,-1},
00101 { 0, 0},
00102 { 0, 1},
00103 { 0, 2}},
00104
00105 {{-1, 0},
00106 { 0, 0},
00107 { 1, 0},
00108 { 0, 1}},
00109
00110 {{ 0, 0},
00111 { 1, 0},
00112 { 0, 1},
00113 { 1, 1}},
00114
00115 {{-1,-1},
00116 { 0,-1},
00117 { 0, 0},
00118 { 0, 1}},
00119
00120 {{ 1,-1},
00121 { 0,-1},
00122 { 0, 0},
00123 { 0, 1}}};
00124 if (type < 1 || type > 7)
00125 type = 1;
00126 pieceType = type;
00127 for(int i = 0 ; i < 4 ; i++) {
00128 coordinates[i][0] = pieceTypes[type - 1][i][0];
00129 coordinates[i][1] = pieceTypes[type - 1][i][1];
00130 }
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 double TetrixPiece::randomSeed = 0.33333;
00173
00174 void TetrixPiece::setRandomSeed(double seed)
00175 {
00176 #ifdef __MIPSEL__
00177 srand( clock() );
00178 #else
00179 QCString buffer;
00180 if (seed < 0)
00181 seed = - seed;
00182 if (seed >= 1)
00183 seed = seed - (double) ((int) seed);
00184 buffer.sprintf("%1.5f",(float) seed);
00185 for (int i = 0 ; i < 5 ; i++)
00186 if ((buffer[i + 2] - '0') % 2 == 0)
00187 buffer[i + 2]++;
00188 randomSeed = atof(buffer);
00189 #endif
00190 }
00191
00192 int TetrixPiece::randomValue(int maxPlusOne)
00193 {
00194 #ifdef __MIPSEL__
00195 return rand() % maxPlusOne;
00196 #else
00197 randomSeed = randomSeed*147;
00198 randomSeed = randomSeed - (double) ((int) randomSeed);
00199 return (int) (randomSeed*maxPlusOne);
00200 #endif
00201 }