本文整理汇总了C++中Square类的典型用法代码示例。如果您正苦于以下问题:C++ Square类的具体用法?C++ Square怎么用?C++ Square使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Square类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
// ----------------------------------------------------------------------------
int main(int argc, char** argv) {
DBG("[Lesson 5]: C Style 5");
Square square;
SquareCtor(&square, 10, 10);
square.print();
WRN("Square area: %.2f", square.area(&square));
/**
* What we want to happen is that the print() activation of the Shape pointer
* will activate the print() function of the Square object which its pointing to.
*/
Shape* ptr = reinterpret_cast<Shape*>(&square);
ptr->print(); // expected polymorphism
DBG("[Lesson 5]: C Style 5 [END]");
return 0;
}
示例2: while
//Referenced brinkmwj's update method to create mine, modified it to work with mouse input
void HW_02App::update()
{
Square* cur = mSquare_;
Vec2f center = kUnitX*width/2.0 + kUnitY*height/2.0;
if(mIsPressed){
cur->update(mMouseLoc, width/4.0);
}
if(cur != NULL && mIsPressed){
do {
cur->update(mMouseLoc, width/4.0);
cur = cur->next_;
} while (cur != mSquare_);
}
frame_number_++;
}
示例3: main
int main() {
Square square;
square.draw();
square.virtual_draw();
std::cout << std::endl;
Shape* triangle = new Triangle();
triangle->draw();
triangle->virtual_draw();
std::cout << std::endl;
WeirdShape weird;
weird.virtual_draw();
system("PAUSE");
return EXIT_SUCCESS;
}
示例4: main
int main()
{
Rectangle r (5,3);
cout << "Width is " ;
cout << r.get_width() << endl;
cout << "Length is ";
cout << r.get_length() << endl;
cout << "Area is ";
cout << r.get_area() << endl;
return 1;
Square s (5);
cout << "Square Length is ";
cout << s.get_length() << endl;
cout << "Square Area is ";
cout << s.get_area() << endl;
return 1;
}
示例5: printGrid
void Grid::printGrid()
{
for(int yPos = 0; yPos < height ; yPos++)
{
for(int xPos = 0; xPos < width ; xPos++)
{
Square* testSquare = grid[xPos + (yPos * width)];
if(testSquare->getCurrentState())
{
std::cout << "█" ;
}
else
{
std::cout << "•";
}
}
std::cout << std::endl;
}
}
示例6: rollDice
/// Calls rollDice() and calculates the destination square
/// Passes these too executeMove().
bool SnakesAndLadders::getMove() {
// Setup a pointer to the current player and the square they are on.
SLPlayer* player = dynamic_cast<SLPlayer*>(players[currentPlayer]);
Coord current = dynamic_cast<SrcPiece&>(player->getPiece(0)).getSource();
Square* srcSquare = &grid[current.y][current.x];
// Prompt the user to roll.
cout << "Press enter to roll a dice and make your move\n";
cin.get();
int roll = rollDice();
int total=roll;
// Unsuspend the player if they roll a 6.
if(roll == 6) {
player->suspended = false;
}
// Roll again if a 6 is rolled.
while((roll % 6 == 0) && (total != 6*3)) {
cout << "You rolled a " << roll << " go again\n";
cin.get();
roll = rollDice();
total += roll;
}
if(roll != 6) cout << "You rolled a " << roll << "\n";
if(total == 6*3) {
player->suspended = true;
executeMove(srcSquare, squareRefs[0]);
cout << "You rolled 3 sucessive 6s.\n";
} else if(!player->suspended) {
total = total + srcSquare->getIdentifier()-1;
total = total > 100 ? 100 - (total % 100) : total;
this->executeMove(srcSquare, squareRefs[total-1]);
} else {
cout << "You are suspended until you roll a 6\n";
}
// Switch Player.
currentPlayer=(currentPlayer+1)%(amountOfPlayers);
return true;
}
示例7: initializeBoard
void ChessBoard::initializeBoard() {
for( int i = 0; i < BOARD_WIDTH_HEIGHT; ++i ) {
for( int j = 0; j < BOARD_WIDTH_HEIGHT; ++j ) {
PieceColor squareColor;
if( (i+j) % 2 == 0 ) squareColor = WHITE;
else squareColor = BLACK;
Square* sq = &board[i][j];
sq->color = squareColor;
if( i < 2 || i > 5 ) {
PieceColor color;
if( i < 2 ) color = BLACK;
else color = WHITE;
PieceType type;
if( i == 0 || i == 7 ) type = getPieceType( j );
else type = PAWN;
Piece* piece = new Piece( type, color, true );
piece->x = j;
piece->y = i;
sq->setPiece( piece );
if( i < 2 ) blackPieces.push_back( piece );
else whitePieces.push_back( piece );
} else {
sq->setPiece(NULL);
}
sq->x = j;
sq->y = i;
}
}
}
示例8: main
int main(int argc, char* argv[])
{
double l,l2;
cout << "Length=";
cin >> l;
Square p1(l);
Cube p2(l);
Square *pp;
pp = &p1;
pp->print();
pp->Space(l);
pp = &p2;
pp->print();
pp->Space(l);
Cube p3(1);
p2 = p3;
p2.print();
system("pause");
return 0;
}
示例9: printf
void Board::print_board()
{
printf("\nPlayer to move: %s\n", current_player == Square::BLACK ? "BLACK" : "WHITE");
const char* hyphens = std::string(SQUARE_DIMENSION * 6 - 1, '-').c_str();
printf(" %s\n", hyphens);
for (int y = SQUARE_DIMENSION - 1; y >= 0; --y)
{
for (int x = 0; x < SQUARE_DIMENSION; ++x)
{
Square* sq = (*board)[x][y];
printf("| %s%-2d ", sq->get_occupant() == Square::BLACK ? "B" : (sq->get_occupant() == Square::WHITE ? "W" : "E"), sq->get_num_stones());
}
printf("|\n");
}
printf(" %s\n", hyphens);
}
示例10: Color
void HW_02App::draw()
{
gl::clear( Color( 0, 0, 0 ), true );
if((frame_number_ <=1) || mDrawImage){
mDrawImage = true;
gl::clear( Color( 0, 0, 0 ), true );
gl::drawString("Welcome to The Royal Society for Putting Things on Top of Other Things", Vec2f (20,200), Color(0.0f,1.0f,0.0f), *f);
gl::drawString("Press '?' to continue...", Vec2f (20,230), Color(0.0f,1.0f,0.0f), *f);
}
else{
Square* cur = mSquare_;
if(cur != NULL){
do {
cur->draw();
cur = cur->next_;
} while (cur != mSquare_);
}
}
}
示例11: getSquareByXY
void Grid::updateLoop()
{
for(int yPos = 0; yPos < height ; yPos++)
{
for(int xPos = 0; xPos < width ; xPos++)
{
Square* testSquare = getSquareByXY(xPos, yPos);
int indexNum = testSquare->getIndexNum();
int neighbours = findNeighbours(indexNum);
bool alive = testSquare->getCurrentState();
if (alive && (neighbours < 2 || neighbours > 3))
{
testSquare->setShouldFlip();
}
else if (!alive && neighbours == 3)
{
testSquare->setShouldFlip();
}
}
}
}
示例12: willCollid
bool Shot::willCollid(Square square, int x, int y) {
if ((box.x + x == square.getx()) or ((box.x + x > square.getx()) and (box.x + x < (square.getx() + square.getw())))
or ((square.getx() > box.x + x) and (square.getx() < (box.x + x + box.w))))
if ((box.y + y <= square.gety()) and (box.y + y + box.h >= square.gety()))
return true;
return false;
};
示例13: undo
bool AttackCommand::undo(Chessboard &board)
{
Square *to = board.squareAt(fromSquare());
Square *from = board.squareAt(toSquare());
if (!to->isEmpty())
{
qCritical() << "Runtime error: square is not empty";
return false;
}
if (from->isEmpty())
{
qCritical() << "Runtime error: square is empty";
return false;
}
Piece* movedePiece = from->piece();
undoMarkingAsMoved(*movedePiece);
board.removePiece(movedePiece);
board.putPiece(to, movedePiece);
board.putPiece(from, m_killedPiece);
m_killedPiece = nullptr;
qDebug() << "Attack (Undo): " << Chess::toString(movedePiece->type()) << " " << from->toStr() << ":" << to->toStr();
return true;
}
示例14: main
int main(){
Rectangle R;
R.set_Length(5);
R.set_Width(6);
cout<<"Rectangle :";
R.get_Length();
cout<<"Rectangle :";
R.get_Width();
R.cal_Area();
Square S;
S.set_Length(8);
cout<<"Square :";
S.get_Length();
S.cal_Area();
Parellelogram P;
P.set_Length(4);
cout<<"Parellolgram :";
P.get_Length();
P.set_Height(3);
cout<<"Parellolgram :";
P.get_Height();
P.cal_Area();
Trapezoid T;
T.set_Base1(3);
cout<<"Trapezoid :";
T.get_Base1();
T.set_Base2(4);
cout<<"Trapezoid :";
T.get_Base2();
T.set_Height(2);
cout<<"Trapezoid :";
T.get_Height();
T.cal_Area();
return 0;
}
示例15: getBoundingRectangle
bool Square::intersects(Square square, vector<Coordinate> & pos){
vector<double> boundingRectanglePoints;
Square boundingRectangle = getBoundingRectangle(square, boundingRectanglePoints);
if ((boundingRectangle.getWidth() < getWidth() + square.getWidth())
&& (boundingRectangle.getHeight() < getHeight() + square.getHeight())){
pos.push_back(Coordinate(max(LB.getX(), square.getLB().getX()), max(LB.getY(), square.getLB().getY())));
pos.push_back(Coordinate(min(RA.getX(), square.getRA().getX()), min(RA.getY(), square.getRA().getY())));
//cout << "height bounding rectangle: " << abs(pos[1].getY() - pos[0].getY()) << endl;
//cout << "height first rectangle: " << getHeight() << endl;
if (abs(pos[1].getY() - pos[0].getY()) >= getHeight() || abs(pos[1].getY() - pos[0].getY()) >= square.getHeight()){
pos.push_back(Coordinate(pos[0].getX(), pos[0].getY() + boundingRectangle.getHeight()));
pos.push_back(Coordinate(pos[1].getX(), pos[1].getY() - boundingRectangle.getHeight()));
}
return true;
}
else {
return false;
}
}