// Draw the control. void Slider::draw(void) { // Draw the background. drawBackground(); // Draw the thumb. if(!(isClear(m_thumbColor) && isClear(m_thumbOutlineColor))) { float relativePosition = 0.0; if(m_maxValue != m_minValue) { relativePosition = ((float)(m_position-m_minValue)) / (m_maxValue-m_minValue); } Rect thumbRect = m_rect; if(m_vertical) { // Vertical thumb. thumbRect.size.height = m_thumbLength * m_rect.size.height; thumbRect.origin.y += (1.0 - relativePosition) * (m_rect.size.height-thumbRect.size.height); } else { // Horizontal thumb. thumbRect.size.width = m_thumbLength * m_rect.size.width; thumbRect.origin.x += relativePosition * (m_rect.size.width-thumbRect.size.width); } m_thumbRect = thumbRect; // Want to save away the bigger version for mouse hits. thumbRect.inset(Size(.01,.01)); drawRect(thumbRect, m_thumbColor); drawRectOutline(thumbRect, m_thumbOutlineColor, 1.0); } }
//Draw window background. void Window::drawBackground( void ) { m_texture.draw( m_rect ); if ( !isClear( m_color ) ) drawRect( m_rect, m_color ); if ( !isClear( m_outlineColor ) ) drawRectOutline( m_rect, m_outlineColor, m_outlineWidth ); }
FiltrationResult AbstractValue::filter(Graph& graph, const StructureSet& other) { if (isClear()) return FiltrationOK; // FIXME: This could be optimized for the common case of m_type not // having structures, array modes, or a specific value. // https://bugs.webkit.org/show_bug.cgi?id=109663 m_type &= other.speculationFromStructures(); m_arrayModes &= other.arrayModesFromStructures(); m_currentKnownStructure.filter(other); // It's possible that prior to the above two statements we had (Foo, TOP), where // Foo is a SpeculatedType that is disjoint with the passed StructureSet. In that // case, we will now have (None, [someStructure]). In general, we need to make // sure that new information gleaned from the SpeculatedType needs to be fed back // into the information gleaned from the StructureSet. m_currentKnownStructure.filter(m_type); if (m_currentKnownStructure.hasSingleton()) setFuturePossibleStructure(graph, m_currentKnownStructure.singleton()); filterArrayModesByType(); filterValueByType(); return normalizeClarity(); }
void MapGenerator::placeDoodad(int x, int y) { sf::IntRect doodadRect(x, y, 1, 1); if (isClear(doodadRect)) { std::vector<sf::Vector2i> doodadSprites; doodadSprites.push_back(sf::Vector2i(2, 4)); doodadSprites.push_back(sf::Vector2i(3, 4)); doodadSprites.push_back(sf::Vector2i(3, 5)); doodadSprites.push_back(sf::Vector2i(3, 6)); doodadSprites.push_back(sf::Vector2i(3, 8)); doodadSprites.push_back(sf::Vector2i(4, 8)); if (x >= 0 && x < mMap.getWidth() && y >= 0 && y < mMap.getHeight()) { mMap[x][y].setSprite(1, doodadSprites[std::rand() % doodadSprites.size()]); mMap[x][y].setCollidable(true); mMap[x][y].setOccupied(true); } } }
bool AbstractValue::mergeOSREntryValue(Graph& graph, JSValue value) { AbstractValue oldMe = *this; if (isClear()) { FrozenValue* frozenValue = graph.freeze(value); if (frozenValue->pointsToHeap()) { m_structure = frozenValue->structure(); m_arrayModes = asArrayModes(frozenValue->structure()->indexingType()); } else { m_structure.clear(); m_arrayModes = 0; } m_type = speculationFromValue(value); m_value = value; } else { mergeSpeculation(m_type, speculationFromValue(value)); if (!!value && value.isCell()) { Structure* structure = value.asCell()->structure(); graph.registerStructure(structure); mergeArrayModes(m_arrayModes, asArrayModes(structure->indexingType())); m_structure.merge(StructureSet(structure)); } if (m_value != value) m_value = JSValue(); } checkConsistency(); assertIsRegistered(graph); return oldMe != *this; }
//displays every game enemy in the current level void displayGameEnemies(){ attron(COLOR_PAIR(MONSTER_COLOR)); for(int i=0;i<ENTS;i++) if(ISTRUE==isClear(getDist(enemies[i].coords.x,chara.coords.x), getDist(enemies[i].coords.y,chara.coords.y))) if(enemies[i].alive==ISTRUE) mvaddch(enemies[i].coords.y,enemies[i].coords.x,ENEMY); attroff(COLOR_PAIR(MONSTER_COLOR)); }
FiltrationResult AbstractValue::filterArrayModes(ArrayModes arrayModes) { ASSERT(arrayModes); if (isClear()) return FiltrationOK; m_type &= SpecCell; m_arrayModes &= arrayModes; return normalizeClarity(); }
// Calculate the thumb colors based on the specified background color. void Slider::setThumbColorBasedOnColor(const GFXColor& c) { if(!isClear(c)) { if(isColorLight(c)) { // Light color. Make thumb darker. setThumbColor(darkenColor(c,.3), GUI_OPAQUE_WHITE()); } else { // Dark Color. setThumbColor(lightenColor(c,.3), GUI_OPAQUE_WHITE()); } } }
FiltrationResult AbstractValue::filter(SpeculatedType type) { if (isClear()) return FiltrationOK; if (type == SpecTop) return isClear() ? Contradiction : FiltrationOK; m_type &= type; // It's possible that prior to this filter() call we had, say, (Final, TOP), and // the passed type is Array. At this point we'll have (None, TOP). The best way // to ensure that the structure filtering does the right thing is to filter on // the new type (None) rather than the one passed (Array). m_currentKnownStructure.filter(m_type); m_futurePossibleStructure.filter(m_type); filterArrayModesByType(); filterValueByType(); return normalizeClarity(); }
void solveNQueens(vector<vector<string> > &res, vector<string> &board, int index, int n) { if(index == n) { res.push_back(board); return; } for(int i=0; i<n; i++) { if(isClear(board, i, index, n)) { board[i][index] = 'Q'; solveNQueens(res, board, index+1, n); board[i][index] = '.'; } } }
//displays the current map void displayGameMap(){ for(int yy=0;yy<sizeof(map)/sizeof(char*);yy++) for(int xx=0;xx<strlen(map[0]);xx++) if(ISTRUE==isClear(getDist(xx,chara.coords.x),getDist(yy,chara.coords.y))){ if(map[yy][xx]=='.'){ attron(COLOR_PAIR(DEFAULT_COLOR)); mvaddch(yy,xx,map[yy][xx]); attroff(COLOR_PAIR(DEFAULT_COLOR)); }else attron(COLOR_PAIR(WALL_COLOR)); mvaddch(yy,xx,map[yy][xx]); attroff(COLOR_PAIR(WALL_COLOR)); }else mvaddch(yy,xx,UNKNOWN); }
void AbstractValue::checkConsistency() const { if (!(m_type & SpecCell)) { ASSERT(m_currentKnownStructure.isClear()); ASSERT(m_futurePossibleStructure.isClear()); ASSERT(!m_arrayModes); } if (isClear()) ASSERT(!m_value); if (!!m_value) ASSERT(mergeSpeculations(m_type, speculationFromValue(m_value)) == m_type); // Note that it's possible for a prediction like (Final, []). This really means that // the value is bottom and that any code that uses the value is unreachable. But // we don't want to get pedantic about this as it would only increase the computational // complexity of the code. }
//RETURNS 1 if there are n squares of uncarved rock in direction d, 0 o/w int shMapLevel::enoughClearance (int x, int y, shDirection d, int m, int n) { int x1, x2; int y1, y2; switch (d) { case kNorth: if (y < 5) return 0; x1 = x - n; x2 = x + n; y1 = y - m; y2 = y - 1; break; case kSouth: if (y > mRows - 5) return 0; x1 = x - n; x2 = x + n; y1 = y + 1; y2 = y + m; break; case kEast: if (x > mColumns - 6) return 0; x1 = x + 1; x2 = x + m; y1 = y - n; y2 = y + n; break; case kWest: if (x < 6) return 0; x1 = x - m; x2 = x - 1; y1 = y - n; y2 = y + n; break; default: abort (); } return isClear (x1, y1, x2, y2); }
void MapGenerator::placeKrimsKrams(int x, int y) { sf::IntRect krimsRect(x, y, 1, 1); if (isClear(krimsRect)) { std::vector<sf::Vector2i> krimsSprites; krimsSprites.push_back(sf::Vector2i(0, 8)); krimsSprites.push_back(sf::Vector2i(1, 8)); krimsSprites.push_back(sf::Vector2i(2, 8)); krimsSprites.push_back(sf::Vector2i(4, 6)); if (x >= 0 && x < mMap.getWidth() && y >= 0 && y < mMap.getHeight()) { mMap[x][y].setSprite(1, krimsSprites[std::rand() % krimsSprites.size()]); mMap[x][y].setCollidable(false); mMap[x][y].setOccupied(true); } } }
void AbstractValue::checkConsistency() const { if (!(m_type & SpecCell)) { ASSERT(m_structure.isClear()); ASSERT(!m_arrayModes); } if (isClear()) ASSERT(!m_value); if (!!m_value) { SpeculatedType type = m_type; // This relaxes the assertion below a bit, since we don't know the representation of the // node. if (type & SpecInt52) type |= SpecInt52AsDouble; ASSERT(mergeSpeculations(type, speculationFromValue(m_value)) == type); } // Note that it's possible for a prediction like (Final, []). This really means that // the value is bottom and that any code that uses the value is unreachable. But // we don't want to get pedantic about this as it would only increase the computational // complexity of the code. }
vector<vector<string> > solveNQueens(int n) { vector<vector<string> > res; if(n==2 || n == 3 || n <= 0) { return res; } // use 1d vector to store the // index of queens on the row vector<int> index(n, -1); //initialization int k=0; index[0] = 0; // consider kth row while(k >= 0) { if(k < n && index[k] < n) { while(!isClear(index, k)) { index[k] } } } }
//aqui recebe uma string e são tratados todos os chars para o proposito do programa int calcular(char g_char[], pilha *p){ if( isEnter(g_char[0]) || !isEmpty(p)){ int i = 0; while(g_char[i] != '\0'){ //insere o estado dos calculos if(!isClear(g_char[i]) && !isConsulta(g_char[i])){ if(isEmpty(p)) printf("- "); consulta_inversa(p); printf("\n"); } //se for numero insere na pilha if(isNum(g_char[i])){ insertNum(p, g_char[i] - 48); //se o char anterior tbm for numero faz calculo para fazer dos 2 um numero if(isNum(g_char[i-1] )|| isEnter(g_char[i-1])) faz_calculo(p); else{ clear_calc(p); if(!RUN_CODES){ exibeHeader(); printf("\nErro! Voce deve usar necessariamente \'E\' para informar a entrada de um numero\n"); } } i++; continue; } //se for um E insere 0 na pilha if(isEnter(g_char[i])){ insertNum(p, 0); i++; continue; } //se for '-' faz uma subtração if(g_char[i] == '-'){ faz_sub(p); i++; continue; } //se for '+' faz uma adição if(g_char[i] == '+'){ faz_soma(p); i++; continue; } //se for '/' faz uma divisão if(g_char[i] == '/'){ faz_div(p); i++; continue; } //se for '*' faz uma multiplicação if(g_char[i] == '*'){ faz_mult(p); i++; continue; } //se for '^' faz uma potencia if(g_char[i] == '^'){ faz_pow(p); i++; continue; } //se for '!' faz um fatorial if(g_char[i] == '!'){ faz_fatorial(p); i++; continue; } //se for C limpa a pilha if(isClear(g_char[i])){ clear_calc(p); if(!RUN_CODES){ exibeHeader(); printf("\nPilha Vazia\n"); } i++; continue; } //se for V faz uma consulta na pilha if(isConsulta(g_char[i]) && strlen(g_char) == 1){ if(!RUN_CODES) consulta(p); i++; } } if(!isConsulta(g_char[i-1])) //consulta que exibe a pilha ao contrario consulta_inversa(p); if(!RUN_CODES) printf("\n"); return 0; }else{ //se o char indice 0 for V exibe a consulta if(isConsulta(g_char[0])) if(!RUN_CODES) consulta(p); else{ //se o char indice 0 for C limpa a pilha if(isClear(g_char[0])) clear_calc(p); else return 1; } } }
int main(void){ /*マス目の確保 端の一列は空のまま使うので余分に2列多く取る*/ //MINE_TABLE table[MINE_TABLE_HIGHT + 2][MINE_TABLE_WIDTH + 2]; MINE_TABLE **table; /*マス目メモリ領域確保*/ table = getMemory(MINE_TABLE_WIDTH,MINE_TABLE_HIGHT); /*マス目初期化*/ init_mine_table(table); printf("\n座標を入力し、行動を数値で入力して下さい。\n" "(q でプログラム終了します。)\n" "(r でゲームをリスタートします。)\n"); while(1){ /*マス目表示*/ view_mine_table(table,debug); /*登録処理*/ printf("\n(d でデバッグ表示します。)" "例:x y no\n" "x,y:座標 no:1 めくる 2 フラグ立て\n" "-->"); gets(char_temp);/*文字入力受付*/ if(strcmp("q",char_temp) == 0){ printf("終了します。\n"); return 0; }else if(strcmp("d",char_temp) == 0){ if(debug == 0){ debug = 1;/*デバッグ表示ON*/ }else if(debug == 1){ debug = 0;/*デバッグ表示OFF*/ } }else if(strcmp("r",char_temp) == 0){ /*ゲーム初期化*/ init_mine_table(table); continue; } /*入力受付*/ sscanf(char_temp,"%d %d %d",&y,&x,&no); /*マス目を開く*/ if(no == 1){ if(isBomd(table,x,y)){/*爆弾なら*/ if(isOpend(table,x,y)){ printf("そのマスは既に開いています。\n"); }else{ gameover();/*ゲームオーバー*/ } }else{ if(isOpend(table,x,y)){ /*既に開かれている数字の周りを自動で開く*/ open_mine_table_execute(table,x,y); }else{ /*未開拓領域を開く*/ open_mine_table(table,x,y); } } }else if(no == 2){ if(isOpend(table,x,y)){ printf("そのマスは既に開いています。\n"); }else{ /*印をつける*/ check_flag_mine_table(table,x,y); } } if(isClear(table)){/*クリアーなら*/ gameclear(); } } return(0); }
// Draw the picker void Picker::draw(void) { // If we need to change the displayed cells, do that first. if(m_needRecalcDisplay) { recalcDisplay(); } // Draw the background. drawBackground(); const float cellHeight = totalCellHeight(); // This is the current cell rect. Start with control rect and adjust y. Rect rect(m_rect); rect.origin.y += m_rect.size.height - cellHeight; rect.size.height = cellHeight; for(int i=m_scrollPosition; i<m_displayCells.size() && rect.origin.y > m_rect.origin.y; i++) { DisplayCell& display = m_displayCells[i]; const PickerCell* cell = display.cell; // Get the next cell. // Figure background and text color. GFXColor backgroundColor = GUI_CLEAR; GFXColor textColor = cell->textColor(); if(cell == m_selectedCell) { // Selected state more important than highlighted state. backgroundColor = m_selectionColor; if(isClear(textColor)) textColor = m_selectionTextColor; } // Selection color might be clear, or might be highlighted cell. if(isClear(backgroundColor) && cell == m_highlightedCell) { // Highlighted cell. backgroundColor = m_highlightColor; if(isClear(textColor)) textColor = m_highlightTextColor; } if(!isClear(backgroundColor)) { drawRect(rect, backgroundColor); } // If we haven't got a text color yet, use the control's color. if(isClear(textColor)) textColor = m_textColor; // Include indent in drawing rect. // Indent is based on cell height. const float indentPerLevel = m_displayCells[i].level * cellHeight * CHILD_INDENT_FACTOR; Rect drawRect = rect; drawRect.inset(m_textMargins); drawRect.origin.x += indentPerLevel; drawRect.size.width -= indentPerLevel; // Paint the text. // There is a PaintText object in each DisplayCell so that we don't have to re-layout the text // all the time. This code should be smarter about only setting the attributes of the text // object when things change, but that means cell changes need to be communicated back to // this object, and they aren't now. display.paintText.setRect(drawRect); display.paintText.setText(cell->text()); display.paintText.setFont(m_font); display.paintText.setColor(textColor); display.paintText.draw(); rect.origin.y -= cellHeight; } }
/*======================================= ウィンドウプロシージャ処理 コールバック関数 メッセージを受け取りそれぞれ処理する ---------------------------------------*/ LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam){ /*マス目配列アドレス情報*/ MINE_TABLE **table; HDC hdc; PAINTSTRUCT ps; int id = 0; int difficulty = DIFFICULT;/*初期難易度*/ int size_x,size_y; switch(msg){ case WM_DESTROY: PostQuitMessage(0); break; case WM_CLOSE: id = MessageBox(hWnd, (LPCSTR)"終了しますか", (LPCSTR)"終了確認", MB_OKCANCEL | MB_ICONQUESTION); if(id == IDOK) DestroyWindow(hWnd); return (0L); case WM_PAINT: hdc = BeginPaint(hWnd,&ps); ShowMyBMP(hWnd,hdc); TextOut(hdc,50,50,"まいんすい〜ぱ",14); SetBkMode(hdc,TRANSPARENT); SetTextColor(hdc,RGB(255,0,0)); TextOut(hdc,50,100,"池田健太 試作",14); EndPaint(hWnd,&ps); break; case WM_COMMAND: switch(LOWORD(wParam)){ case EXIT_GAME: SendMessage(hWnd,WM_CLOSE,wParam,lParam); case HELP: MessageBox(hWnd, (LPCSTR)"ヘルプが押されました", (LPCSTR)"test", MB_OK); break; case VERSION_INFO: MessageBox(hWnd, (LPCSTR)"バージョン情報が押されました", (LPCSTR)"About", MB_OK); break; case NEW_GAME: /*難易度ごとにテーブルサイズを指定*/ if(difficulty == DIFFICULT_EASY){ size_x = size_y = EASY_TABLE_SIZE; }else if(difficulty == DIFFICULT_NORMAL){ size_x = size_y = NORMAL_TABLE_SIZE; }else if(difficulty == DIFFICULT_HARD){ size_x = size_y = HARD_TABLE_SIZE; } /*マス目メモリ領域確保*/ table = getMemory(size_x,size_y); /*マス目初期化*/ init_mine_table(table); /* printf("\n座標を入力し、行動を数値で入力して下さい。\n" "(q でプログラム終了します。)\n" "(r でゲームをリスタートします。)\n"); */ while(1){ break;/*デバッグ用*/ /*マス目表示*/ //view_mine_table(table,debug); /*登録処理*/ /*printf("\n(d でデバッグ表示します。)" "例:x y no\n" "x,y:座標 no:1 めくる 2 フラグ立て\n" "-->"); */ //gets(char_temp);/*文字入力受付*/ if(strcmp("q",char_temp) == 0){ printf("終了します。\n"); return 0; }else if(strcmp("d",char_temp) == 0){ if(debug == 0){ debug = 1;/*デバッグ表示ON*/ }else if(debug == 1){ debug = 0;/*デバッグ表示OFF*/ } }else if(strcmp("r",char_temp) == 0){ /*ゲーム初期化*/ init_mine_table(table); continue; } /*入力受付*/ //sscanf(char_temp,"%d %d %d",&y,&x,&no); /*マス目を開く*/ if(no == 1){ if(isBomd(table,x,y)){/*爆弾なら*/ if(isOpend(table,x,y)){ printf("そのマスは既に開いています。\n"); }else{ gameover();/*ゲームオーバー*/ } }else{ if(isOpend(table,x,y)){ /*既に開かれている数字の周りを自動で開く*/ open_mine_table_execute(table,x,y); }else{ /*未開拓領域を開く*/ open_mine_table(table,x,y); } } }else if(no == 2){ if(isOpend(table,x,y)){ printf("そのマスは既に開いています。\n"); }else{ /*印をつける*/ check_flag_mine_table(table,x,y); } } if(isClear(table)){/*クリアーなら*/ gameclear(); } } return(0); } break; default: return(DefWindowProc(hWnd,msg,wParam,lParam)); } return (0L); }
void MapGenerator::placeTree(int x, int y) { int width = std::rand() % 4 + 2; int height = std::rand() % 4 + 3; sf::IntRect treeRect(x - 1, y - 1, width, height ); if (isClear(treeRect)) { //first make all tiles occupied: for (int i = treeRect.left; i < treeRect.left + treeRect.width; i++) { for (int j = treeRect.top; j < treeRect.top + treeRect.height; j++) { int tileX = i; int tileY = j; if (tileX >= 0 && tileX < mMap.getWidth() && tileY >= 0 && tileY < mMap.getHeight()) { mMap[tileX][tileY].setOccupied(true); } } } //then place corners: if (treeRect.left >= 0 && treeRect.left < mMap.getWidth() && treeRect.top >= 0 && treeRect.top < mMap.getHeight()) { mMap[treeRect.left][treeRect.top].setSprite(2, sf::Vector2i(3, 0)); mMap[treeRect.left][treeRect.top].setCollidable(false); } if (treeRect.left + treeRect.width - 1 >= 0 && treeRect.left + treeRect.width - 1 < mMap.getWidth() && treeRect.top >= 0 && treeRect.top < mMap.getHeight()) { mMap[treeRect.left + treeRect.width - 1][treeRect.top].setSprite(2, sf::Vector2i(4, 0)); mMap[treeRect.left + treeRect.width - 1][treeRect.top].setCollidable(false); } if (treeRect.left >= 0 && treeRect.left < mMap.getWidth() && treeRect.top + treeRect.height - 1 >= 0 && treeRect.top + treeRect.height - 1 < mMap.getHeight()) { mMap[treeRect.left][treeRect.top + treeRect.height - 1].setSprite(2, sf::Vector2i(3, 1)); mMap[treeRect.left][treeRect.top + treeRect.height - 1].setCollidable(false); } if (treeRect.left + treeRect.width - 1 >= 0 && treeRect.left + treeRect.width - 1 < mMap.getWidth() && treeRect.top + treeRect.height - 1 >= 0 && treeRect.top + treeRect.height - 1 < mMap.getHeight()) { mMap[treeRect.left + treeRect.width - 1][treeRect.top + treeRect.height - 1].setSprite(2, sf::Vector2i(4, 1)); mMap[treeRect.left + treeRect.width - 1][treeRect.top + treeRect.height - 1].setCollidable(false); } //place mid leaves! THERE ARE NONE! for (int i = treeRect.left + 1; i < treeRect.left + treeRect.width - 1; i++) { for (int j = treeRect.top + 1; j < treeRect.top + treeRect.height - 1; j++) { int tileX = i; int tileY = j; if (tileX >= 0 && tileX < mMap.getWidth() && tileY >= 0 && tileY < mMap.getHeight()) { mMap[tileX][tileY].setSprite(2, sf::Vector2i(4, 5)); mMap[tileX][tileY].setCollidable(false); } } } //NOW PLACE EDGES! OVER AND OTHER MOTHERFATHERS! for (int i = treeRect.left + 1; i < treeRect.left + treeRect.width - 1; i++) { int tileX = i; int tileY = treeRect.top; if (tileX >= 0 && tileX < mMap.getWidth() && tileY >= 0 && tileY < mMap.getHeight()) { mMap[tileX][tileY].setSprite(2, sf::Vector2i(3, 2)); mMap[tileX][tileY].setCollidable(false); } } for (int i = treeRect.left + 1; i < treeRect.left + treeRect.width - 1; i++) { int tileX = i; int tileY = treeRect.top + treeRect.height - 1; if (tileX >= 0 && tileX < mMap.getWidth() && tileY >= 0 && tileY < mMap.getHeight()) { mMap[tileX][tileY].setSprite(2, sf::Vector2i(4, 3)); mMap[tileX][tileY].setCollidable(false); } } for (int i = treeRect.top + 1; i < treeRect.top + treeRect.height - 1; i++) { int tileX = treeRect.left; int tileY = i; if (tileX >= 0 && tileX < mMap.getWidth() && tileY >= 0 && tileY < mMap.getHeight()) { mMap[tileX][tileY].setSprite(2, sf::Vector2i(4, 2)); mMap[tileX][tileY].setCollidable(false); } } for (int i = treeRect.top + 1; i < treeRect.top + treeRect.height - 1; i++) { int tileX = treeRect.left + treeRect.width - 1; int tileY = i; if (tileX >= 0 && tileX < mMap.getWidth() && tileY >= 0 && tileY < mMap.getHeight()) { mMap[tileX][tileY].setSprite(2, sf::Vector2i(4, 4)); mMap[tileX][tileY].setCollidable(false); } } //BUT BEFORE WE LEAVE: PLACE DA F*****G TRUNK SON! for (int i = treeRect.left + 1; i < treeRect.left + treeRect.width - 1; i++) { int tileX = i; int tileY = treeRect.top + treeRect.height; if (tileX >= 0 && tileX < mMap.getWidth() && tileY >= 0 && tileY < mMap.getHeight()) { mMap[tileX][tileY].setSprite(1, sf::Vector2i(2, 3)); mMap[tileX][tileY].setCollidable(true); } } //EDGES if (treeRect.left >= 0 && treeRect.left < mMap.getWidth() && treeRect.top + treeRect.height >= 0 && treeRect.top + treeRect.height < mMap.getHeight()) { mMap[treeRect.left][treeRect.top + treeRect.height].setSprite(1, sf::Vector2i(1, 3)); mMap[treeRect.left][treeRect.top + treeRect.height].setCollidable(true); } if (treeRect.left + treeRect.width - 1 >= 0 && treeRect.left + treeRect.width - 1 < mMap.getWidth() && treeRect.top + treeRect.height >= 0 && treeRect.top + treeRect.height < mMap.getHeight()) { mMap[treeRect.left + treeRect.width - 1][treeRect.top + treeRect.height].setSprite(1, sf::Vector2i(3, 3)); mMap[treeRect.left + treeRect.width - 1][treeRect.top + treeRect.height].setCollidable(true); } } }
void MapGenerator::placeHut(int x, int y) { int width = std::rand() % 3 + 3; int height = std::rand() % 3 + 3; sf::IntRect hutRect(x - width / 2, y - height / 2, width, height ); if (width % 2 == 0) x-=1; if (height % 2 == 0) y-=1; if (isClear(hutRect)) { //first make all tiles occupied for (int i = hutRect.left; i < hutRect.left + hutRect.width; i++) { for (int j = hutRect.top; j < hutRect.top + hutRect.height; j++) { int tileX = i; int tileY = j; if (tileX >= 0 && tileX < mMap.getWidth() && tileY >= 0 && tileY < mMap.getHeight()) { mMap[tileX][tileY].setOccupied(true); } } } //then place corners: if (hutRect.left >= 0 && hutRect.left < mMap.getWidth() && hutRect.top >= 0 && hutRect.top < mMap.getHeight()) { mMap[hutRect.left][hutRect.top].setSprite(2, sf::Vector2i(0, 0)); mMap[hutRect.left][hutRect.top].setCollidable(false); } if (hutRect.left + hutRect.width - 1 >= 0 && hutRect.left + hutRect.width - 1 < mMap.getWidth() && hutRect.top >= 0 && hutRect.top < mMap.getHeight()) { mMap[hutRect.left + hutRect.width - 1][hutRect.top].setSprite(2, sf::Vector2i(2, 0)); mMap[hutRect.left + hutRect.width - 1][hutRect.top].setCollidable(false); } if (hutRect.left >= 0 && hutRect.left < mMap.getWidth() && hutRect.top + hutRect.height - 1 >= 0 && hutRect.top + hutRect.height - 1 < mMap.getHeight()) { mMap[hutRect.left][hutRect.top + hutRect.height - 1].setSprite(1, sf::Vector2i(0, 2)); mMap[hutRect.left][hutRect.top + hutRect.height - 1].setCollidable(true); } if (hutRect.left + hutRect.width - 1 >= 0 && hutRect.left + hutRect.width - 1 < mMap.getWidth() && hutRect.top + hutRect.height - 1 >= 0 && hutRect.top + hutRect.height - 1 < mMap.getHeight()) { mMap[hutRect.left + hutRect.width - 1][hutRect.top + hutRect.height - 1].setSprite(1, sf::Vector2i(2, 2)); mMap[hutRect.left + hutRect.width - 1][hutRect.top + hutRect.height - 1].setCollidable(true); } //place roof! for (int i = hutRect.left + 1; i < hutRect.left + hutRect.width - 1; i++) { for (int j = hutRect.top + 1; j < hutRect.top + hutRect.height - 1; j++) { int tileX = i; int tileY = j; if (tileX >= 0 && tileX < mMap.getWidth() && tileY >= 0 && tileY < mMap.getHeight()) { mMap[tileX][tileY].setSprite(2, sf::Vector2i(0, 3)); mMap[tileX][tileY].setCollidable(true); } } } //then place chimney! if (x >= 0 && x < mMap.getWidth() && y >= 0 && y < mMap.getHeight()) { mMap[x][y].setSprite(2, sf::Vector2i(1, 1)); mMap[x][y].setCollidable(true); } //NOW PLACE WALLS! OVER AND OUT MOTHERFAKKARS! for (int i = hutRect.left + 1; i < hutRect.left + hutRect.width - 1; i++) { int tileX = i; int tileY = hutRect.top; if (tileX >= 0 && tileX < mMap.getWidth() && tileY >= 0 && tileY < mMap.getHeight()) { mMap[tileX][tileY].setSprite(2, sf::Vector2i(1, 0)); mMap[tileX][tileY].setCollidable(false); } } for (int i = hutRect.left + 1; i < hutRect.left + hutRect.width - 1; i++) { int tileX = i; int tileY = hutRect.top + hutRect.height - 1; if (tileX >= 0 && tileX < mMap.getWidth() && tileY >= 0 && tileY < mMap.getHeight()) { mMap[tileX][tileY].setSprite(1, sf::Vector2i(1, 2)); mMap[tileX][tileY].setCollidable(true); } } for (int i = hutRect.top + 1; i < hutRect.top + hutRect.height - 1; i++) { int tileX = hutRect.left; int tileY = i; if (tileX >= 0 && tileX < mMap.getWidth() && tileY >= 0 && tileY < mMap.getHeight()) { mMap[tileX][tileY].setSprite(1, sf::Vector2i(0, 1)); mMap[tileX][tileY].setCollidable(true); } } for (int i = hutRect.top + 1; i < hutRect.top + hutRect.height - 1; i++) { int tileX = hutRect.left + hutRect.width - 1; int tileY = i; if (tileX >= 0 && tileX < mMap.getWidth() && tileY >= 0 && tileY < mMap.getHeight()) { mMap[tileX][tileY].setSprite(1, sf::Vector2i(2, 1)); mMap[tileX][tileY].setCollidable(true); } } //BUT FIRST PLACE DA F*****G DOOR! if (x >= 0 && x < mMap.getWidth() && hutRect.top + hutRect.height - 1 >= 0 && hutRect.top + hutRect.height - 1 < mMap.getHeight()) { mMap[x][hutRect.top + hutRect.height - 1].setSprite(1, sf::Vector2i(0, 4)); mMap[x][hutRect.top + hutRect.height - 1].setCollidable(true); } } }
//------------------------------------------------------------------------------ void Game::removePiece() { if ( ! isClear() ) { return; } m_replay[m_num][0] = m_index; m_replay[m_num][1] = m_rotate; m_replay[m_num][2] = m_row; m_replay[m_num][3] = m_col; m_num += 1; for ( int x = 0; x < 4; ++x ) { for ( int y = 0; y < 4; ++y ) { if ( ! m_piece[x][y] ) { continue; } m_buffer[m_col + x - 3][m_row + y - 3] = false; } } for ( int y = 19; y > 0; --y ) { int count( 0 ); for ( int x = 0; x < 10; ++x ) { if ( m_buffer[x][y] ) { break; } ++count; } if ( count < 10 ) { continue; } for ( int x = 0; x < 10; ++x ) { for ( int i = y; i > 0; --i ) { m_buffer[x][i] = m_buffer[x][i-1]; } } } int count( 0 ); for ( int x = 0; x < 10; ++x ) { for ( int y = 0; y < 20; ++y ) { m_arena[x][y] = m_buffer[x][y]; if ( m_arena[x][y] ) { count += 1; } } } if ( count == 0 ) { m_replaying = true; m_row = 1; clearArena(); } }
//RETURNS: # of doors int shMapLevel::buildRoomOrElRoom (int sx, int sy, int ey) { int ex; int x; int y; int ndoors = 0; int doortries = 0; int ra = 0 == RNG (20); for (ex = sx + 2; ex < mColumns; ex++) { if ((ex > sx + 4) and (0 == RNG(7))) { /* check for nearby hallway */ if (isClear (ex, sy, mColumns, ey)) { do { --sx; --ex; } while (isClear (sx, sy, sx, ey)); ++sx; break; } while (1) { if (RNG (2)) { if (isClear (sx, ey, ex, ey)) { ey++; sy++; if (ey >= mRows) { return -1; } } else { break; } } else if (isClear (ex, sy, ex, ey)) { ex++; sx++; } else { break; } } } if (!isClear (ex, sy, ex, ey - 1)) { break; } } for (x = sx + 1; x < ex -1; x++) { for (y = sy + 1; y < ey -1; y++) { SETSQ (x, y, kFloor); if (ra) { SETSQFLAG (x, y, kRadioactive); } } } /* add walls */ for (x = sx + 1; x < ex - 1; x++) { SETSQ (x, sy, kHWall); SETSQ (x, ey - 1, kHWall); } for (y = sy + 1; y < ey - 1; y++) { SETSQ (sx, y, kVWall); SETSQ (ex - 1, y, kVWall); } SETSQ (sx, sy, kNWCorner); SETSQ (sx, ey - 1, kSWCorner); SETSQ (ex - 1, sy, kNECorner); SETSQ (ex - 1, ey - 1, kSECorner); /* add doors */ while ((doortries < 122) and (ndoors < 1 + RNG (ex - sx) / 4)) { if (RNG (2)) { x = RNG (sx + 1, ex - 2); y = RNG (2) ? sy : ey -1; if (TESTSQ (x, y - 1, kFloor) and TESTSQ (x, y + 1, kFloor)) { SETSQ (x, y, kFloor); addDoor (x, y, 0 == RNG (4), 0 == RNG (5), -1); ++ndoors; } } else { y = RNG (sy + 1, ey - 1); x = RNG (2) ? sx : ex - 1; if (TESTSQ (x - 1, y, kFloor) and TESTSQ (x + 1, y, kFloor)) { SETSQ (x, y, kFloor); addDoor (x, y, 0 == RNG (4), 0 == RNG (5), -1); ++ndoors; } } ++doortries; } return ndoors; }
/** * Deallocate the chunk of memory at address ptr * * @param ptr The address of the chunk to deallocate * * @return None */ void free(void* ptr) { Run* run_ptr=NULL, *prev_run_ptr=NULL; int bit_index=0; int ret=0; LargeChunk *lc_ptr=NULL, *prev_ptr=NULL; // Check to see if ptr is a large chunk if(((unsigned int)ptr & 0xfff) == 0 && largeChunks != NULL) { for(lc_ptr = largeChunks; lc_ptr!= NULL && lc_ptr->memory != ptr; prev_ptr=lc_ptr, lc_ptr=lc_ptr->next); } // If ptr is a large chunk if (lc_ptr != NULL) { if((ret = deallocate(ptr, lc_ptr->size))) _terminate(4); lc_ptr->memory = 0; lc_ptr->size = 0; if(prev_ptr == NULL) largeChunks = lc_ptr->next; else prev_ptr->next = lc_ptr->next; free(lc_ptr); return; } // Find the run the ptr belongs to int j; for(j=0; j<POOL_NUM; j++) { int found=0; for(run_ptr = pool[j], prev_run_ptr=NULL; run_ptr != NULL; prev_run_ptr=run_ptr, run_ptr=run_ptr->next) { if(run_ptr->memory == ((void *)((unsigned int)ptr & 0xfffff000))) { found=1; break; } } if(found) break; } // No run found if(run_ptr == NULL) return; // Free and zero chunk bit_index = (ptr - run_ptr->memory) / run_ptr->size; clearBit(run_ptr->bitmap, bit_index); //bzero(ptr, run_ptr->size); // Deallocate empty run if(isClear(run_ptr->bitmap)) { if(prev_run_ptr == NULL) pool[j] = run_ptr->next; else prev_run_ptr->next = run_ptr->next; if((ret = deallocate(run_ptr->memory, _SC_PAGESIZE))) _terminate(4); clearRun(run_ptr); if((ret = deallocate(run_ptr, _SC_PAGESIZE))) _terminate(4); run_ptr = NULL; } }