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

正文內(nèi)容

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

2024-11-08 05:37本頁(yè)面

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

  

【正文】 以輸出一些東西。 QTime 是一個(gè)定時(shí)器類。 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 用來(lái)記錄程序程序結(jié)束時(shí)的勝 利或失敗的情況。 frameWidth 和 frameHeight 用來(lái)保存每一時(shí)刻的窗格的大小 ,注意 ,初始化值寬度 800 和高度 500 并不代表窗格的實(shí)際大小 ,這里只是提供了一個(gè)理想的值 ,因?yàn)樾∏?、劃漿、磚塊的大小的設(shè)定都需要窗格的大小來(lái)設(shè)定。 構(gòu)造函數(shù)中調(diào)用 createBrick()、 createPaddle()、 createBall() 函數(shù) ,用 來(lái)對(duì)磚塊、劃漿、和小球進(jìn)行初始化。之后 ,設(shè)定定時(shí)器 ,每個(gè) 10 毫秒將調(diào)用一次moveBall 函數(shù)。 最后 ,調(diào)用 changeColor 函數(shù)用來(lái)改變小球、磚塊、劃漿的顏色 ,函數(shù) randomColor 將返回一個(gè)隨機(jī)顏色。 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 ) 語(yǔ)句 ,將得到一個(gè) 0 至 255 的隨機(jī)顏色 ,因此 , randomColor 函數(shù)能夠產(chǎn)生隨機(jī)顏色。 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 表示磚塊之間的距離 ,只有這個(gè)變量是不隨著窗口的縮放而改變的??梢宰⒁獾?,磚塊、劃漿、小球的大小都是根據(jù)預(yù)設(shè)的窗格的大小來(lái)確定的。其中 ,用 QList Brick * 類型的變量 bricks 來(lái)保存 Brick 對(duì)象 ,總共有 5 行 10 列即 50 個(gè) Brick 對(duì)象。在 createBall 函數(shù)中 ,將小球的直徑設(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。 } 當(dāng)窗格大小發(fā)生變化時(shí) ,程序?qū)?huì)調(diào)用 resizeEvent 函數(shù) ,這時(shí) rect().width()和 rect().height() 將會(huì)分別返回當(dāng)前窗格的寬度和高度 ,因此 ,scaleWidth 變量表示寬度的縮放因子 ,而 scaleHeight 表示高度的縮放因子 ,adjustShape 函數(shù)能根據(jù)這些縮 放因子對(duì)其接受的參數(shù) shape 進(jìn)行相應(yīng)的縮放 ,并返回一個(gè)經(jīng)縮放之后的 新矩形。 當(dāng)窗口發(fā)生變化時(shí) ,也應(yīng)相應(yīng)地增大或縮小小球的移動(dòng)速度和劃漿的水平移動(dòng)距離 ,由于劃漿的移動(dòng)步長(zhǎng)窗格水平寬度相關(guān) ,小球的移動(dòng)速度又與劃漿的移動(dòng)步長(zhǎng)相關(guān) ,因此 ,這里使用 scaleWidth 作為縮放因子。 最后 ,需要將當(dāng)前窗格的高度和寬度進(jìn)行保存。 Game::~Game(){ delete ball。 delete paddle。 while( !() ) delete ()。 } 析構(gòu)函數(shù)用來(lái)刪除變量 ,QList 的 takeFirst 函數(shù)能將第一個(gè)對(duì)象指針從進(jìn)行QList 中移除并返回這個(gè)指針 ,因此 ,可以通過(guò) delete 一個(gè) Brick 指針來(lái)刪除一個(gè) Brick 對(duì)象。 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ù)由程序自動(dòng)調(diào)用 ,用來(lái)對(duì)窗格進(jìn)行繪制。每次繪制之前 ,都需要對(duì) isWin 和 isFailure 變量進(jìn)行確認(rèn) ,當(dāng)二者之一為 true 時(shí) ,說(shuō)明程序運(yùn)行結(jié)束 ,這時(shí) ,將在窗格中繪制相應(yīng)的文本 ,再將定時(shí)器暫停 ,發(fā)送一 個(gè) finished 信號(hào) ,并調(diào)用 return 語(yǔ)句進(jìn)行返回。當(dāng)游戲在進(jìn)行時(shí) ,則需要對(duì)窗格進(jìn)行繪制 ,這時(shí) ,調(diào)用 ( Qt::NoPen )。 語(yǔ)句能設(shè)置在繪制時(shí)使用畫刷而不使用畫筆。 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 個(gè)槽函數(shù)為 Game 提供了外部接口 ,用來(lái)為其它 widget 提供控制劃漿移動(dòng)、開(kāi)始游戲、停止游戲的接口。例如 ,當(dāng) Game 對(duì)象作為 QMainWindow 的中央部件時(shí) ,通過(guò)連接相應(yīng)的信號(hào)和槽 ,就能通過(guò)鍵盤
點(diǎn)擊復(fù)制文檔內(nèi)容
高考資料相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1