Main Page   Packages   Class Hierarchy   Alphabetical List   Data Structures   File List   Namespace Members   Data Fields   Globals  

Bingo.cpp

Go to the documentation of this file.
00001 /*
00002  * $Id: Bingo.cpp,v 1.5 2002/08/09 11:19:18 virtualcasino Exp $
00003  */
00004 #include<Bingo.h>
00005 #include<stdlib.h>
00006 #include<unistd.h>
00007 #include<Random.h>
00008 #include<SDL.h>
00009 #include<SDL_gfxPrimitives.h>
00010 
00011 static int _b[16];
00012 static int _i[16];
00013 static int _n[16];
00014 static int _g[16];
00015 static int _o[16];
00016 
00017 namespace clawsoft{
00018         BingoCard *AllCards;
00019         bool *usedCards;
00020 
00021         BingoCard::BingoCard():Object("BingoCard"){
00022 
00023         }
00024 
00025 
00026         bool BingoCard::operator==(BingoCard b){
00027                 int i, j;
00028                 for(i = 0; i < 5; i++){
00029                         for(j = 0; j < 5; j++){
00030                                 if(numbers[i][j] != b.numbers[i][j])
00031                                         return false;
00032                         }
00033                 }
00034                 return true;
00035         }
00036 
00037         void BingoCard::autogen(){
00038                 int i, j, temp;
00039                 bool flag;
00040                 for(i = 0; i < 16; i++){
00041                         _b[i] = i;
00042                         _i[i] = i + 15;
00043                         _n[i] = i + 30;
00044                         _g[i] = i + 45;
00045                         _o[i] = i + 60;
00046                 }
00047                 for(i = 0; i < 5; i++){
00048                         for(j = 0; j < 5; j++){
00049                                 do{
00050                                         flag = false;
00051                                         temp = rand()%15 + 1;
00052                                         switch(i){
00053                                                 case 0: //columna b;
00054                                                         if(_b[temp] == temp)
00055                                                                 _b[temp] = 0;
00056                                                         else
00057                                                                 flag = true;
00058                                                         break;
00059                                                 case 1: //columna i;
00060                                                         temp += 15;
00061                                                         if(_i[temp - 15] == temp)
00062                                                                 _i[temp - 15] = 0;
00063                                                         else
00064                                                                 flag = true;
00065                                                         break;
00066                                                 case 2: //columna n;
00067                                                         temp += 30;
00068                                                         if(_n[temp - 30] == temp)
00069                                                                 _n[temp - 30] = 0;
00070                                                         else
00071                                                                 flag = true;
00072                                                         break;
00073                                                 case 3: //columna g;
00074                                                         temp += 45;
00075                                                         if(_g[temp - 45] == temp)
00076                                                                 _g[temp - 45] = 0;
00077                                                         else
00078                                                                 flag = true;
00079                                                         break;
00080                                                 case 4: //columna o;
00081                                                         temp += 60;
00082                                                         if(_o[temp - 60] == temp)
00083                                                                 _o[temp - 60] = 0;
00084                                                         else
00085                                                                 flag = true;
00086                                                         break;
00087                                         }
00088                                 }while(flag);
00089                                 numbers[j][i] = temp;
00090                                 vchktable[j][i] = 0;
00091                         }
00092                 }
00093                 vchktable[2][2] = 1;
00094                 numbers[2][2] = 0;
00095         }
00096 
00097         void genCards(){
00098                 int i, k;
00099                 bool areequal;
00100                 cout.flush();
00101                 AllCards = new BingoCard[MAXIMUM_PLAYERS];
00102                 usedCards = new bool[MAXIMUM_PLAYERS];
00103                 for(k = 0; k < MAXIMUM_PLAYERS; k++){
00104                         do{
00105                                 areequal = false;
00106                                 cout << "Generando " << (k + 1)/100 << "%    \r";
00107                                 cout.flush();
00108                                 AllCards[k].autogen();
00109                                 for(i = 0; i < k; i++){
00110                                         if(AllCards[i] == AllCards[k]){
00111                                                 areequal = true;
00112                                                 break;
00113                                         }
00114                                 }
00115                                 //usleep(5);
00116                         }while(areequal);
00117                 }
00118                 cout << endl << "Bingo generado" << endl;
00119                 usedCards[k] = false;
00120         }
00121 
00122         void provideCard(Socket &client){
00123                 Random r;
00124                 String ack;
00125                 int num, i, j;
00126                 bool flag;
00127                 do{
00128                         flag = false;
00129                         num = r.random(100);
00130                         if(usedCards[num] == true)
00131                                 flag = true;
00132                 }while(flag);
00133                 //Now we know which bingocard, let's send it over the network
00134                 for(i = 0; i < 5; i++){
00135                         for(j = 0; j < 5; j++){
00136                                 //ack.deleteString();
00137                                 ack = AllCards[num].numbers[i][j];
00138                                 client << ack;
00139                                 cout << ack << "\t";
00140                                 client >> ack;
00141                                 ack.deleteString();
00142                         }
00143                         cout << endl;
00144                 }
00145 
00146         }
00147 
00148         void BingoCard::request(String url, int port){
00149                 int i, j;
00150                 String data, ack;
00151                 Socket server(url, port);
00152                 server >> data;
00153                 data = "4";
00154                 server << data;
00155                 for(i = 0; i < 5; i++){
00156                         for(j = 0; j < 5; j++){
00157                                 data.deleteString();
00158                                 server >> data;
00159                                 server << "ACK";
00160                                 numbers[i][j] = data.toUInt();
00161                         }
00162                 }
00163 
00164         }
00165 
00166         void BingoCard::draw(int x, int y){
00167                 w = 
00168         }
00169 }

Powered by:

SourceForge Logo