AffichageGrille.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Pierre Schmitt, Ludovic Giacomello, Nhi Ly      *
00003  *                                                                         *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 
00022 
00023 
00024 #ifndef AFFICHAGEGRILLE_H
00025 #define AFFICHAGEGRILLE_H
00026 
00027 #include <string>
00028 #include <iostream>
00029 #include <cstdlib>
00030 #include <sstream>
00031 
00032 #include "SocketUDP.h"
00033 #include "Thread.h"
00034 #include "Mutex.h"
00035 
00036 using namespace std;
00037 
00042 class AffichageGrille : public Thread {
00043 public:
00051         AffichageGrille(Socket *s, Mutex *m){
00052                 mSocket=s;
00053                 mVerrou=m;
00054                 mOver=false;
00055         }
00056 
00061         void *Traitement(){
00062                 while(1){
00063                         mVerrou->Lock();
00064                         //On demande la grille
00065                         mSocket->Envoyer("GRID");
00066                         string grille=mSocket->Ecouter();
00067                         if(AfficherGrille(grille)){
00068                                 mVerrou->Unlock();
00069                                 break;
00070                         }
00071                         mVerrou->Unlock();
00072                         sleep(1);
00073                         system("clear");
00074 
00075                 }
00076                 printf("\e[33m GAME OVER\e[m\n");
00077                 mOver=true;
00078         }
00079 
00084         bool GameOver(){return mOver;}
00085 
00091         bool AfficherGrille(string grille){
00092                 //On récupère le status 
00093                 string cmd=grille;
00094                 istringstream iss(cmd);
00095                 string loginP, scoreP, loginF1, scoreF1, loginF2, scoreF2, loginF3, scoreF3, nbPomme, status;
00096                 getline(iss,loginP,' '); getline(iss,scoreP,' '); getline(iss,loginF1,' '); getline(iss,scoreF1,' '); 
00097                 getline(iss,loginF2,' '); getline(iss,scoreF2,' '); getline(iss,loginF3,' '); getline(iss,scoreF3,' '); 
00098                 getline(iss,nbPomme,' '); getline(iss,status,' '); 
00099                 getline(iss,grille,' '); 
00100                 cout<<loginP<<": "<<scoreP<<", "<<loginF1<<": "<<scoreF1<<", "<<loginF2<<": "<<scoreF2<<", "<<loginF3<<": "<<scoreF3<<" "<<nbPomme<<" pommes restantes"<<endl;
00101                 for(unsigned int i=0, j=0; i<grille.length(); i++, j++){
00102                         switch(grille[i]){
00103                                 case '+' : {
00104                                         printf( "\e[30;47m  \e[m");
00105                                         break;
00106                                 }
00107                                 case 'x' : {
00108                                         printf( "\e[30;47m\e[33m%c \e[m\e[m",grille[i]);
00109                                         break;
00110                                 }
00111                                 case 'P' : {
00112                                         printf( "\e[30;47m\e[34m%c \e[m\e[m",grille[i]);
00113                                         break;
00114                                 }
00115                                 case 'F' : {
00116                                         printf( "\e[30;47m\e[31m%c \e[m\e[m",grille[i]);
00117                                         break;
00118                                 }
00119                                 case 'I' : {
00120                                         printf( "\e[30;47m%c \e[m",grille[i]);
00121                                         break;
00122                                 }               
00123                         }
00124                         if(j==19){
00125                                 cout<<endl;
00126                                 j=-1;
00127                         }
00128                 }
00129                 cout<<endl;
00130                 if(status=="GAMEOVER") return true;
00131                 return false;
00132         }
00133 
00134 public:
00138         Socket *mSocket;
00139 
00143         Mutex *mVerrou;
00144         
00148         bool mOver;
00149 };
00150 
00151 #endif

Generated on Wed Jan 2 14:01:41 2008 for Pacman by  doxygen 1.5.1