freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

基于qt的打磚塊游戲的設計與實現(xiàn)論文-資料下載頁

2024-11-08 05:37本頁面

【導讀】Creator軟件中實現(xiàn)構(gòu)建和運行。游戲包含三種模式,初級,中級,高級。小球的彈射,把所有的磚塊打完勝利。本論文首先指出了打磚塊游戲、Linux桌面環(huán)境、QT開發(fā)環(huán)境的發(fā)展現(xiàn)狀,桌面環(huán)境和QT的發(fā)展。件開發(fā)的邏輯分析,程序設計,軟件實現(xiàn)和軟件測試幾個步驟。

  

【正文】 以輸出一些東西。 QTime 是一個定時器類。 include cstdlib include ctime Game::Game( QWidget *parent ) :QWidget( parent ){ 25 isWin = false。 isFailure = false。 frameWidth = 800。 frameHeight = 500。 score = 0。 rows = 5。 columns = 10。 createBricks()。 createPaddle()。 createBall()。 timer = new QTimer( this )。 timersetInterval( 10 )。 connect( timer, SIGNAL( timeout() ), this, SLOT( moveBall() ) )。 changeColor()。 } bool 類型變量 isWin 和 isFailure 用來記錄程序程序結(jié)束時的勝 利或失敗的情況。 frameWidth 和 frameHeight 用來保存每一時刻的窗格的大小 ,注意 ,初始化值寬度 800 和高度 500 并不代表窗格的實際大小 ,這里只是提供了一個理想的值 ,因為小球、劃漿、磚塊的大小的設定都需要窗格的大小來設定。 構(gòu)造函數(shù)中調(diào)用 createBrick()、 createPaddle()、 createBall() 函數(shù) ,用 來對磚塊、劃漿、和小球進行初始化。之后 ,設定定時器 ,每個 10 毫秒將調(diào)用一次moveBall 函數(shù)。 最后 ,調(diào)用 changeColor 函數(shù)用來改變小球、磚塊、劃漿的顏色 ,函數(shù) randomColor 將返回一個隨機顏色。 void Game::changeColor(){ srand( (int) time( NULL ) )。 foreach( Brick *brick, bricks ) bricksetColor( randomColor() )。 ballsetColor( randomColor() )。 paddlesetColor( randomColor() )。 26 } QColor Game::randomColor(){ return QColor( randomInt( 255 ), randomInt( 255 ), randomInt( 255 ) )。 } int Game::randomInt( int high ){ double d = (double)rand() / ( (double)RAND_MAX + 1 )。 int k = (int) (d * ( high + 1 ))。 return k。 } 調(diào)用 randomInt( 255 ) 語句 ,將得到一個 0 至 255 的隨機顏色 ,因此 , randomColor 函數(shù)能夠產(chǎn)生隨機顏色。 void Game::createBricks(){ qreal gap = 。 qreal brickWidth = frameWidth / ( columns + 1 ) gap。 qreal brickHeight = frameHeight / 4 / ( rows + 1 ) gap。 for( int r = 0。 r rows。 ++r ) for( int c = 0。 c columns。 ++c ){ Brick *brick = new Brick( brickWidth / 2 + c * ( brickWidth + gap ), brickHeight / 2 + r * ( brickHeight + gap ), brickWidth, brickHeight )。 ( brick )。 } } void Game::createPaddle(){ qreal paddleWidth = frameWidth / 10。 qreal paddleHeight = paddleWidth / 5。 paddle = new Paddle( frameWidth / 2 paddleWidth / 2 , frameHeight paddleHeight * 2, paddleWidth, paddleHeight )。 27 } void Game::createBall(){ qreal ballSide = paddlegetShape().height()。 ball = new Ball( frameWidth / 2 ballSide / 2, paddlegetShape().top() ballSide, ballSide )。 } createBricks 中的變量 gap 表示磚塊之間的距離 ,只有這個變量是不隨著窗口的縮放而改變的??梢宰⒁獾?,磚塊、劃漿、小球的大小都是根據(jù)預設的窗格的大小來確定的。其中 ,用 QList Brick * 類型的變量 bricks 來保存 Brick 對象 ,總共有 5 行 10 列即 50 個 Brick 對象。在 createBall 函數(shù)中 ,將小球的直徑設定 成劃漿的高度。 void Game::createBall(){ qreal ballSide = paddlegetShape().height()。 ball = new Ball( frameWidth / 2 ballSide / 2, paddlegetShape().top() ballSide, ballSide )。 } void Game::resizeEvent( QResizeEvent * ){ qreal scaleWidth = rect().width() / frameWidth。 qreal scaleHeight = rect().height() / frameHeight。 foreach( Brick *brick, bricks ){ QRectF shape = brickgetShape()。 bricksetShape( adjustShape( shape, scaleWidth, scaleHeight ) )。 } QRectF ballShape = ballgetShape()。 ballsetShape( adjustShape( ballShape, scaleWidth, scaleHeight ) )。 ballsetSpeed( ballgetSpeed() * scaleWidth )。 QRectF paddleShape = paddlegetShape()。 paddlesetShape( adjustShape( paddleShape, scaleWidth, scaleHeight ) )。 28 paddlesetStep( paddlegetStep() * scaleWidth )。 frameWidth = rect().width()。 frameHeight = rect().height()。 } QRectF Game::adjustShape( QRectF shape, qreal scaleWidth, qreal scaleHeight ){ QRectF newShape( () * scaleWidth, () * scaleHeight, () * scaleWidth, () * scaleHeight )。 return newShape。 } 當窗格大小發(fā)生變化時 ,程序?qū){(diào)用 resizeEvent 函數(shù) ,這時 rect().width()和 rect().height() 將會分別返回當前窗格的寬度和高度 ,因此 ,scaleWidth 變量表示寬度的縮放因子 ,而 scaleHeight 表示高度的縮放因子 ,adjustShape 函數(shù)能根據(jù)這些縮 放因子對其接受的參數(shù) shape 進行相應的縮放 ,并返回一個經(jīng)縮放之后的 新矩形。 當窗口發(fā)生變化時 ,也應相應地增大或縮小小球的移動速度和劃漿的水平移動距離 ,由于劃漿的移動步長窗格水平寬度相關(guān) ,小球的移動速度又與劃漿的移動步長相關(guān) ,因此 ,這里使用 scaleWidth 作為縮放因子。 最后 ,需要將當前窗格的高度和寬度進行保存。 Game::~Game(){ delete ball。 delete paddle。 while( !() ) delete ()。 } 析構(gòu)函數(shù)用來刪除變量 ,QList 的 takeFirst 函數(shù)能將第一個對象指針從進行QList 中移除并返回這個指針 ,因此 ,可以通過 delete 一個 Brick 指針來刪除一個 Brick 對象。 void Game::paintEvent( QPaintEvent * ){ QPainter painter( this )。 if( isWin || isFailure ){ 29 QFont font( Courier, 20, QFont::DemiBold )。 QFontMetrics fm( font )。 ( font )。 ( QPoint( width() / 2, height() / 2 ) )。 if( isWin ){ int textWidth = ( You are winner! )。 ( Qt::blue )。 ( textWidth / 2, 0, tr( You are the winner! ) )。 }else{ int textWidth = ( You are loser! )。 ( Qt::red )。 ( textWidth / 2, 0, tr( You are the loser! ) )。 } timerstop()。 emit finished()。 return。 } ( Qt::NoPen )。 ( ballgetColor() )。 ( ballgetShape() )。 ( paddlegetShape(), paddlegetColor() )。 foreach( Brick *brick, bricks ) ( brickgetShape(), brickgetColor() )。 } paintEvent 函數(shù)由程序自動調(diào)用 ,用來對窗格進行繪制。每次繪制之前 ,都需要對 isWin 和 isFailure 變量進行確認 ,當二者之一為 true 時 ,說明程序運行結(jié)束 ,這時 ,將在窗格中繪制相應的文本 ,再將定時器暫停 ,發(fā)送一 個 finished 信號 ,并調(diào)用 return 語句進行返回。當游戲在進行時 ,則需要對窗格進行繪制 ,這時 ,調(diào)用 ( Qt::NoPen )。 語句能設置在繪制時使用畫刷而不使用畫筆。 void Game::movePaddleLeft(){ 30 if( paddlegetLeft() rect().left() ){ paddlemoveLeft()。 update()。 } } void Game::movePaddleRight(){ if( paddlegetRight() rect().right() ){ paddlemoveRight()。 update()。 } } void Game::startGame(){ timerstart()。 } void Game::stopGame(){ timerstop()。 } 以上 4 個槽函數(shù)為 Game 提供了外部接口 ,用來為其它 widget 提供控制劃漿移動、開始游戲、停止游戲的接口。例如 ,當 Game 對象作為 QMainWindow 的中央部件時 ,通過連接相應的信號和槽 ,就能通過鍵盤
點擊復制文檔內(nèi)容
高考資料相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1