当前位置: 首页>>代码示例>>C++>>正文


C++ Square类代码示例

本文整理汇总了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;
}
开发者ID:duplyakin,项目名称:CppCourse,代码行数:19,代码来源:cstyle_5.cpp

示例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_++;
}
开发者ID:andyshear,项目名称:HW02,代码行数:19,代码来源:HW_02App.cpp

示例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;
}
开发者ID:cyrillrx,项目名称:cpp_experiments,代码行数:18,代码来源:main.cpp

示例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;
}
开发者ID:EvaMartinuzzi,项目名称:Comp-270,代码行数:18,代码来源:main.cpp

示例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;
    }
}
开发者ID:kgleeson,项目名称:GameOfLife,代码行数:19,代码来源:Grid.cpp

示例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;
}
开发者ID:BroganD1993,项目名称:CBG,代码行数:45,代码来源:SnakesAndLadders.cpp

示例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;


    }
  }
}
开发者ID:JoakimMisund,项目名称:Chess,代码行数:42,代码来源:ChessBoard.cpp

示例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;
}
开发者ID:BMSTU732,项目名称:Lab_3,代码行数:20,代码来源:Lab3(4).cpp

示例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);
}
开发者ID:ghanan94,项目名称:cooperative-adaptive-algorithms-assignment-2,代码行数:20,代码来源:board.cpp

示例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_);
		}
	}
}
开发者ID:andyshear,项目名称:HW02,代码行数:21,代码来源:HW_02App.cpp

示例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();
            }
        }
    }
}
开发者ID:kgleeson,项目名称:GameOfLife,代码行数:21,代码来源:Grid.cpp

示例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;
};
开发者ID:lucasvg,项目名称:TetrisBot,代码行数:7,代码来源:Shot.cpp

示例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;
}
开发者ID:yudjin87,项目名称:qml_chess,代码行数:29,代码来源:AttackCommand.cpp

示例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;
}
开发者ID:omkar0613,项目名称:C-Programming-Stuff,代码行数:39,代码来源:Quad.cpp

示例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;
	}
}
开发者ID:yvanvds,项目名称:tmi,代码行数:22,代码来源:Square.cpp


注:本文中的Square类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。