void SinglePlayer(void) { /* 啟動鍵盤控制 */ initializeKeyInput(); char ch='0'; winTimes=0; //Left loseTimes=0; count = 0; int pick = -1; int initime=clock(); int time; while(winTimes<3 && loseTimes<3) { clearScreen(); if(turn == 0) { ch = getKeyEventVirtual(); switch(ch) { case 0x58: //左方拍桌 check(pick,initime); initime = clock(); break; case 0x5A: if(count==pick) { Loser(); } else getNewCard(); initime = clock(); break; } } else { if(waitForKeyDown(3.0)) { ch = getKeyEventVirtual(); if(ch == 0x58){ check(pick,initime); initime = clock(); } } else //if(tick > WAIT_TIME) { getNewCard(); initime = clock(); } } } if(loseTimes==3) gameover(); showingPlane =2; }
void intro(void) { FILE *in; char ch; int i,j; int vk; clearScreen(); in = fopen("intro.txt","r"); /* 把檔案�堶悸漲r讀取並顯示出來 */ for(i=0;i<HEIGHT;i++) { for(j=0;j<WIDTH*2;j++) { while((ch = fgetc(in)) == '\n' || ch == '|' || ch == '-'); putASCII2(j + OFFSET_X,i + OFFSET_Y,ch,15,0); } } fclose(in); drawCmdWindow(); /* 當使用者按下 Enter 鍵即離開 */ while(1) { if(waitForKeyDown(1)) { vk=getKeyEventVirtual(); if(vk == VK_RETURN) break; } if(i==0) putString(46+OFFSET_X,18+OFFSET_Y," ",12,0); else putString(46+OFFSET_X,18+OFFSET_Y,"想離開請按 Enter ...",12,0); drawCmdWindow(); i= !i; } }
void rankList(void) { FILE *in; char name[100]; char toString[100]; int score; int i=1; int vk; clearScreen(); in = fopen("ranklist.slmt","r"); putString(24+OFFSET_X,1+OFFSET_Y,"排 行 榜",11,5); while(fscanf(in,"%d,%s",&score,name) == 2) { sprintf(toString,"%d. %7d",i,score); putString(14+OFFSET_X,i*2+1+OFFSET_Y,toString,15,0); putString(44+OFFSET_X,i*2+1+OFFSET_Y,name,15,0); i++; } fclose(in); drawCmdWindow(); /* 當使用者按下 Enter 鍵即離開 */ while(1) { if(waitForKeyDown(1)) { vk=getKeyEventVirtual(); if(vk == VK_RETURN) break; } if(i==0) putString(46+OFFSET_X,18+OFFSET_Y," ",12,0); else putString(46+OFFSET_X,18+OFFSET_Y,"想離開請按 Enter ...",12,0); drawCmdWindow(); i= !i; } }
void MuitiplePlayers(void) { Font *large_font = read_font("font.txt"); /* 啟動鍵盤控制 */ initializeKeyInput(); char ch,prech='0'; char *card; card = (char*)malloc(sizeof(char)); *(card+1) = '\0'; int isWin=0,isLose=0; int count = 0, pick; int initime =clock(), time; int turn=2; // 1:Right 2:Left while(isWin<3 && isLose<3) { clearScreen(); time = clock() - initime; ch = getKeyEventVirtual(); switch(ch) { case VK_LEFT: //右方拍桌 if(( count==pick && time<10 )|| count==14) { //win(10); putStringLarge(large_font, 200, 20, "YOU WIN!!", 15, 15); drawCmdWindow(); Sleep(200); turn = 2; time = 0; isLose++; } else if(count==pick) {//show_image(*(poker+1),0,0); //drawCmdWindow(); //AIwin(); putStringLarge(large_font, 200, 20, "YOU LOSE! How slow you are!", 15, 15); drawCmdWindow(); Sleep(200); turn = 1; time = 0; isWin++; } else { //lose(10); putStringLarge(large_font, 200, 20, "YOU LOSE! Watch out the number!", 15, 15); drawCmdWindow(); Sleep(200); turn = 1; time = 0; isWin++; } break; break; case 0x58: //左方拍桌 if(( count==pick && time<10 )|| count==14) { //win(10); putStringLarge(large_font, 10, 20, "YOU WIN!!", 15, 15); drawCmdWindow(); Sleep(200); turn = 1; time = 0; isWin++; } else if(count==pick) { //AIwin(); putStringLarge(large_font, 10, 20, "YOU LOSE! How slow you are!", 15, 15); drawCmdWindow(); Sleep(200); turn = 2; time = 0; isLose++; } else { //lose(10); putStringLarge(large_font, 10, 20, "YOU LOSE! Watch out the number!", 15, 15); drawCmdWindow();//show_image(*(poker+1),0,0); //drawCmdWindow(); Sleep(200); turn = 2; time = 0; isLose++; } break; case 0x5A: //左方發牌 if(count==pick|| count==14) { putStringLarge(large_font, 10, 20, "YOU LOSE! Watch out the number!", 15, 15); drawCmdWindow(); Sleep(200); turn = 2; time = 0; isLose++; } else if(turn == 2) { count = count%13 +1; if(count<11) *card = ('0'+count); else if(count == 11) *card = 'J'; else if(count == 12) *card = 'Q'; else if(count == 13) *card = 'K'; putStringLarge(large_font, 100, 40, "NUM ", 0, 15); putStringLarge(large_font, 150, 40, card, 0, 15); pick = (rand()%13)+1; if(pick<11) *card = ('0'+pick); else if(pick == 11) *card = 'J'; else if(pick == 12) *card = 'Q'; else if(pick == 13) *card = 'K'; else if(pick == 14) *card = 'P'; putStringLarge(large_font, 100, 50, "CARD ", 0, 15); putStringLarge(large_font, 150, 50, card, 0, 15); time = 0; turn = 1; int ran = (rand()%4)+1; //show_image(poker[0][0],100,20); drawCmdWindow(); }//show_image(*(poker+1),0,0); //drawCmdWindow(); break; case VK_DOWN: //右方發牌 if(count==pick|| count==14) { putStringLarge(large_font, 200, 20, "YOU LOSE! Watch out the number!", 15, 15); drawCmdWindow(); Sleep(200); turn = 1; time = 0; isWin++; } else if(turn == 1) { count = count%13 +1; if(count<11) *card = ('0'+count); else if(count == 11) *card = 'J'; else if(count == 12) *card = 'Q'; else if(count == 13) *card = 'K'; putStringLarge(large_font, 100, 40, "NUM ", 0, 15); putStringLarge(large_font, 150, 40, card, 0, 15); pick = (rand()%13)+1; if(pick<11) *card = ('0'+pick); else if(pick == 11) *card = 'J'; else if(pick == 12) *card = 'Q'; else if(pick == 13) *card = 'K'; else if(pick == 14) *card = 'P'; putStringLarge(large_font, 100, 50, "CARD ", 0, 15); putStringLarge(large_font, 150, 50, card, 0, 15); time = 0; turn = 2; int ran = (rand()%4)+1; //show_image(poker[0][0],100,20); drawCmdWindow(); } break;//show_image(*(poker+1),0,0); //drawCmdWindow(); case VK_ESCAPE: break; } } if(winTimes==3) { Loser2(50,35);//send location Winner2(300,35);//send location showingPlane =1; } else if(loseTimes==3) { Loser2(300,35);//send location Winner2(50,35);//send location showingPlane =1; } }
void Menu(void) { /* 啟動鍵盤控制 */ initializeKeyInput(); //show_image(poker[0][3],150,100); char ch; int place = 0; int color1[3]; int color2[3]; //initialize bottoms int i; for( i=0; i<3; i++) { if(i==n) { color1[i] = 12; color2[i] = 12; } else { color1[i] = 2; color2[i] = 2; } } putStringLarge(large_font, 100, 20, "MENU", 15, 15); putStringLarge(large_font, 50, 30+10*1, "Single Player Mode", color1[0], color2[0]); putStringLarge(large_font, 50, 30+10*2, "Two Players Mode", color1[1], color2[1]); putStringLarge(large_font, 50, 30+10*3, "Help", color1[2], color2[2]); putStringLarge(large_font, 180, 100, "CTRL TO SETECT", 7, 7); ch = getKeyEventVirtual(); switch(ch) { case VK_UP: n = (n+2)%3; break; case VK_DOWN: n = (n+1)%3; break; case VK_CONTROL: switch(n) { case 0: showingPlane = 2; break; case 1: showingPlane = 3; break; case 2: showingPlane = 4; break; default: break; } } }