void GraphicsBoard::movePiece(const Chess::Square& source, const Chess::Square& target) { GraphicsPiece* piece = pieceAt(source); Q_ASSERT(piece != nullptr); m_squares[squareIndex(source)] = nullptr; setSquare(target, piece); }
void CrazyhouseBoard::restorePieces(Piece piece, const QVarLengthArray<int>& squares) { if (!piece.isValid() || squares.isEmpty()) return; Piece prom(piece.side(), promotedPieceType(piece.type())); for (int i = 0; i < squares.size(); i++) setSquare(squares[i], prom); }
GameItem::GameItem(int x,int y,Game* game){ myPolygon << QPointF(-10, 0) << QPointF(0, 10) << QPointF(10, 0) << QPointF(0, -10) << QPointF(-10, 0); this->setPolygon(myPolygon); setSquare(x,y); this->game = game; setupAnimation(); }
GameItem::GameItem(Game* game) { myPolygon << QPointF(-10, 0) << QPointF(0, 10) << QPointF(10, 0) << QPointF(0, -10) << QPointF(-10, 0); this->setPolygon(myPolygon); setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsSelectable, true); setSquare(0,0); this->game = game; setupAnimation(); }
void GameItem::animationDone() { animation->clear(); switch(dir){ case Up: setSquare(square.x(),square.y() - 1); break; case Down: setSquare(square.x(),square.y() + 1); break; case Left: setSquare(square.x() - 1,square.y()); break; case Right: setSquare(square.x() + 1,square.y()); break; } if(move(dir)){ setAnimationStep(square,QPoint(square.x(),square.y()),this->dir); } }
void Map::clear() { for (unsigned short i = 0; i < 12; ++i) for (unsigned short j = 0; j < 10; ++j) m_board.horizontalWalls[i][j] = false; for (unsigned short i = 0; i < 13; ++i) for (unsigned short j = 0; j < 9; ++j) m_board.verticalWalls[i][j] = false; for (unsigned short i = 0; i < 12; ++i) for (unsigned short j = 0; j < 9; ++j) setSquare(i, j, SquareType::Void); m_entities.clear(); m_name.erase(); }
void CrazyhouseBoard::normalizePieces(Piece piece, QVarLengthArray<int>& squares) { if (!piece.isValid()) return; Piece prom(piece.side(), promotedPieceType(piece.type())); Piece base(piece.side(), normalPieceType(piece.type())); if (base == prom) return; const int size = arraySize(); for (int i = 0; i < size; i++) { if (pieceAt(i) == prom) { squares.append(i); setSquare(i, base); } } }
void setWaveform(int numSamples, int mode, uint8 *currentWaveform) { switch (mode) { case SQUARE: setSquare(numSamples, currentWaveform); break; case SINE: setSine(numSamples, currentWaveform); break; case TRIANGLE: setTriangle(numSamples, currentWaveform); break; case SAWTOOTH: setSawtooth(numSamples, currentWaveform); break; case DC: setDC(numSamples, currentWaveform); break; } }
int main(int argc, char *argv[]) { /* printf("Argument count: %d\n", argc); for (int i = 0; i < argc; i++) { printf("Argument vector values:%s at %p memory\n", argv[i], argv[i]); for (char *j=argv[i]; *j!='\0'; j++) { printf("Another way to print argument vector values: " "%c at %p memory\n", *j, j); } } */ struct Line line1; double m,c; m = -1.00; c = 6.00; setLine(&line1,m,c); printf("Line1 has slope: %f and y-intercept: %f\n",line1.slope,line1.yintercept); struct Line line2; m = 1.00; c = 6.00; setLine(&line2,m,c); printf("Line2 has slope: %f and y-intercept: %f\n",line2.slope,line2.yintercept); struct Point p1; double xval,yval; xval = 2; yval = 1; setPoint(&p1,xval,yval); printf("Point1 has x: %f and y: %f\n",p1.x,p1.y); struct Point p2; xval = 2; yval = 1; setPoint(&p2,xval,yval); printf("Point2 has x: %f and y: %f\n",p2.x,p2.y); m = getSlope(p1,p2); printf("Slope of Line joining p1 and p2: %f\n",m); p2 = getIntersectPoint(line1,line2); printf("Intersection Point of Line1 and Line2 has x: %f and y: %f\n",p2.x,p2.y); struct Square sq1; double xl,xr,yt,yb; xl = 2.00; xr = 4.00; yt = 4.00; yb = 2.00; setSquare(&sq1, xl, xr, yt, yb); printf("Sqaure1 has xleft: %f, xright: %f and ytop: %f, ybottom: %f\n",sq1.xleft,sq1.xright,sq1.ytop,sq1.ybottom); struct Point sqCentre1; sqCentre1 = getSquareCentre(sq1); printf("Centre Point of Square1 has x: %f and y: %f\n",sqCentre1.x,sqCentre1.y); struct Square sq2; xl = 4.00; xr = 6.00; yt = 6.00; yb = 4.00; setSquare(&sq2, xl, xr, yt, yb); printf("Sqaure2 has xleft: %f, xright: %f and ytop: %f, ybottom: %f\n",sq2.xleft,sq2.xright,sq2.ytop,sq2.ybottom); struct Point sqCentre2; sqCentre2 = getSquareCentre(sq2); printf("Centre Point of Square2 has x: %f and y: %f\n",sqCentre2.x,sqCentre2.y); m = getSlope(sqCentre1,sqCentre2); printf("Slope of Line joining Square 1 Centre and Square 2 Centre: %f\n",m); return 0; }