00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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