void GenBoard(context_t *ctxt) { int i = 0, x, y; free(ctxt->board); ctxt->board = malloc(ctxt->rows * ctxt->columns * sizeof(*(ctxt->board))); if(ctxt->board == NULL) { fprintf(stderr, "Unable to malloc board in GenBoard !\n"); exit(EXIT_FAILURE); } for(x = 0; x < ctxt->rows; ++x) { for(y = 0; y < ctxt->columns; ++y) { ctxt->board[x*ctxt->columns + y].visited = SDL_FALSE; ctxt->board[x*ctxt->columns + y].value = 0; ctxt->board[x*ctxt->columns + y].flagged = SDL_FALSE; } } do { x = rand() % ctxt->columns; y = rand() % ctxt->rows; if(ctxt->board[y*ctxt->columns + x].value != MINE) { SetMine(ctxt, x, y); ++i; } } while(i != ctxt->nbombs); }
void ns_Game::Update( NETFunc::Game *game ) { SetMine(game->IsCurrentSession()); m_locked = strlen(game->GetPassword()) ? g_netshell->GetTrueBmp() : 0; m_closed = (game->IsClosed() || game->IsHostile() || game->GetFree() == 0) ? g_netshell->GetTrueBmp() : 0; m_launched = game->IsLaunched() ? g_netshell->GetTrueBmp() : 0; m_name = game->GetName(); m_players = game->GetPlayers(); }