void BinImg::OnBinImg() { CFileDialog fdlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,_T("BMP Files (*.bmp)|*.bmp")); if(!fdlg.DoModal()) return; CString str; str=fdlg.GetPathName(); char strPath[256]={0}; memcpy(strPath,str,str.GetLength()); strcpy(gstrPath,strPath); ShowBMP(IDC_BINIMG,strPath); }
void BinImg::GenImg(int nType) { if(!pMyDlg->OpenDev()) { AfxMessageBox("设备打开失败"); return; } if(gstrPath[0]==0) { AfxMessageBox("请选择图像"); return; } int ret; memset(gpImageData,0,gnImageSize); ret=PSGetImgDataFromBMP(gstrPath,gpImageData,&gnImageSize) ; if(ret!=PS_OK) { AfxMessageBox( PSErr2Str(ret) ); return; } ret = PSDownImage(pMyDlg->m_Addr,gpImageData,gnImageSize); if(ret!=PS_OK) { AfxMessageBox( PSErr2Str(ret) ); return; } ret = PSGenBinImage(pMyDlg->m_Addr,nType); if(ret!=PS_OK) { AfxMessageBox( PSErr2Str(ret) ); return; } ret = PSUpImage(pMyDlg->m_Addr,gpImageData,&gnImageSize); if(ret!=PS_OK) { AfxMessageBox( PSErr2Str(ret) ); return; } ret=PSImgData2BMP(gpImageData,"C:\\test.bmp"); if(ret!=0) { AfxMessageBox("失败"); return; } ShowBMP(IDC_BINIMG,"C:\\test.bmp"); }
void Update_all() { int i = 0, j = 0; ShowBMP(qipanBmp, 0, 0, 0); for(i=0;i<15;i++) { for(j=0;j<15;j++) { if( bb[i][j].stat==1) { //BitBlt(hDC,xx[j],xx[i],21,21,hMemDC,0,0,SRCAND); Pain_back(i,j); } else if( bb[i][j].stat==2) { //BitBlt(hDC,xx[j],xx[i],21,21,hMemDC,0,0,SRCAND); Pain_white(i,j); } } } }
main(int argc, char *argv[]) { //This initializes the SDL system for audio and video. if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(1); } //Whenever the program exits, SDL_Quit() will be called. //SDL_Quit() is defined in SDL.h atexit(SDL_Quit); //Also, TTF_Quit() should be called upon program exit. atexit(TTF_Quit); // Initialize the TrueType font system. TTF_Init(); // This call retrieves information about your screen, // including width and height (in pixels) and the // number of bits per pixels (i.e. the pixel depth). // See the SDL_VideoInfo type defined in SDL_video.h const SDL_VideoInfo *video_info = SDL_GetVideoInfo(); // Let's have a window of 600x400 pixels window_w = 600; window_h = 400; // This creates a graphics window with the specified // width, height, and bits per pixel. You are best // off matching the number of pits per pixel to that // of your screen. The last argument is a flags argument, // the various choices are described in SDL_video.h . // SDL_HWSURFACE seems to work fine. SDL_Surface *screen = SDL_SetVideoMode(window_w, window_h, video_info->vfmt->BitsPerPixel, SDL_HWSURFACE); //This generates the number representing the background color. unsigned int background = SDL_MapRGB(screen->format, 0x90, 0x90, 0xff); //Read in a font from the specified font file of the specified size //This one for Mac OS X. //TTF_Font *text_font = TTF_OpenFont("/Library/Fonts/Times New Roman.ttf", 36); //This one is for Windows/Cygwin, assuming there is a font named //times.ttf that you copied into the current working directory. // // TTF_Font *text_font = TTF_OpenFont("times.ttf", 36); //This one is for Linux // TTF_Font *text_font = TTF_OpenFont("/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf", 36); if (text_font == NULL) { printf("Could not load font\n"); exit(1); } //This writes the background color to the entirety of the screen surface. //It won't actually appear on the visible screen until //SDL_Flip() is called. The NULL second argument indicates //that the backgorund color should be written to the entire screen //screen surface. SDL_FillRect(screen, NULL, background); //This declares a variable of type SDL_Color, which is a struct type //containing three 8-bit fields, r, g, and b. It is used to specify //the font color for the displayed text image. SDL_Color font_color; font_color.r = 0; font_color.g = 0xff; //very green. If you want black, make this 0. font_color.b = 0; //This is the character array that will contain the string to turn into //the text image to be displayed. char textbuf[80]; //This is the count of the number of times the text bounces off the side //of the window. It will be displayed as part of the text image. int bouncecount = 0; //sprintf is like printf, but instead of writing the output to the screen, it //writes the output to a string which is passed as the first parameter to //sprintf. sprintf(textbuf, "Bounces = %d", bouncecount); //This converts a string to an SDL_Surface (image) that can be displayed //like any other image. TTF_RenderText_Solid takes as parameters the //font, the text string, and the font color. SDL_Surface *text_image = TTF_RenderText_Solid(text_font, textbuf, font_color); //This causes the actual visible screen to be updated with the //contents of the screen surface. SDL_Flip(screen); //The text image will bounce back and forth horizontally. int x_pos = 1; int y_pos = (window_h - text_image->h)/2; //This variables are used to determine how far the text_image moves, //in pixels, each time through the loop, below. int delta_x = 2; int done = FALSE; //SDL_Event, defined in SDL_events.h, is a type used to store //events -- such as mouseclicks, key presses, mouse movements, //etc. that can occur while the program is running. SDL_Event event; SDLKey current_key; //This loop will keep going until the user presses a mouse key //or a key on the keyboard. while (!done) { //erase any text_image on the screen by writing the background //color to the entire screen. SDL_FillRect(screen, NULL, background); //Call the ShowBMP procedure, above, to write the text text_image //to the screen at the specified x and y locations. ShowBMP(text_image, screen, x_pos, y_pos); /* This will actually cause the visible screen to be updated */ SDL_Flip(screen); //SDL_Delay, defined in SDL_timer.h, allows you to specify //a delay in milliseconds, in order to help control the speed of //motion in your program. SDL_Delay(1); //Add the delta's to the x and y directions. x_pos += delta_x; //Check if the text_image, in the next iteration, will be past the //right or left edge of the window. If so, reverse direction. if ((x_pos > screen->w - text_image->w) || (x_pos < 0)) { delta_x = -delta_x; //put the text_image at the edge of the window x_pos = (x_pos < 0) ? 0 : screen->w - text_image->w; //The text has bounced, so increment the bounce count. bouncecount++; //Create a new text image, incorporating the new value //of bouncecount: //Free up the memory used by the old SDL_Surface image SDL_FreeSurface(text_image); //new string containing the new bouncecount sprintf(textbuf, "Bounces = %d", bouncecount); //new SDL_Surface image text_image = TTF_RenderText_Solid(text_font, textbuf, font_color); } //Now poll to see if the user has hit a key or a //mouse button. If so, set done to true so the loop //will exit. while ( SDL_PollEvent(&event) ) { switch (event.type) { case SDL_KEYDOWN: case SDL_MOUSEBUTTONDOWN: case SDL_QUIT: done = TRUE; break; default: break; } } } }
int Pain_white(int i,int j) { ShowBMP(whiteBmp,xx[j],xx[i], 0); return (0); }
int Pain_back(int i,int j) { ShowBMP(blackBmp, xx[j],xx[i], 0); return (0); }
/*********************************************************** synopsis: a big while loop that runs the full length of the game, checks the game events and responds accordingly event action ------------------------------------------------- winGame stop the clock and solve puzzle timeRemaining update the clock tick timeUp stop the clock and solve puzzle solvePuzzle trigger solve puzzle and stop clock updateAnswers trigger update answers startNew trigger start new updateScore trigger update score shuffle trigger shuffle clear trigger clear answer quit end loop poll events check for keyboard/mouse and quit finally, move the sprites -this is always called so the sprites are always considered to be moving no "move sprites" event exists - sprites x&y just needs to be updated and they will always be moved inputs: head - first node in the answers list (in/out) dblHead - first node in the dictionary list screen - the SDL_Surface to display the image letters - first node in the letter sprites (in/out) outputs: n/a ***********************************************************/ static void gameLoop(struct node **head, struct dlb_node *dlbHead, SDL_Surface *screen, struct sprite **letters) { int j,k; int done=0; int numofwords=1; SDL_Event event; time_t timeNow; SDL_TimerID timer; int timer_delay = 20; char buffer[512]; #ifdef demo if (conf.totalgames < 0){ conf.totalgames=8; } conf.totalgames +=1;//demo tags sprintf(buffer,"globaldata/agdemo.cfg"); saveCFG(buffer,&conf); #endif timer = SDL_AddTimer(timer_delay, TimerCallback, NULL); /* main game loop */ while (!done) { if (winGame) { stopTheClock = 1; solvePuzzle = 1; } if ((gameTime < AVAILABLE_TIME) && !stopTheClock) { timeNow = time(0) - gameStart; if (timeNow != gameTime){ gameTime = timeNow; updateTime(screen); } } else { if (!stopTheClock){ stopTheClock = 1; solvePuzzle = 1; } } /* check messages */ if (solvePuzzle) { /* walk the list, setting everything to found */ solveIt(*head); clearWord(letters); strcpy(shuffle, SPACE_FILLED_STRING); strcpy(answer, rootWord); /*displayLetters(screen);*/ displayAnswerBoxes(*head, screen); gamePaused = 1; if (!stopTheClock){ stopTheClock = 1; } solvePuzzle = 0; } if (updateAnswers){ /* move letters back down again */ clearWord(letters); /* displayLetters(screen);*/ displayAnswerBoxes(*head, screen); updateAnswers = 0; } if ((stopTheClock && !gotBigWord && !checkScore)||(startNewGame&&!gotBigWord& !checkScore)){ //Error("inside highscore\n"); for(j=9;j>=0 && hiscore[j].score<totalScore;j--); //Error("score position: %i\n",j); /* the player will be in the hall of fame? */ if(j<9) { for(k=8;k>j;k--) hiscore[k+1]=hiscore[k]; /* put the new score */ hiscore[j+1].score=totalScore; hiscore[j+1].stage=numofwords; //hiscore[j+1].name[0]=0; //if(!getName(hiscore[j+1].name, j+2,i+1)) // break; /* probably a problem if the user closes the window */ /* show the hall of fame */ //hiscores(); /* save hi-scores */ #ifdef demo sprintf(buffer,"/media/internal/appdata/com.cribme.aghddemo/ag-hiscore"); #else sprintf(buffer,"/media/internal/appdata/com.cribme.aghd/ag-hiscore"); #endif //sprintf(buffer,"globaldata/ag-hiscore"); if(!saveScore(buffer,hiscore)) fprintf(stderr,"unable to save hi-scores\ndo you have permissions to write into %s?\n" ,buffer); } checkScore=1; } if (startNewGame) { /* move letters back down again */ if (!gotBigWord){ totalScore = 0; numofwords=0; } newGame(head, dlbHead, screen, letters); #ifdef demo conf.totalgames +=1;//demo tags char buffer[512]; sprintf(buffer,"globaldata/agdemo.cfg"); //Error("Buffer :%s\n",buffer); //Error("TotalGames Written to file :%i\n",conf.totalgames); saveCFG(buffer,&conf); #endif numofwords+=1; checkScore = 0; startNewGame = 0; } if (updateTheScore) { updateScore(screen); updateTheScore = 0; } if (shuffleRemaining) { /* shuffle up the shuffle box */ char shuffler[8]; strcpy(shuffler, shuffle); shuffleAvailableLetters(shuffler, letters); strcpy(shuffle, shuffler); shuffleRemaining = 0; } if (clearGuess) { /* clear the guess; */ if (clearWord(letters) > 0) { Mix_PlayChannel(-1, getSound("clear"),0); } clearGuess = 0; } #ifdef demo //Error("TotalGames:%i\n",conf.totalgames);//conf.totalgames if (conf.totalgames > 8){//conf.totalgames destroyLetters(letters); strcpy(txt, language); ShowBMP(strcat(txt,"images/demo.bmp"),screen, 100,75); done=1; } #endif if (quitGame) { done = 1; } if (inactive){ SDL_WaitEvent(&event); if (event.type == SDL_ACTIVEEVENT && event.active.gain == 1) { inactive = 0; timer = SDL_AddTimer(timer_delay, TimerCallback, NULL); } } else { while (SDL_WaitEvent(&event)) { if (event.type == SDL_ACTIVEEVENT && event.active.gain == 0) { inactive = 1; break; } if (event.type == SDL_USEREVENT) { timer_delay = anySpritesMoving(letters) ? 10 : 100; moveSprites(&screen, letters, letterSpeed); timer = SDL_AddTimer(timer_delay, TimerCallback, NULL); break; } else if (event.type == SDL_MOUSEBUTTONDOWN) { clickDetect(event.button.button, event.button.x, event.button.y, screen, *head, letters); moveSprites(&screen, letters, letterSpeed);//added by me } else if (event.type == SDL_KEYUP) { handleKeyboardEvent(&event, *head, letters); } else if (event.type == SDL_QUIT) { done = 1; break; } } } } #ifdef demo while(conf.totalgames > 8){//conf.totalgames while(SDL_WaitEvent(&event)){ if (event.type == SDL_MOUSEBUTTONDOWN) { PDL_ServiceCall("palm://com.palm.applicationManager/open", "{\"target\":\"http://developer.palm.com/appredirect/?packageid=com.cribme.aghd\"}"); //PDL_LaunchBrowser("http://developer.palm.com/appredirect/?packageid=com.cribme.aghd"); } } } #endif }
/*********************************************************** synopsis: do all of the initialisation for a new game: build the screen get a random word and generate anagrams (must get less than 66 anagrams to display on screen) initialise all the game control flags inputs: head - first node in the answers list (in/out) dblHead - first node in the dictionary list screen - the SDL_Surface to display the image letters - first node in the letter sprites (in/out) outputs: n/a ***********************************************************/ static void newGame(struct node** head, struct dlb_node* dlbHead, SDL_Surface* screen, struct sprite** letters) { char guess[9]; char remain[9]; int happy = 0; /* we don't want any more than ones with 66 answers */ /* - that's all we can show... */ int i; /* show background */ strcpy(txt, language); ShowBMP(strcat(txt,"images/background.bmp"),screen, 0,0); destroyLetters(letters); assert(*letters == NULL); while (!happy) { char buffer[9]; getRandomWord(buffer, sizeof(buffer)); strcpy(guess,""); strcpy(rootWord, buffer); bigWordLen = strlen(rootWord)-1; strcpy(remain, rootWord); rootWord[bigWordLen] = '\0'; /* destroy answers list */ destroyAnswers(head); /* generate anagrams from random word */ ag(head, dlbHead, guess, remain); answersSought = Length(*head); happy = ((answersSought <= 77) && (answersSought >= 6)); #ifdef DEBUG if (!happy) { Debug("Too Many Answers! word: %s, answers: %i", rootWord, answersSought); } #endif } #ifdef DEBUG Debug("Selected word: %s, answers: %i", rootWord, answersSought); #endif /* now we have a good set of words - sort them alphabetically */ sort(head); for (i = bigWordLen; i < 7; i++){ remain[i] = SPACE_CHAR; } remain[7] = '\0'; remain[bigWordLen]='\0'; shuffleWord(remain); strcpy(shuffle, remain); strcpy(answer, SPACE_FILLED_STRING); /* build up the letter sprites */ assert(*letters == NULL && screen != NULL); buildLetters(letters, screen); addClock(letters, screen); addScore(letters, screen); /* display all answer boxes */ displayAnswerBoxes(*head, screen); gotBigWord = 0; score = 0; updateTheScore = 1; gamePaused = 0; winGame = 0; answersGot = 0; gameStart = time(0); gameTime = 0; stopTheClock = 0; }