// by 한나 void drop() { int i, j, A; srand(time(0)); int Q; while (1) { Q = 0; for (i = 0; i < BOARD_WIDTH; i++) { for (j = 0; j < BOARD_HEIGHT; j++) { if (board[i][j] == 0) { if (j - 1 >= 0) { board[i][j] = board[i][j - 1]; DrawBoard(i, j); if (TEST == T) Sleep(75); // 시험중 board[i][j - 1] = 0; DrawBoard(i, j - 1); Sleep(75); } } } } for (i = 0; i < BOARD_WIDTH; i++) { for (j = 0; j < BOARD_HEIGHT; j++) { if (board[i][0] == 0) { board[i][j] = rand() % RANDOM + 1; DrawBoard(i, j); Sleep(100); } } } for (i = 0; i < BOARD_WIDTH; i++) { for (j = 0; j < BOARD_HEIGHT; j++) { if (board[i][j] != 0) { Q++; } } } if (Q == 64)break; } BackColor(' '); color(15); SetCursors(50, 10); printf("score:%5d", score); if (score > s_limit && timer <= t_limit) { level++; if (level % 2 == 0) t_limit -= 3; if (level % 2 == 1) RANDOM++; score = 0; } else if ((end - start)>500); start = clock(); }
void CGame::PlayTurn() { int x,y; scare_mouse(); DrawBoard(); DrawPlayer(); DrawScores(); DrawCursor(); blit(background, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); unscare_mouse(); while (!players[currplayer].Done()) { if (mouse_b & 1) { x = mouse_x; y = mouse_y; players[currplayer].HandleMouse(x,y); rest (200); //rest for a bit so it doesnt keep catching mouse clicks scare_mouse(); DrawBoard(); DrawScores(); //shouldnt have to redraw this, but i dont have time to do a decent redraw management system if (!players[currplayer].Done()) DrawPlayer(); //only redraw if not at end of turn DrawCursor(); blit(background, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); unscare_mouse(); } }//end while players[currplayer].ResetTurnComplete(); //update currplayer int oldcurrplayer; oldcurrplayer = currplayer; do { if (currplayer == (numplayers-1)) { //if currplayer is last in line currplayer = 0; } else { currplayer++; } //stop increment currplayer if the curr isnt playing AND we have gone through the whole list already } while (!players[currplayer].stillplaying && currplayer != oldcurrplayer); }
Coordinates GetToCoordsforpawn(piecol *Board[8][8]) { Coordinates Tocoords, FromCoords; DrawBoard(Board); while (!ValidCoordsforpawn(FromCoords, ToCoords, Board) { DrawBoard(Board); printf("Invalid Coordinates for a pawn! move piece where?\n"); ToCoords = GetInput(); } return ToCoords; }
uint64 PERFD (typePOS* POSITION, int n) { int i; uint64 TOTAL = 0, TIME; typeMoveList LM[256], *lm; DrawBoard (POSITION); TIME = GetClock(); Mobility (POSITION); if (IN_CHECK) lm = EvasionMoves (POSITION, LM, 0xffffffffffffffff); else { lm = CaptureMoves (POSITION, LM, POSITION->OccupiedBW); lm = OrdinaryMoves (POSITION, lm); } for (i = 0; i < lm - LM; i++) { Make (POSITION, LM[i].move); Mobility (POSITION); if (!ILLEGAL) { printf ("%s ",Notate (LM[i].move, STRING1[POSITION->cpu])); PERFT (POSITION, n - 1); TOTAL += CNT[n - 1]; } Undo (POSITION, LM[i].move); } printf ("TOTAL %lld moves %ld time: %lld us\n", TOTAL, lm - LM, GetClock() - TIME); return TOTAL; }
void TestFull() { int i, x, y, ty; int count = 0; static int arScoreInfo[] = { 0, 1, 3, 8, 20 }; for (i = 0; i < 4; i++) { board[nx + Shape[brick][rot][i].x][ny + Shape[brick][rot][i].y] = BRICK; // 벽돌의 위치 기록 } for (y = 1; y < BH + 1; y++) { for (x = 1; x < BW + 1; x++) { if (board[x][y] != BRICK) break; // 벽돌이 없는칸이 있으면 루프를 빠져나온다. } if (x == BW + 1) // 벽돌로 꽉 차있다. { count++; for (ty = y; ty>1; ty--) { for (x = 1; x < BW + 1; x++) { board[x][ty] = board[x][ty - 1]; // 보드 배열에서 제거될 벽돌의 정보를 삭제 } } DrawBoard(); delay(200); Score = Score + arScoreInfo[count]; PrintInfo(); } } }
//响应绘图 VOID CMainWnd::OnPaint(WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hDC;//窗口DC HDC hMemDC;//缓存窗口DC HBITMAP hBitmap, hOldBitmap; hDC = BeginPaint(hWnd, &ps); hMemDC = CreateCompatibleDC(hDC);//创建兼容DC hBitmap = CreateCompatibleBitmap(hDC, rtClient.right - rtClient.left, rtClient.bottom - rtClient.top);//创建位图 hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);//将位图选入兼容DC if (ps.rcPaint.left <= rtBackground.right) { if (ps.rcPaint.left<rtBoard.left || ps.rcPaint.right>rtBoard.right || ps.rcPaint.top<rtBoard.top || ps.rcPaint.bottom<rtBoard.bottom) FillBkAndBoard(hMemDC);//绘制主体界面背景 DrawBoard(hMemDC);//绘制棋盘 } if (ps.rcPaint.right >= rtBoardPart.left) { DrawCtrlBoard(hMemDC);//绘制操作面板 } BitBlt(hDC, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right - ps.rcPaint.left, ps.rcPaint.bottom - ps.rcPaint.top, hMemDC, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);//用兼容DC图像更新窗口图像 DeleteObject(hBitmap); DeleteDC(hMemDC); EndPaint(hWnd, &ps); return; }
//--------------------------------------------------------------------------- void __fastcall TMainForm::FormShow(TObject *Sender) { // Загрузка изображений фигур LoadImage("b"); LoadImage("w"); LoadImage("bbb"); LoadImage("bbw"); LoadImage("bkb"); LoadImage("bkw"); LoadImage("bnb"); LoadImage("bnw"); LoadImage("bpb"); LoadImage("bpw"); LoadImage("bqb"); LoadImage("bqw"); LoadImage("brb"); LoadImage("brw"); LoadImage("wbb"); LoadImage("wbw"); LoadImage("wkb"); LoadImage("wkw"); LoadImage("wnb"); LoadImage("wnw"); LoadImage("wpb"); LoadImage("wpw"); LoadImage("wqb"); LoadImage("wqw"); LoadImage("wrb"); LoadImage("wrw"); // Задание размеров формы MainForm->Width = size * 8 + 4; MainForm->Height = MainForm->Width + 41; // Рисование доски DrawBoard(); }
void CTicTacView::OnDraw(CDC* pDC) { CTicTacDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here DrawBoard(pDC); }
/* The level is stored 'compressed', taking up 38 bytes a time. * byte 0 - position of ball * byte 1 - position of box * 2-37 - Level data * * Level data is stored as two bits per block, so we have to shift our * picked up byte round to get it. */ void SetupLevel(void) { int x; char *ptr,*ptr2; /* Fresh level, so start with the ball */ PieceIsBall = FALSE; ptr2 = Board; /* We copy to the Board */ ptr = levels + (Level * 38); /* from the Level data */ /* First two bytes are the ball and the box position */ BallOffset = *ptr++; BoxOffset = *ptr++; /* Decompress Level into the Board */ for (x=0; x!=36; x++) { *ptr2++=((*ptr)>>6)&3; *ptr2++=((*ptr)>>4)&3; *ptr2++=((*ptr)>>2)&3; *ptr2++=( *ptr) &3; ptr++; } /* Put the ball and box into their Board position */ *(Board+BallOffset) = BALL; *(Board+BoxOffset) = BOX; DrawBoard(); /* Display the clean Board */ }
/* * Function: main * ----------------- * Serves as entry point of program. Takes in all user inputs to determine specific boggle configuration. * Then, it gives the user a chance to find words in the boggleBoard. Then, the computer takes over * to find any remaining words. Finally, gives user option to play another round. * *@return 0 if program completed successfully. */ int main() { Randomize(); //initializes random constructor SetWindowSize(8, 5); InitGraphics(); Welcome(); GiveInstructions(); Lexicon wordList("lexicon.dat"); //generates list of all possible words while (true) { Lexicon usedWords; //generates a list that stores all words found by the player and computer InitGraphics(); SoundFeature(); int boardDimension = BoggleBoardSize(); DrawBoard(boardDimension, boardDimension); Grid<char> boggleBoard(boardDimension, boardDimension); if (!UserBoardConfiguration()) { InitializeRandomBoard(boggleBoard); //if user chooses not to specify board configuration, a random one is generated } else { string diceConfig = GetDiceConfiguration(boardDimension); SetDiceConfiguration(boggleBoard, diceConfig); } DrawBoggleBoard(boggleBoard); Grid<bool> usedDice(boggleBoard.numRows(), boggleBoard.numCols()); CreateMarker(usedDice); InputGuesses(boggleBoard, wordList, usedWords, usedDice); //player's turn FindRemainingWords(boggleBoard, wordList, usedWords, usedDice); //computer's turn PlayNamedSound("thats pathetic.wav"); //assumes the player will always lose to the computer if (!GameContinue()) break; } return 0; }
void InitializeGame(int x_cur, int y_cur) { int i,j; for (i=0; i<15; i++) { for (j=0; j<15; j++) { board_state[i][j]=EMPTY; } } DrawNumber(level,3,2,EMPTY); DrawWinning(0,1, EMPTY); DrawStatus(1, 21, EMPTY,PVP); DrawBack(3,1119,EMPTY); count=0; time0=0; turn=HUMAN_PLAYER; step_flag=0; win_flag=0; DrawBoard(); DrawChess(x_cur, y_cur, CURSOR); DrawTime(88, EMPTY); DrawTime(30, turn); DrawStatus(1, 21, COMPUTER_PLAYER,PVP); xil_printf("\r\nGame Start!\r\n"); }
void InitializeGame() { game.Initialize(); srand(time(NULL)); game.playerIDList.push_back(2); game.SetGamerAI(2, 10); DrawBoard(); }
Coordinates GetFromCoords(Dudes *Board[8][8]) { Coordinates Coords; DrawBoard(Board); printf("Move which piece?\n"); Coords = GetInput(); while (!ValidateCoords(Coords.X, Coords.Y)) { DrawBoard(Board); printf("Invalid Coordinates! Select a piece to move:\n"); Coords = GetInput(); } return Coords; }
/********************************************************************* * * ThreadGUI() * * Function description: * GUI thread to redraw the board if neccessary. * * */ VOID ThreadGUI(PVOID pvoid) { do { if(_redraw == 1) { DrawBoard(); _redraw = 0; } Sleep(10); } while (_close != 1); }
Coordinates GetToCoords(Dudes *Board[8][8]) { Coordinates Coords; DrawBoard(Board); printf("Move piece to where?\n"); Coords = GetInput(); while (!ValidateCoords(Coords.X, Coords.Y)) { DrawBoard(Board); printf("Invalid Coordinates! move piece where?\n"); Coords = GetInput(); } return Coords; }
void main() { int x; DrawBoard(); //Black Rook PutPiece (0,0,P_ROOK,P_BLACK); PutPiece (7,0,P_ROOK,P_BLACK); //Black Knight PutPiece (1,0,P_KNIGHT,P_BLACK); PutPiece (6,0,P_KNIGHT,P_BLACK); //Black Bishop PutPiece (2,0,P_BISHOP,P_BLACK); PutPiece (5,0,P_BISHOP,P_BLACK); //Black Queen PutPiece (3,0,P_QUEEN,P_BLACK); //Black King PutPiece (4,0,P_KING,P_BLACK); //Black Pawn for (x=0 ; x!=8; x++) { PutPiece (x,1,P_PAWN,P_BLACK); } //White Pawn for (x=0 ; x!=8; x++) { PutPiece (x,6,P_PAWN,P_WHITE); } //White Rook PutPiece (0,7,P_ROOK,P_WHITE); PutPiece (7,7,P_ROOK,P_WHITE); //White Knight PutPiece (1,7,P_KNIGHT,P_WHITE); PutPiece (6,7,P_KNIGHT,P_WHITE); //White Bishop PutPiece (2,7,P_BISHOP,P_WHITE); PutPiece (5,7,P_BISHOP,P_WHITE); //White Queen PutPiece (3,7,P_QUEEN,P_WHITE); //White King PutPiece (4,7,P_KING,P_WHITE); }
void Play() { //Use a quit flag to start a game loop bool quit = false; SDL_Event event; Uint32 lastEvent = 0; while(!quit) { //While there are events to pull... while(SDL_PollEvent(&event) != 0) { //Handle each one //SDL_QUIT is something like hitting the Red X on the top right of screen. Also added support for ESC quit if(event.type == SDL_QUIT) { quit = true; } if(event.key.keysym.sym == SDLK_ESCAPE) { quit = true; //Menu(); //continue; } for(int i = 0; i != TILE_TOTAL; ++i) { tTiles[i].HandleEvent(&event, lastEvent); } //std::cout << lastEvent <<std::endl; } if(IWin('X')) { std::cout << "\n\nX Wins" << std::endl; ResetGame(); } else if(IWin('O')) { std::cout << "\n\nO Wins" << std::endl; ResetGame(); } //If its not my turn, let the computer go if(isMyTurn == false) { ComputersTurn(); } //Clear screen with white SDL_SetRenderDrawColor(theRenderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(theRenderer); DrawBoard(); SDL_RenderPresent(theRenderer); } //Quit is true at this point so we return return; }
void MainWindow::paintEvent(QPaintEvent* event){ QPainter painter(this); DrawBoard(painter); if (!promotion && startPiece){ QPen pen(Qt::red); painter.setPen(pen); painter.drawRect(startX*CELL_SIZE, startY*CELL_SIZE, CELL_SIZE, CELL_SIZE); DrawPossibleMoves(painter); } DrawStatus(painter); }
// draw 3D void Tetris::Draw(game_info* gi) { if (!engine.network_thread && gi->side == 1) { return; } DrawBoard(gi); DrawPiece(gi, (0.5) * (double)gi->pos, gi->fine); }
// ----------------------------------------------------------------------------- // CSIPExGameView::DrawGame // Draws the game view. Decides whether we should draw the board or cursor // or not // ----------------------------------------------------------------------------- // void CSIPExGameView::DrawGame( CWindowGc& aGc, const TRect& aRect ) const { if( iEngine->DrawBoard() ) { DrawBoard(aGc, aRect); if( iEngine->DrawCursor() ) { DrawCursor(aGc, aRect); } } }
/***** MAIN BLOCK *****/ int main(void) { InitGen(); DrawBoard(); side = LIGHT; xside = DARK; computerside = DARK; do { if (side == computerside) ComputerThink(); else if (GetHumanMove()) break; side = xside; xside = 1-xside; } while (!UpdateNewMove()); }
void AnimateDeadPlayer(void *pCtx, state *ptr) { int iFrame = 0; char *szAnim = "|Vv_.+*X*+. "; do { DrawBoard(pCtx, ptr); DrawPills(pCtx, ptr); attron(A_BOLD | COLOR_PAIR(PC_PACMAN)); mvaddch(ptr->Player.Pos.y, ptr->Player.Pos.x, szAnim[iFrame]); attroff(A_BOLD | COLOR_PAIR(PC_PACMAN)); Blit(pCtx); usleep(150000); } while(++iFrame < strlen(szAnim)); }
void Board::OnRender(SDL_Surface *surf, int x, int y) { DrawBoard(); SDL_Rect desc; desc.x = x; desc.y = y; SDL_Rect src; src.x = 0; src.y = 0; src.w = board_surface->w; src.h = board_surface->h; SDL_BlitSurface(board_surface, &src, surf, &desc); }
static gboolean configure_event_cb (GtkWidget *widget, GdkEventConfigure *event, gpointer data) { if (surface) cairo_surface_destroy(surface); surface = gdk_window_create_similar_surface(gtk_widget_get_window(widget), CAIRO_CONTENT_COLOR, CanvasWidth, CanvasWidth); DrawBoard(); gtk_widget_queue_draw_area(widget, 0, 0, CanvasWidth, CanvasWidth); return TRUE; }
void main() { #ifdef __ZX80__ gen_tv_field_init(0); #endif #ifdef DKTRONICS #asm ld a,$2a ld i,a #endasm #else #ifndef TEXT /* Load user defined graphics onto ZX81 set */ /* Quicksilva position */ memcpy(0x8400, sprites, 136); /* ROM position */ memcpy(0x1e00, sprites, 136); /* Others */ memcpy(0x8e00, sprites, 136); memcpy(0x9e00, sprites, 136); memcpy(0x2e00, sprites, 136); /* dk'tronics (quick board test: PEEK 11905 must give 32)*/ memcpy(0x3000, sprites, 136); memcpy(0x3200, sprites, 136); #asm ld a,$30 ld i,a #endasm #endif #endif /* Interesting way to find the display file address ! */ /* (we're working in text mode, with redefinded font) */ display=d_file+1; #ifdef CHROMA81 display_attr=d_file+1+32768; #asm ld bc,7FEFh ld a,16+8+5 ; 8="attribute file" mode, (border 7) out (c),a #endasm #endif DrawBoard(); /* Loop keyhandler till you finished the game */ while (CheckNotFinished()) Gamekeys(); }
// Game::Start void Game::Start() { if( this->GameMode == MODE_NET_HOST ) { this->Server = new GameServer(DEFAULT_PORT); } if( this->GameMode == MODE_NET_CLIENT ) { this->Client = new GameClient(); } for(;;) { DrawBoard(); Analyze(); NextStep(); } }
void __fastcall TMainForm::ImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if(start.Row == -1) // если выбирается начальная позиция фигуры { start.Row = Y/size; start.Col = X/size; } else // выбрана конечная позиция фигуры { end.Row = Y/size; end.Col = X/size; board.Move(start, end); start.Row = -1; DrawBoard(); } }
int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int) { // check preloaded resources assert(icon!=NULL); assert(bg!=NULL); for (char i=0;i<FIGsz;i++) assert(FIG[i]!=NULL); //Start SDL assert(SDL_Init(SDL_INIT_VIDEO)==0); // load font subsystem assert(TTF_Init()==0); font=TTF_OpenFont( "TTF/WhiteRabbit.ttf", 18 ); assert(font!=0); msg=TTF_RenderText_Solid( font, "sdlBoard: CHESS engine GUI for SSAU Linux", clrmsg); assert(msg!=NULL); // init scr scr = SDL_SetVideoMode( 800, 600, 8, SDL_SWSURFACE ); assert(scr!=NULL); SDL_WM_SetCaption( "sdlBoard: CHESS", NULL ); // update drawing rect with & height to figure sizes rect.w=FIG[0]->w; rect.h=FIG[0]->h; // draw board DrawBoard(); // event loop for (char F_QUIT=0;!F_QUIT;) { // Pause SDL_Delay(100); // event dispatcher while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: F_QUIT=1; } } } // Quit SDL SDL_FreeSurface(icon); SDL_FreeSurface(bg); for (char i=0;i<FIGsz;i++) SDL_FreeSurface(FIG[i]); SDL_Quit(); // fake return fclose(log); return 0; }
// Pass the current turn and update the status bar and history void SimpleGoPanel::MakePass() { if(gnugoscore) { gnugoscore = false; wxClientDC dc(this); DrawBoard(dc, board); } curmove++; history = (char(*)[21][21])realloc(history, (curmove+1)*BOARDMEMORYLEN); memcpy(history[curmove], board, BOARDMEMORYLEN); movelist = (pos*)realloc(movelist, curmove*sizeof(pos)); movelist[curmove-1].x = 0; movelist[curmove-1].y = 0; totmove = curmove; if(curmove>=2 && movelist[curmove-2].x==0 && movelist[curmove-2].y==0) { gnugopause = true; frame->playmenu->Check(ID_RANDOM, false); frame->MakeGNUGoScore(); } else UpdateStatus(); }
void testAI(){ Grid<char> board = makeRandomBoard(StandardCubes); DrawBoard(4,4); addLetters(board); Set<string> results; Lexicon lex("lexicon.dat"); findWords(board, lex, results); Set<string>::Iterator itr = results.iterator(); while ( itr.hasNext() ){ string word = itr.next(); cout << "word: " << word << endl; } }