LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CREATE: { hdc = GetDC(hWnd); GetClientRect(hWnd,&rect); int ret = SetTimer(hWnd, TIMER_ID, 5, NULL); initFigures(); break; } case WM_PAINT: { BeginPaint(hWnd, &ps); Paint(hWnd, &ps); EndPaint(hWnd, &ps); } break; case WM_LBUTTONDOWN: { Figure *figure; figure = new Figure(rand()%rect.right, rand()%rect.bottom, 100, 100); figure->setCircle(false); figure->setDir(rand()%4); figure->setVelocity(rand()%8 + 1); figure->setColor(rand()%250, rand()%250, rand()%250); vec.push_back(*figure); vectorSize++; break; } case WM_MOUSEWHEEL : { int deltaZ = (short) HIWORD(wParam); if(deltaZ > 0) { velocity += 2; }else { if(velocity > 0) velocity -= 2; } break; } case WM_TIMER: { InvalidateRect(hWnd, &rect, FALSE); } break; case WM_DESTROY: { KillTimer(hWnd, TIMER_ID); PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, msg, wParam, lParam); }
// draw controls point around a figure void drawSel() { glColor3f(0, 0, 0); int size = figureSet.size(); Figure *f = figureSet[selected]; /* getPoint() is a virtual method: every figure has at least two points (is at least a line) */ int *pt1 = f->getPoint(1)->getCoords(); int *pt2 = f->getPoint(2)->getCoords(); glLoadName(size+1); drawQuad(pt1[0]-3, pt1[1]-3, pt1[0]+3, pt1[1]+3); glLoadName(size+2); drawQuad(pt2[0]-3, pt2[1]-3, pt2[0]+3, pt2[1]+3); if (Triangle *t = dynamic_cast<Triangle*>(f)) { // triangle: one more point int *pt3 = t->getPoint(3)->getCoords(); glLoadName(size+3); drawQuad(pt3[0]-3, pt3[1]-3, pt3[0]+3, pt3[1]+3); } else if (Quad *q = dynamic_cast<Quad*>(f)) { // quad: two more point int *pt3 = q->getPoint(3)->getCoords(); int *pt4 = q->getPoint(4)->getCoords(); glLoadName(size+3); drawQuad(pt3[0]-3, pt3[1]-3, pt3[0]+3, pt3[1]+3); glLoadName(size+4); drawQuad(pt4[0]-3, pt4[1]-3, pt4[0]+3, pt4[1]+3); } }
bool Board::move(const char* from,const char* to ) { unsigned int fromX = from[1] - '1'; unsigned int fromY = from[0] - 'a'; unsigned int toX = to[1] - '1'; unsigned int toY = to[0] - 'a'; Figure* figure = getFigure(Position(fromX, fromY)); if (figure == NULL) { return false; } if (figure->figureColor != moveTurn) { return false; } if (figure->move(Position(toX, toY))) { //change turn moveTurn = !moveTurn; return true; } else { return false; } }
ListDouble dff_1(PackingProblemData data) { ListDouble cnt; Figure f; double byk; double w, h, s; //cout << "\n\nDFF 1 >>>>>>>>>>>>>>\n"; for (int i = 0; i < data.count(); ++i) { byk = 0; f = data[i]; for (int k = 1; k < 100; ++k) { //cout << "\n"; s = 0; for (int j = 0; j < f.count(); ++j) { w = dff_1_func(f[j].width(), k); h = dff_1_func(f[j].height(), k); s += w * h; } if (s > byk) { byk = s; } } cnt.append(byk); } return cnt; }
void ChessWindow::addMove(int oldX, int oldY, int newX, int newY) { Figure *f = nullptr; if(model_->gameType_ == Figure::WhitePlayer) { //for compatibility with tkabber oldY = 7-oldY; newY = 7-newY; f = model_->findFigure(model_->index(newY, newX)); } else if(model_->gameType_ == Figure::BlackPlayer) { f = model_->findFigure(model_->index(7-newY, newX)); oldX = 7-oldX; newX = 7-newX; } QString type = " "; if(f) type = f->typeString(); QString text = ui_.te_moves->toPlainText(); int moveNumber = movesCount+2; if(moveNumber&1) { text += " "+type[0]+model_->headerData(oldX, Qt::Horizontal).toString().toLower()+model_->headerData(oldY, Qt::Vertical).toString()+"-" +model_->headerData(newX, Qt::Horizontal).toString().toLower()+model_->headerData(newY, Qt::Vertical).toString()+"\n"; } else { text += QString::number(moveNumber/2)+". "+type[0]+model_->headerData(oldX, Qt::Horizontal).toString().toLower() +model_->headerData(oldY, Qt::Vertical).toString()+"-"+model_->headerData(newX, Qt::Horizontal).toString().toLower() +model_->headerData(newY, Qt::Vertical).toString(); } ui_.te_moves->setText(text); QTextCursor cur = ui_.te_moves->textCursor(); cur.setPosition(text.length()); ui_.te_moves->setTextCursor(cur); movesCount++; }
ListDouble dff_2(PackingProblemData data) { ListDouble cnt; Figure f; double byk; double w, h, s; //cout << "\n\nDFF 2 >>>>>>>>>>>>>>\n"; for (int i = 0; i < data.count(); ++i) { //cout << "\n"; byk = 0; f = data[i]; for (double k = 0.0; k <= 0.5; k += 0.0001) { s = 0; for (int j = 0; j < f.count(); ++j) { w = dff_2_func(f[j].width(), k); h = dff_2_func(f[j].height(), k); s += w * h; } if (s > byk) { byk = s; } } cnt.append(byk); } return cnt; }
Quantum quantumFragmentation(ListXY xy, Figure f) { ListDouble x = xy.first; ListDouble y = xy.second; double w, h; Figure res; RectByLines rectSource, rectGrid; bool **square = new bool* [x.count() - 1]; for (int i = 0; i < x.count() - 1; ++i) { square[i] = new bool [y.count() - 1]; memset(square[i], false, sizeof(bool) * (y.count() - 1)); for (int j = 0; j < y.count() - 1; ++j) { w = x[i + 1] - x[i]; h = y[j + 1] - y[j]; for (int k = 0; k < f.count(); ++k) { rectSource = fromQRect(f[k]); rectGrid = RectByLines(x[i], x[i + 1], y[j], y[j + 1]); if (isInclude(rectSource, rectGrid)) { res.append(fromLines(rectGrid)); square[i][j] = true; break; } } } } return Quantum(res, square); }
void MainWindow::onTimerTick() { Figure newFig = *cur_figure; newFig.setPosition(newFig.getPosition().x(), cur_figure->getPosition().y() + 1); if (m_cup.hasPlace(newFig)) { delete cur_figure; cur_figure = new Figure(newFig); } else { m_cup.putFigure(*cur_figure); m_score += m_cup.clearedLines() * 100 + (m_cup.clearedLines() > 0 ? 100 : 0); if (m_score >= NEXTLEVELSCORE) { m_score = 0; if (m_level < MAX_LEVEL) m_level++; else endGame(); init(); } delete cur_figure; cur_figure = new Figure(m_cup); if (m_cup.filled()) gameOver(); } draw(); }
void MainWindow::keyPressEvent(QKeyEvent *event) { Figure newFig = *cur_figure; switch(event->key()){ case Qt::Key_Up:{ newFig.rotate(); break; } case Qt::Key_Down: { newFig.setPosition(cur_figure->getPosition().x(), cur_figure->getPosition().y() + 1); break; } case Qt::Key_Left: { newFig.setPosition(cur_figure->getPosition().x() - 1, cur_figure->getPosition().y()); break; } case Qt::Key_Right: { newFig.setPosition(cur_figure->getPosition().x() + 1, cur_figure->getPosition().y()); break; } default: { QMainWindow::keyPressEvent(event); } } if (m_cup.hasPlace(newFig)) { delete cur_figure; cur_figure = new Figure(newFig); } draw(); }
void TetrisCup::putFigure(const Figure &_figure) { m_clearedLines = 0; Matrix figMatrix = _figure.getContent(); for (int i = 0; i < figMatrix.getWidth(); i++) for (int j = 0; j < figMatrix.getHeight(); j++) if (figMatrix.getValue(i, j) > 0) m_content.setValue(_figure.getX() + i, _figure.getY() + j, figMatrix.getValue(i, j)); int i = 0; while (i < m_content.getHeight()) { bool filled = true; for (int j = 0; j < m_content.getWidth(); j++) if (m_content.getValue(j, i) == 0) { filled = false; break; } if (filled) { m_content.delRow(i); m_clearedLines++; } else i++; } }
void mouseMotion(int x, int y) { Point *p = new Point(x, H2-y); if ((figType == POINTER) && sel) { Figure *f = figureSet[selected]; if (cpsel){ // the user is trying to move a control point (modify) f->setPoint(cp - figureSet.size(), p); } else { // the user want to move the figure as a block (move) // common points int xoffset = x - ox; int yoffset = oy - y; // openGl invert y coordinate int *pt1 = f->getPoint(1)->getCoords(); int *pt2 = f->getPoint(2)->getCoords(); // move coordinates basing on offsets Point *p1 = new Point(pt1[0] + xoffset, pt1[1] + yoffset); f->setPoint(1, p1); Point *p2 = new Point(pt2[0] + xoffset, pt2[1] + yoffset); f->setPoint(2, p2); if (Triangle *t = dynamic_cast<Triangle*>(f)) { int *pt3 = t->getPoint(3)->getCoords(); Point *p3 = new Point(pt3[0] + xoffset, pt3[1] + yoffset); t->setPoint(3, p3); } else if (Quad *q = dynamic_cast<Quad*>(f)) { int *pt3 = q->getPoint(3)->getCoords(); int *pt4 = q->getPoint(4)->getCoords(); Point *p3 = new Point(pt3[0] + xoffset, pt3[1] + yoffset); q->setPoint(3, p3); Point *p4 = new Point(pt4[0] + xoffset, pt4[1] + yoffset); q->setPoint(4, p4); } } ox = x; // refresh coordinates oy = y; } // show the figure while creating switch(figType) { case LINE: { Line *l = (Line*) figureSet.back(); l->setPoint(2, p); break; } case TRIANGLE: { Triangle *t = (Triangle*) figureSet.back(); t->setTriangle(p); break; } case QUAD: { Quad *q = (Quad*) figureSet.back(); q->setQuad(p); break; } } glutPostRedisplay(); }
int Truck::Is_out() { FigureLink *p=content.GetNext(); Figure *cast; cast=p->Get(); if(cast->Is_out()==1) return 1; return 0; }
int main () { Figure r {4, 7}; std::cout << "Rectangle Area: " << r.area() << std::endl; Figure c {1}; std::cout << "Circle Area: " << c.area() << std::endl; return 0; }
void testAccess() { Figure obj; switch (obj.type()) { // expected-warning {{enumeration values 'SQUARE', 'TRIANGLE', and 'CIRCLE' not handled in switch}} case SQUARE: // expected-error-re {{use of undeclared identifier 'SQUARE'{{$}}}} case TRIANGLE: // expected-error-re {{use of undeclared identifier 'TRIANGLE'{{$}}}} case CIRCE: // expected-error-re {{use of undeclared identifier 'CIRCE'{{$}}}} break; } }
// delete all plots on a specified figure void clear(const string figure_name) { Figure *fig = pm.FindFigure(figure_name); if (fig != NULL) { fig->Clear(); } }
bool Board::CheckMove (const Figure & figure, int newX, int newY) { for (int i=0; i<4; ++i) { int x = newX + figure.X(i); int y = newY + figure.Y(i); if (x < 0 || x >= BoardHeight || y < 0 || y >= BoardWidth || board[x][y] != 0) return false; } return true; }
void Board::move( int fromX, int fromY, int toX, int toY ) { Figure * from = m_board[ fromY ][ fromX ]; if( from ) { m_board[ fromY ][ fromX ] = 0; m_board[ toY ][ toX ] = from; from->setX( toX ); from->setY( toY ); const QModelIndex fromIndex = index( fromY * 8 + fromX, 0 ); const QModelIndex toIndex = index( toY * 8 + toX, 0 ); emit dataChanged( fromIndex, fromIndex ); emit dataChanged( toIndex, toIndex ); // Take on the pass. if( from->type() == Figure::PawnFigure ) { Pawn * p = static_cast< Pawn* > ( from ); switch( p->color() ) { case Figure::White : toY += 1; break; case Figure::Black : toY -= 1; break; default : break; } if( m_board[ toY ][ toX ] && m_board[ toY ][ toX ]->type() == Figure::PawnFigure ) { Pawn * killed = static_cast< Pawn* > ( m_board[ toY ][ toX ] ); if( killed && killed->isPass() ) { m_board[ toY ][ toX ] = nullptr; const QModelIndex toIndex = index( toY * 8 + toX, 0 ); emit dataChanged( toIndex, toIndex ); } } } } }
// update function void Update(int value){ if(loseFlag==FALSE){ newFigureFlag=tetrisFigure.Translate(0, -1); if(!newFigureFlag){ tetrisGame.Update(tetrisFigure); tetrisFigure.New(rand()%NUM_FIGURE); } } glutPostRedisplay(); // Refresh Display glutTimerFunc(100, Update, 0); }
Figure* WFObjLoader::loadGCBFile(const char *fileName) { std::vector<char>* data = GCLoadAsset(fileName); Figure *out = WFObjLoader::loadGCBData(data); if (out) { out->name = fileName; out->build(); } delete data; return out; }
void List::moveAllSelected(int x, int y) { Node *p = head; while (p != NULL) { Figure *f = p->getData(); if (f->getSelected()) f->move(x, y); p = p->getNext(); } }
void FigureLink::show() { Figure *current; current=head; while(current) { current->Draw(); current=current->next; } }
void FigureLink::hide() { Figure *current; current=head; while(current) { current->Hide(); current=current->next; } }
void FigureLink::move() { Figure *current; current=head; while(current) { current->Move(); current=current->next; } }
void MenFigure::setup(std::vector<float>radiusParams) { for (unsigned int i = 0; i < radiusParams.size() ; i++) { Figure fig; fig.setup(radiusParams[i]); this->bodyParts.push_back( fig ); } this->partNum = radiusParams.size(); }
void Game::drawFigures(){ //increase time if (++time > cycle) time = 0; bool noCollision = true; for (int i = 0; i < figures.size(); ++i){ Figure * fig = figures[i]; fig->draw(); } }
void Well::addFigure(const Figure &f) { for(int y=0; y<4; ++y) for(int x=0; x<4; ++x) { int wx = x + f.x(), wy = y + f.y(); if(wx >= 0 && wx < width_ && wy >= 0 && wy < height_ ) map_[wy][wx] = map_[wy][wx] | f.map(x, y); } }
/* Dibuja una lista de figuras en una imagen. Parámetros: image la imagen donde dibuja. list la lista de figuras que dibuja en la imagen. */ void drawList(IplImage* image, std::list<Figure> &list) { std::list<Figure>::iterator pos; Figure temp = Figure(0,0,0); pos = list.begin(); while(pos != list.end()) { temp = *pos; temp.draw(image); pos++; } }
void Vehicle::erase() { FigureLink *p=content.GetNext(); Figure *cast; while(/*p->GetNext()!=NULL*/1) { cast=p->Get(); cast->erase(); p=p->GetNext(); if(p==0) return; } }
void Vehicle::move(int x,int y) { FigureLink *p=content.GetNext(); Figure *cast; while(/*p->GetNext()!=NULL*/1) { cast=p->Get(); cast->move(x,y); p=p->GetNext(); if(p==0) return; } }
void Truck::draw() { FigureLink *p=content.GetNext(); Figure *cast; while(/*p->GetNext()!=NULL*/1) { cast=p->Get(); cast->draw(); p=p->GetNext(); if(p==0) return; } }