void Graphics::refreshScreen(Map *map) { app->Clear(); printBackground(); cleanMap(map); highlightCase(map->getHud()); printRessources(map); printEggs(map); printPlayers(map); printHud(map); app->Display(); }
// ================================ START Menu ================================ int GUI::play( ) { Table t; // choi tren Table nay srand(time(NULL)); //Sinh so ngau nhien double timeDelay = 1000 - level * 100 ; //thoi gian de roi double tempTimeDelay = timeDelay; int IDBrick, IDNextBrick; //So thu tu cua gach score = 0; //Diem ban dau lines = 0; //So hang da an duoc ban dau system( "cls" ); //Tao 2 khoi gach dau tien IDBrick = createIDBrick(); IDNextBrick = createIDBrick(); //In ra background, level, line va score ban dau printBackground( ); gotoxy( 12, 4 ); std::cout << level; gotoxy( 12, 6 ); std::cout << score; gotoxy( 12, 8 ); std::cout << lines; do { t.create( IDBrick ); //tao khoi moi while ( t.checkEmpty( -1, 0 ) ) { //In ra vien gach tiep theo va mau cua no setTextColor( IDNextBrick + 7 ); t.printNextBrick( IDNextBrick ); Sleep( ( tempTimeDelay ) ); int count = 5; //So lan xoay toi da trong timeDelay while (--count && kbhit() ) //doi phim an { KEY = key_press( ); if ( KEY == KEY_LEFT ) // dich trai neu nhap phim trai t.moveLeft( ); else if ( KEY == KEY_RIGHT ) // dich phai neu nhap phim phai t.moveRight( ); else if ( KEY == KEY_DOWN ) // roi luon neu nhap phim xuong tempTimeDelay /= 10; else if ( KEY == KEY_UP ) // xoay neu nhap phim len t.rotate( ); else if ( KEY == PAUSE || KEY == ESCAPE ) // tam dung pause while ( 1 ) //man hinh pause { system( "cls" ); //xoa man hinh, chong gian lan //In ra tuy chon o man hinh pause setTextColor( COLOR ); gotoxy( 20, 9 ); std::cout << " _____PAUSE_____ "; gotoxy( 20, 12 ); std::cout << " RESUME "; gotoxy( 20, 14 ); std::cout << " RESTART "; gotoxy( 20, 16 ); std::cout << " MAIN MENU "; int chosenMenu = cursor( 12, 16, 1 ); //Thuc hien lenh tuy theo toa do con tro tuy chon if(chosenMenu == 1 ) //tiep tuc { //In ra nen game, level, lines va score hien tai va tiep tuc game printBackground( ); gotoxy( 12, 4 ); std::cout << level; gotoxy( 12, 6 ); std::cout << score; gotoxy( 12, 8 ); std::cout << lines; break; } else if(chosenMenu == 2 && confirm("RESTART") ) //choi lai ( can xac nhan ) return play( ); else if(chosenMenu == 3 && confirm("BACK TO MAIN MENU") ) //quay ve return -1; //return restart( ); } } t.moveDown( ); // dich xuong } t.setBrickNum( IDBrick + 7 ); t.getFullRows( ); //Lay diem //Tinh diem hien tai score = score + level + level * level * t.getDeletedLines() * t.getDeletedLines(); lines += t.getDeletedLines(); //In ra level, lines va score hien tai setTextColor ( COLOR ); gotoxy( 12, 4 ); std::cout << level; gotoxy( 12, 6 ); std::cout << score; gotoxy( 12, 8 ); std::cout << lines; IDBrick = IDNextBrick; //Gan khoi cu thanh khoi moi IDNextBrick = createIDBrick(); //Tao khoi gach tiep theo tempTimeDelay = timeDelay *= 0.99; level = ( 1000 - timeDelay ) / 100; } while ( t.checkGameOver() == 0 ); return score; //lay diem }
int main() { // Open the file for reading and writing fbfd = open("/dev/fb0", O_RDWR); if (fbfd == -1) { perror("Error: cannot open framebuffer device"); exit(1); } printf("The framebuffer device was opened successfully.\n"); // Get fixed screen information if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) { perror("Error reading fixed information"); exit(2); } // Get variable screen information if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) { perror("Error reading variable information"); exit(3); } printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel); displayWidth = vinfo.xres; displayHeight = vinfo.yres; // Figure out the SIZE of the screen in bytes screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; // Map the device to memory fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); if (atoi(fbp) == -1) { perror("Error: failed to map framebuffer device to memory"); exit(4); } printf("The framebuffer device was mapped to memory successfully.\n"); printBackground(); // /* // Triangle t = MakeTRIANGLE(MakePOINT(100,100),MakePOINT(100,200),MakePOINT(400,200)); // Triangle t1 = scaleTriangle(t,1.5); // drawTriangle(t1.P1.X, t1.P1.Y, t1.P2.X, t1.P2.Y, t1.P3.X, t1.P3.Y, 255, 255, 255); // drawTriangle(100,100,100,200,400,200,0,0,0); // */ // //drawLine(100,100,100,200); // //drawLine(100,100,400,200); // //drawLine(100,200,400,200); // //drawTriangle(100,100,500,300,250,600); // Vector2dVector a; // a.push_back( Vector2d(110,110)); // a.push_back( Vector2d(160,110)); // a.push_back( Vector2d(160,190)); // a.push_back( Vector2d(110,190)); // a.push_back( Vector2d(110,150)); // a.push_back( Vector2d(140,150)); // a.push_back( Vector2d(140,130)); // a.push_back( Vector2d(110,130)); // Vector2dVector result; // // Invoke the triangulator to triangulate this polygon. // Triangulate::Process(a,result); // // print out the results. // int tcount = result.size()/3; // Triangle tri, tri1; // for (int i=0; i<tcount; i++) { // const Vector2d &p1 = result[i*3+0]; // const Vector2d &p2 = result[i*3+1]; // const Vector2d &p3 = result[i*3+2]; // tri = MakeTRIANGLE(MakePOINT(p1.GetX(),p1.GetY()),MakePOINT(p2.GetX(),p2.GetY()),MakePOINT(p3.GetX(),p3.GetY())); // //printf("Triangle %d => (%0.0f,%0.0f) (%0.0f,%0.0f) (%0.0f,%0.0f)\n",i+1,p1.GetX(),p1.GetY(),p2.GetX(),p2.GetY(),p3.GetX(),p3.GetY()); // tri1 = scaleTriangle(tri, 1.8); // drawTriangle(tri1.P1.X, tri1.P1.Y, tri1.P2.X, tri1.P2.Y, tri1.P3.X, tri1.P3.Y, (i*15 + 30) % 255 , (i*5 + 100) % 255, (i*10 + 50) % 255); // } int scale = 2; // Membuat pergerakan tulisan system("setterm -cursor off"); printBackground(); for(int i=0; i<85; i++) { if (i%10==0) { if (i<=30) { scale++; } else { scale--; } } int r = 255; int g = 255; int b = 255; printIrene(200, 700-i*25, scale, r, g, b); printWilliam(200, 700-i*25+33*scale, scale, r, g, b); printAngela(200, 700-i*25+66*scale, scale, r, g, b); printKevin(200, 700-i*25+99*scale, scale, r, g, b); printMarcel(200, 700-i*25+132*scale, scale, r, g, b); printDevina(200, 700-i*25+165*scale, scale, r, g, b); usleep(10000); // dalam miliseconds printBackground(); } system("setterm -cursor on"); munmap(fbp, screensize); close(fbfd); return 0; }