static void setupgame(int i) { allocgame(i & 2); initgame(); #if !NO_MENU if (!in_menu) goto skipmenu; while (gamemenu()) { in_menu = 0; rm_invitfile(); skipmenu: #endif writeconfig(); do textgfx_entergame(); while (startgame()); #if !NO_MENU clearwin(0); in_menu = 1; textgfx_entermenu(); readoptions(); } inputdevs_player[0] = 0; # ifdef SOCKET rmsocket(); mk_invitfile(); # endif #endif game = NULL; }
// slots that change the map layout by picking level // also emits the signal that starts the game with given inputs void ChooseWindow::pickLevel1(){ level = 1; isVisible = false; emit startgame(level,difficulty); this->close(); }
int main(void) { int choice = showmenu(); switch (choice) { case 1: //New Game loadconsole(); startgame(); // game.c break; case 2: //Load Game break; case 3: //Exit exit(0); // include cleanup code later! default: break; } return 0; }
void loadgame() { clrscr(); printf("Loading\n"); int i,j; for(i = 0;i < 10;i++) { for(j = 0;j <= 100000000;j++); printf("."); } printf("\nGame is loaded,press enter to play\n"); int snakeXY[2][MAX_SIZE]; int snakelength = 4; int dir = LEFT; int foodXY[0]; int score = 0; int consolewidth = 80; int consoleheight = 25; int speed = getgamespeed(); snakeXY[0][0] = 40; snakeXY[1][0] = 10; border(consolewidth, consoleheight); initsnake(snakeXY, snakelength); loadsnake(snakeXY,snakelength); foodcreate(foodXY,consolewidth,consoleheight,snakeXY,snakelength); scoreboard(score,speed); startgame(snakeXY, foodXY, consolewidth, consoleheight, snakelength, dir, score, speed); }
void MainWindow::showEvent(QShowEvent *){ //初始化 startgame(); //計時器 connect(&timer,SIGNAL(timeout()),this,SLOT(tick())); connect(this,SIGNAL(quitGame()),this,SLOT(QUITSLOT())); timer.start(10); }
/* called when a mouse button is pressed or released */ void MouseButton(int button,int state,int x,int y) { if(gameOver && y<ButtonHEIGHT+ButtonY && y>ButtonY && x<ButtonWIDTH+ButtonX && x>ButtonX && state == GLUT_UP) { printf("play again clicked. Score was: (not yet implemented) \n"); ismovingD = false; ismovingL = false; ismovingR = false; ismovingU = false; startgame(); gameOver = false; glutTimerFunc(milliSecondsIntervalForSpawningNewSpaceObjects, spawnNewSpaceObjects, 0); } if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { if(mouseSuperBallAcceleration == true) { mouseSuperBallAcceleration = false; superBallSAX=0; superBallSAY=0; } else { mouseSuperBallAcceleration = true; } } }
int main(int argc, char **argv) { superBallSPositionX = 300; superBallSPositionY= 400; superBallSRadius = 80; superBallSSpeedX = 0.0f; superBallSSpeedY = 0.0f; glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); glutInitWindowSize( glutGet(GLUT_SCREEN_WIDTH),glutGet(GLUT_SCREEN_HEIGHT) ); glutInitWindowPosition(400,150); char* s = "Super Ball"; glutCreateWindow(s); screenWidth = glutGet(GLUT_WINDOW_WIDTH);//glutGet(GLUT_SCREEN_WIDTH); screenHeight = glutGet(GLUT_WINDOW_HEIGHT);//glutGet(GLUT_SCREEN_HEIGHT); phidgetManag = new PhidgetManager(); phidgetManag->start(); startgame(); //load the textures: //texture_bomb = LoadTexture("bomb.bmp"); texture_bomb = TextureLoad("bomb.bmp", GL_FALSE, /* I - Generate alpha for bitmap */ GL_LINEAR_MIPMAP_LINEAR, /* I - Minification filter */ GL_LINEAR, /* I - Magnification filter */ GL_REPEAT); /* glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); int imageWidth = 300; int imageHeight = 278; GLsizei sWidth, sHeight; sWidth = nearestPower( imageWidth ); sHeight = nearestPower( imageHeight ); imageData = (GLubyte *)malloc( sHeight*sWidth*4*sizeof( GLubyte ) ); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData); //the texture width and height must be a power of two glEnable( GL_TEXTURE_2D ); */ glutFullScreen(); glutTimerFunc(milliSecondsIntervalForSpawningNewSpaceObjects, spawnNewSpaceObjects, 0); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(MouseButton); glutMotionFunc(MouseMove); glutIdleFunc(spindisplay); glutSpecialFunc(specialKeys); glutKeyboardFunc(keyboard); //start_the_Thread_with_the_Socket_TCP_server(); glutMainLoop(); }
static int keyman_handle_event(GR_EVENT * event) { int ret = 0; switch( event->type ) { case( GR_EVENT_TYPE_TIMER ): switch(GAMEN){ case MENU: makemenu(); MINIPHOTO(0,0,160,128); wlastkey.AR=0;wlastkey.AL=0;wlastkey.AU=0;wlastkey.AD=0;wlastkey.REE=0;wlastkey.PAU=0; break; case INGAME: if (wlastkey.AL==1){wnow.LR=-1;wnow.MUKI=-1;} else if(wlastkey.AR==1){wnow.LR=1;wnow.MUKI=1;} else {wnow.LR=0;} if(wlastkey.REE==1){ if(wnow.JIMEN==ZIM){ wnow.YKANSEI=-9; wnow.JIMEN=SORA; } else if (wnow.HASIGO==1){ wnow.YKANSEI=-9; wnow.JIMEN=SORA; wnow.HASIGO=0; } } if (INIT(wnow.XLOC+8,wnow.YLOC+8,'G')==FALSE){wnow.HASIGO=0;} if (INIT(wnow.XLOC+8,wnow.YLOC+8,'G')== TRUE && wlastkey.AU !=0){ wnow.HASIGO=1; wnow.shupict=2; //GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,32,112,0); wnow.XKANSEI=0; //wnow.YLOC=wnow.YLOC-3; } else if (INIT(wnow.XLOC+8,wnow.YLOC+8,'G')== TRUE && wlastkey.AD !=0){ wnow.HASIGO=0; //GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,32,112,0); wnow.XKANSEI=0; //wnow.YLOC=wnow.YLOC+3; } if (wnow.JIMEN==ZIM){wnow.XKANSEI=(0.9*wnow.XKANSEI)+(1*wnow.LR);} else { if (wnow.LR != 0){ wnow.XKANSEI=(0.99*wnow.XKANSEI)+(0.3*wnow.LR); } } if (wnow.HASIGO==0 ){ if (wnow.YKANSEI <= 6){ wnow.YKANSEI++; } } else {wnow.YKANSEI=0;} wnow.XLOC=wnow.XLOC+wnow.XKANSEI; wnow.YLOC=wnow.YLOC+wnow.YKANSEI; if (wnow.NUPDW==-1 && ((wnow.MAPSCROLL) % 16)==0){wnow.YLOC=wnow.YLOC+16;} else if (wnow.NUPDW==1 && (wnow.MAPSCROLL % 16)==15){wnow.YLOC=wnow.YLOC-16;} if (wnow.MAPSCROLL>0 && wnow.MAPSCROLL<TATEHABA*16){ wnow.MAPSCROLL=wnow.MAPSCROLL+wnow.NUPDW; } scr= (wnow.MAPSCROLL/16); ATARI2(); if (wlastkey.AU != 1 && wlastkey.AD != 1){ if (wnow.MUKI==1){ wnow.shupict=0; //GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,0,112,0); } else { wnow.shupict=1; //GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,16,112,0); } } if (wnow.NUPDW==-1 && wnow.YLOC>136){ wdeady.sp=-20; wdeady.g=1.6; wdeady.nowt=128; GAMEN=END; wdeady.kaiten=0; ketumatu=0; wdeady.deadcount=1;} else if(wnow.NUPDW==1 && wnow.YLOC<0){ wdeady.sp=12; wdeady.g=0; wdeady.nowt=-16; GAMEN=END; wdeady.kaiten=0; ketumatu=0; wdeady.deadcount=1;} else if (wnow.NUPDW==0 && (wnow.YLOC>136)) { wdeady.sp=-10; wdeady.g=1.6; wdeady.nowt=128; GAMEN=END; wdeady.kaiten=0; ketumatu=0; wdeady.deadcount=1;} GrCopyArea(mainmenu_pixmap,keyman_gc,0,0,160,128,allmap_pixmap,0,wnow.MAPSCROLL,0); kmbitmap(); //GrCopyArea(mainmenu_pixmap,keyman_gc,wnow.XLOC,(wnow.YLOC-(wnow.MAPSCROLL % 16)),160,128,shu_pixmap,0,0,0); hensu(); MINIPHOTO(0,0,160,128); if (wlastkey.PAU==1){GAMEN=PAUSE;} wlastkey.AR=0;wlastkey.AL=0;wlastkey.AU=0;wlastkey.AD=0;wlastkey.REE=0;wlastkey.PAU=0; break; case PAUSE: GrCopyArea(dialogall_pixmap,keyman_gc,0,0,96,80,dialog_pixmap,0,0,0); GrCopyArea(dialogall_pixmap,keyman_gc,3,24+(dialogkey*24),13,16,yomipict_pixmap,115,48,0); GrCopyArea(keyman_wid,keyman_gc,32+((screen_info.cols-160)/2),24+((screen_info.rows-128)/2),96,80,dialogall_pixmap,0,0,0); break; case END: if (ketumatu==0){ wdeady.sp=wdeady.sp+wdeady.g; wdeady.nowt=wdeady.nowt+wdeady.sp; //sprintf(hensuu,"%d",wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW)); if (wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW)>0 && wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW)<TATEHABA*16){ GrCopyArea(mainmenu_pixmap,keyman_gc,0,0,160,128,allmap_pixmap,0,wnow.MAPSCROLL+(wdeady.deadcount*wnow.NUPDW),0); } GrCopyArea(shu_pixmap,keyman_gc,0,0,16,16,yomipict_pixmap,wdeady.kaiten*16,16,0); GrCopyArea(mainmenu_pixmap,keyman_gc,wnow.XLOC,wdeady.nowt,160,128,shu_pixmap,0,0,0); hensu(); MINIPHOTO(0,0,160,128); if (wdeady.kaiten<7){wdeady.kaiten++;}else{wdeady.kaiten=0;} if (training==0){ if (wdeady.deadcount>31){GAMEN=MENU; } } else if (training==1){ if (wdeady.deadcount>15){opencard();GAMEN=INGAME; } } wdeady.deadcount++; } else if (ketumatu==1){ if (training==0){ GAMEN=MENU; } if (training==1){ if (tranum>=MAXTRA){ GAMEN=MENU; } else{ startgame(); GAMEN=INGAME; } } } break; case NODATA: GrSetGCForeground(keyman_gc, WHITE); GrFillRect(keyman_wid,keyman_gc,0,0,160,128); GrSetGCForeground(keyman_gc, GRAY); GrLine(keyman_wid,keyman_gc,80,20,34,100); GrLine(keyman_wid,keyman_gc,80,20,126,100); GrLine(keyman_wid,keyman_gc,34,100,126,100); GrEllipse(keyman_wid,keyman_gc,80,55,5,20); GrEllipse(keyman_wid,keyman_gc,80,85,5,5); GrSetGCForeground(keyman_gc, BLACK); GrText(keyman_wid,keyman_gc,50,48,"Please Copy",-1,GR_TFASCII|GR_TFTOP); GrText(keyman_wid,keyman_gc,30,68,"KMData folder to /etc",-1,GR_TFASCII|GR_TFTOP); GrText(keyman_wid,keyman_gc,50,100,"Click to Quit",-1,GR_TFASCII|GR_TFTOP); break; } break; case( GR_EVENT_TYPE_KEY_DOWN ): switch(GAMEN){ case INGAME: if (event->keystroke.ch==wsetkey.KLEFT){wlastkey.AL=1;}else{wlastkey.AL=0;} if (event->keystroke.ch==wsetkey.KRIGHT){wlastkey.AR=1;}else{wlastkey.AR=0;} if (event->keystroke.ch==wsetkey.KUP){wlastkey.AU=1;}else{wlastkey.AU=0;} if (event->keystroke.ch==wsetkey.KDOWN){wlastkey.AD=1;}else{wlastkey.AD=0;} if (event->keystroke.ch==wsetkey.KJUMP){wlastkey.REE=1;}else{wlastkey.REE=0;} if (event->keystroke.ch==wsetkey.KPAUSE){wlastkey.PAU=1;}else{wlastkey.PAU=0;} break; case MENU: switch( event->keystroke.ch ) { case '\r': /* action */ switch (wmenukey.BA){ case 0:if (wmenukey.KEY<2){wmenukey.KEY++;}else{wmenukey.KEY=1;}break; case 1:if (wmenukey.STAGE<MAXSTAGE){wmenukey.STAGE++;} else {wmenukey.STAGE=1;} break; case 2: GAMEN=INGAME; training=0; startgame(); break; case 3:GAMEN=INGAME; tranum=0; training=1; startgame(); break; case 4: pz_close_window(keyman_wid); GrDestroyTimer(keyman_timer); GrUnmapWindow(keyman_wid); GrDestroyWindow(keyman_wid); GrFreeImage(kmimage_id); GrDestroyGC(keyman_gc); ret = 1; break; } break; case 'r': /* CCW spin */ if (wmenukey.BA<4){ipod_beep();wmenukey.BA++;} break; case 'l': /* CW spin */ if (wmenukey.BA>0){ipod_beep();wmenukey.BA--;} break; case 'm': /* menu */ pz_close_window(keyman_wid); GrDestroyTimer(keyman_timer); GrUnmapWindow(keyman_wid); GrDestroyWindow(keyman_wid); GrFreeImage(kmimage_id); GrDestroyGC(keyman_gc); ret = 1; break; } break; case PAUSE: if (event->keystroke.ch==wsetkey.KLEFT && dialogkey == 1){ipod_beep();dialogkey=0;} if (event->keystroke.ch==wsetkey.KRIGHT && dialogkey == 0){ipod_beep();dialogkey=1;} if (event->keystroke.ch==wsetkey.KJUMP && dialogkey == 0){GAMEN=INGAME;} else if (event->keystroke.ch==wsetkey.KJUMP && dialogkey == 1){GAMEN=MENU;} break; case END:break; case NODATA: if (event->keystroke.ch=='\r'){ GrDestroyTimer(keyman_timer); GrUnmapWindow(keyman_wid); GrDestroyWindow(keyman_wid); GrFreeImage(kmimage_id); GrDestroyGC(keyman_gc); ret = 1; } break; } break; } return ret; }
int main() { char line[256]; char args[4][64]; /* It mainly calls ComputerThink(maxdepth) to calculate to desired ply */ char s[256]; int from; int dest; int i; hashRndInit(); startgame (); maxDepth = 6; /* Max depth to search */ MOVE moveBuf[200]; MOVE theBest; int movecnt; /* Belka */ puts (" \n Kitteneitor version June 5th 2013 by Emilio Diaz \n =================================================\n\n"); puts (" Help overview:"); puts (" making a move: e.g. e2e4, c7c5, a7a8q, e1g1 etc."); puts (" d ............ displaying current board"); puts (" on ........... forcing the engine to move"); puts (" sd <n> ....... setting depth to <n> plies"); puts (" undo ......... taking back last move (ply)"); puts (" quit ......... quit console application \n\n"); /* Belka */ side = WHITE; computerSide = BLACK; /* Human is white side */ hdp = 0; /* Current move order */ for (;;) { fflush (stdout); if (side == computerSide) { /* Computer's turn */ theBest = ComputerThink (maxDepth); if (theBest.type_of_move > 8) printf ("type of move the best %d \n", theBest.type_of_move); makeMove (theBest); /* Just the move without pawn crown */ printf("move %c%d%c%d", 'a' + COL(theBest.from), 8 - ROW(theBest.from), 'a' + COL(theBest.dest), 8 - ROW(theBest.dest)); /* Check whether it's a crown */ switch (theBest.type_of_move) { case MOVE_TYPE_PROMOTION_TO_QUEEN: printf("q\n"); break; case MOVE_TYPE_PROMOTION_TO_ROOK: printf("r\n"); break; case MOVE_TYPE_PROMOTION_TO_BISHOP: printf("b\n"); break; case MOVE_TYPE_PROMOTION_TO_KNIGHT: printf("n\n"); break; default: printf("\n"); } /* end switch */ printBoard (); printf ("Castle rights: %d\n", castle); fflush (stdout); continue; } printf ("k> "); /* Get user input */ if (!fgets (line, 256, stdin)) return 0; if (line[0] == '\n') continue; sscanf (line, "%s", s); // if (scanf ("%s", s) == EOF) /* Shut down the program */ // return 0; if (!strcmp (s, "d")) { printBoard (); continue; } if (!strcmp (s, "test1")) { test1 (); printBoard(); continue; } if (!strcmp (s, "test2")) { test2 (); printBoard(); continue; } if (!strcmp (s, "test3")) { test3 (); printBoard(); continue; } if (!strcmp (s, "test4")) { test4 (); printBoard(); continue; } if (!strcmp (s, "test5")) { test5 (); printBoard(); continue; } if (!strcmp (s, "test6")) { test6 (); printBoard(); continue; } if (!strcmp (s, "test7")) { test7 (); printBoard(); continue; } if (!strcmp (s, "test8")) { test8 (); printBoard(); continue; } if (!strcmp (s, "test9")) { test9 (); printBoard(); continue; } if (!strcmp (s, "test10")) { test10 (); printBoard(); continue; } if (!strcmp (s, "test11")) { test11 (); printBoard(); continue; } if (!strcmp (s, "test12")) { test12 (); printBoard(); continue; } if (!strcmp (s, "test13")) { test13 (); printBoard(); continue; } if (!strcmp (s, "test14")) { test14 (); printBoard(); continue; } if (!strcmp (s, "testMoveGen")) //Belka: McKenzie test position { testMoveGen(); printBoard(); continue; } if (!strcmp (s, "testEvalSym")) //Belka: McKenzie test position { testEvalSym(); continue; } if (!strcmp (s, "countNodes")) { countNodes(); continue; } if (!strcmp (s, "testWhitePassedPawns")) { testWhitePassedPawns (); continue; } if (!strcmp (s, "testBlackPassedPawns")) { testBlackPassedPawns (); continue; } if (!strcmp (s, "testWhiteDoubledPawns")) { testWhiteDoubledPawns (); continue; } if (!strcmp (s, "testBlackDoubledPawns")) { testBlackDoubledPawns (); continue; } if (!strcmp (s, "testIsIsolatedPawnWhite")) { testIsIsolatedPawnWhite (); continue; } if (!strcmp (s, "testIsIsolatedPawnBlack")) { testIsIsolatedPawnBlack (); continue; } if (!strcmp (s, "showPawnsInfo")) { showPawnsInfo (); continue; } if (!strcmp (s, "testisSqProtectedByAPawn")) { testisSqProtectedByAPawn(); continue; } // if (!strcmp (s, "testIsSqProtectedByAKnight")) // { // testIsSqProtectedByAKnight(); // continue; // } // if (!strcmp (s, "testIsSqProtectedByABishop")) // { // testIsSqProtectedByABishop(); // continue; // } if (!strcmp (s, "testOpenCols")) { testOpenCols(); continue; } if (!strcmp (s, "undo")) { takeBack (); printBoard (); computerSide = (WHITE + BLACK) - computerSide; continue; } if (!strcmp(s,"setboard")) { strcpy(fenBuf, ""); sscanf(line, "setboard %s %s %s %s", args[0],args[1],args[2],args[3]); strcat(fenBuf, args[0]); strcat(fenBuf, args[1]); strcat(fenBuf, args[2]); strcat(fenBuf, args[3]); setBoard(fenBuf); continue; } if (!strcmp (s, "xboard")) { xboard (); return 0; } if (!strcmp (s, "on")) { computerSide = side; continue; } if (!strcmp (s, "pass")) { side = (WHITE + BLACK) - side; computerSide = (WHITE + BLACK) - side; continue; } if (!strcmp (s, "sd")) { sscanf (line, "sd %d", &maxDepth); continue; } // if (!strcmp (s, "fen")) // { // strcpy (fenstring, ""); // sscanf (linea, "fen %s %s %s %s", args[0], args[1], args[2], // args[3]); // strcat (fenstring, args[0]); // strcat (fenstring, args[1]); // strcat (fenstring, args[2]); // strcat (fenstring, args[3]); // fen (fenstring); // } if (!strcmp (s, "perft")) { sscanf (line, "perft %d", &maxDepth); clock_t start; clock_t stop; double t = 0.0; /* Start timer */ start = clock (); U64 count = perft (maxDepth); /* Stop timer */ stop = clock (); t = (double) (stop - start) / CLOCKS_PER_SEC; // printf ("nodes = %'llu\n", count); printf ("nodes = %8" PRId64 "\n", count); // Belka printf ("time = %.2f s\n", t); continue; } if (!strcmp (s, "quit")) { printf ("Good bye!\n"); return 0; } /* Maybe the user entered a move? */ from = s[0] - 'a'; from += 8 * (8 - (s[1] - '0')); dest = s[2] - 'a'; dest += 8 * (8 - (s[3] - '0')); ply = 0; movecnt = genMoves (side, moveBuf); /* Loop through the moves to see whether it's legal */ for (i = 0; i < movecnt; i++) if (moveBuf[i].from == from && moveBuf[i].dest == dest) { /* Promotion move? */ if (piece[from] == PAWN && (dest < 8 || dest > 55)) { switch (s[4]) { case 'q': moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_QUEEN; break; case 'r': moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_ROOK; break; case 'b': moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_BISHOP; break; case 'n': moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_KNIGHT; break; default: puts("Promoting to a McGuffin..., I'll give you a queen"); moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_QUEEN; } } if (!makeMove (moveBuf[i])) { takeBack (); printf ("Illegal move.\n"); } break; } printBoard (); } }
void xboard() { char line[256], command[256], c; char args[4][64]; int from, dest, i; MOVE moveBuf[200]; MOVE theBest; int movecnt; //int illegal_king = 0; signal(SIGINT, SIG_IGN); printf ("\n"); // hashKeyPosition(); /* hash of the initial position */ // hashRndInit(); startgame (); /* Waiting for a command from GUI */ for (;;) { fflush (stdout); if (side == computerSide) { /* Computer's turn */ /* Find out the best move to reply to the current position */ theBest = ComputerThink (maxDepth); if (theBest.type_of_move > 8) printf ("type of move the best %d \n", theBest.type_of_move); makeMove (theBest); /* send move */ switch (theBest.type_of_move) { case MOVE_TYPE_PROMOTION_TO_QUEEN: c = 'q'; break; case MOVE_TYPE_PROMOTION_TO_ROOK: c = 'r'; break; case MOVE_TYPE_PROMOTION_TO_BISHOP: c = 'b'; break; case MOVE_TYPE_PROMOTION_TO_KNIGHT: c = 'n'; break; default: c = ' '; } printf ("move %c%d%c%d%c\n", 'a' + COL(theBest.from), 8 - ROW(theBest.from), 'a' + COL(theBest.dest), 8 - ROW(theBest.dest), c); fflush(stdout); continue; } if (!fgets (line, 256, stdin)) return; if (line[0] == '\n') continue; sscanf (line, "%s", command); if (!strcmp (command, "xboard")) { continue; } if (!strcmp (command, "d")) { printBoard (); continue; } if (!strcmp (command, "new")) { startgame (); continue; } if (!strcmp (command, "quit")) { return; } if (!strcmp (command, "force")) { computerSide = EMPTY; continue; } /* If we get a result the engine must stop */ if (!strcmp(command, "result")) { computerSide = EMPTY; continue; } if (!strcmp(command, "?")) { computerSide = EMPTY; continue; } if (!strcmp(command, ".")) { continue; } if (!strcmp(command, "exit")) { continue; } if (!strcmp(command,"setboard")) { strcpy(fenBuf, ""); sscanf(line, "setboard %s %s %s %s", args[0],args[1],args[2],args[3]); strcat(fenBuf, args[0]); strcat(fenBuf, args[1]); strcat(fenBuf, args[2]); strcat(fenBuf, args[3]); setBoard(fenBuf); continue; } if (!strcmp (command, "white")) { side = WHITE; computerSide = BLACK; continue; } if (!strcmp (command, "black")) { side = BLACK; computerSide = WHITE; continue; } if (!strcmp (command, "sd")) { sscanf (line, "sd %d", &maxDepth); continue; } if (!strcmp (command, "go")) { computerSide = side; continue; } /* Taken from TSCP: we receive from the GUI the time we have */ if (!strcmp(command, "time")) { sscanf (line, "time %ld", &maxTime); /* Convert to miliseconds */ maxTime *= 10; maxTime /= 10; maxTime -= 300; totalTime = maxTime; // if (totalTime < 3000) // maxDepth = 6; // else maxDepth = 32; continue; } if (!strcmp(command, "otim")) { continue; } if (!strcmp (command, "undo")) { if (hdp == 0) continue; takeBack (); continue; } if (!strcmp (command, "remove")) { if (hdp <= 1) continue; takeBack (); takeBack (); continue; } /* Maybe the user entered a move? */ /* Is that a move? */ if (command[0] < 'a' || command[0] > 'h' || command[1] < '0' || command[1] > '9' || command[2] < 'a' || command[2] > 'h' || command[3] < '0' || command[3] > '9') { printf("Error (unknown command): %s\n", command); /* No move, unknown command */ continue; } from = command[0] - 'a'; from += 8 * (8 - (command[1] - '0')); dest = command[2] - 'a'; dest += 8 * (8 - (command[3] - '0')); ply = 0; movecnt = genMoves (side, moveBuf); /* Loop through the moves to see if it's legal */ for (i = 0; i < movecnt; ++i) { if (moveBuf[i].from == from && moveBuf[i].dest == dest) { if (piece[from] == PAWN && (dest < 8 || dest > 55)) { if (command[4] != 'q' && command[4] != 'r' && command[4] != 'b' && command[4] != 'n') { printf ("Illegal move. Bad letter for promo\n"); goto goon; } switch (command[4]) { case 'q': moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_QUEEN; break; case 'r': moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_ROOK; break; case 'b': moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_BISHOP; break; case 'n': moveBuf[i].type_of_move = MOVE_TYPE_PROMOTION_TO_KNIGHT; break; } } if (moveBuf[i].type_of_move > 8) printf ("Type of move the best %d \n", moveBuf[i].type_of_move); if (makeMove (moveBuf[i])) { goto goon; /* Legal move */ } else { printf ("Illegal move. King is in check\n"); goto goon; } } } printf ("Illegal move.\n"); /* illegal move */ goon: continue; } }
int main(){ parse("C:\\Users\\Syd\\Desktop\\Various\\Open Text Engine\\Versions\\v4\\game.ote"); startgame("start"); }
bool MainWindow::eventFilter(QObject *, QEvent *event){ QMouseEvent *mouseEvent = (QMouseEvent*) event; if(event->type() == QEvent::MouseButtonPress){ if(mouseEvent->pos().x()<300){ //滑鼠位在此範圍才算準備發射 isPressed = true; if(isFired==true&&skillUsed==false&&done==false&&birdnum<4) //收到發射後使用技能 skillUsed = true; if(done==true) //已使用技能 done=false; } //按下重玩 if(mouseEvent->pos().x()>=550&&mouseEvent->pos().x()<650&&mouseEvent->pos().y()>=30&&mouseEvent->pos().y()<130){ clear(); startgame(); } //按下離開 if(mouseEvent->pos().x()>=800&&mouseEvent->pos().x()<900&&mouseEvent->pos().y()>=30&&mouseEvent->pos().y()<130){ close(); } } if(event->type() == QEvent::MouseMove){ if(isPressed==true&&isFired==false&&skillUsed==false&&done==false){ float x = mouseEvent->pos().x(); float y = mouseEvent->pos().y(); float yy = height() - mouseEvent->pos().y() + 30; //y需顛倒 bird[birdnum]->setPos(x/30.0,yy/30.0); dx = x-init_x*30; //轉成像素相減 dy = -(y-(height()-init_y*30)); //最後再顛倒 } } if(event->type() == QEvent::MouseButtonRelease){ if(isPressed==true&&isFired==false&&skillUsed==false&&done==false&&birdnum<4){ //發射 //根據與準備位置的相對距離決定速度 float vx=-(dx/7.0); float vy=-(dy/10.0); bird[birdnum]->setDynamic(); //設為動態 bird[birdnum]->setVelocity(vx,vy); isPressed = false; isFired = true; if(birdnum<3) //尚未到最後一隻鳥,0.3秒後將下一隻鳥移到準備位置 QTimer::singleShot(300,this,SLOT(newBird())); std::cout<<"shoot"<<std::endl; } if(isFired==true&&skillUsed==true&&birdnum<4){ //收到使用技能 if(birdnum==0&&done==false){ //技能:無 done=true; birdnum++; isFired=false; skillUsed=false; std::cout<<"0 skillused"<<std::endl; } if(birdnum==1&&done==false){ //技能:轉成當前反向速度的10倍 float vx = bird[birdnum]->getVelocity().x; float vy = bird[birdnum]->getVelocity().x; bird[birdnum]->setVelocity(-vx*10,-vy*10); done=true; birdnum++; isFired=false; skillUsed=false; std::cout<<"1 skillused"<<std::endl; } if(birdnum==2&&done==false){ //技能:直線衝刺 bird[birdnum]->setVelocity(100,0); done=true; birdnum++; isFired=false; skillUsed=false; std::cout<<"2 skillused"<<std::endl; } if(birdnum==3&&done==false){ //技能:快速旋轉與墜落 bird[birdnum]->rotate(200); bird[birdnum]->setVelocity(0,-50); done=true; isFired=false; skillUsed=false; QTimer::singleShot(1000,this,SLOT(isAllDone())); std::cout<<"3 skillused"<<std::endl; } } } return false; }