定 價(jià):¥49.00
作 者: | 何青 |
出版社: | 清華大學(xué)出版社 |
叢編項(xiàng): | |
標(biāo) 簽: | 暫缺 |
ISBN: | 9787302549772 | 出版時(shí)間: | 2020-06-01 | 包裝: | |
開本: | 16開 | 頁數(shù): | 238 | 字?jǐn)?shù): |
目錄
第 1章 神奇的游戲循環(huán):彈跳小球 ··· 1
1.1 準(zhǔn)備工作 ································· 1
1.1.1 選擇合適的開發(fā)工具 ············· 1
1.1.2 設(shè)置開發(fā)環(huán)境 ······················ 2
1.2 從何處開始 ······························ 3
1.2.1 創(chuàng)建程序窗口 ······················· 3
1.2.2 改變窗口大小和顏色 ·············· 5
1.2.3 顯示圖像 ····························· 7
1.3 建立游戲世界 ··························· 9
1.3.1 創(chuàng)建游戲場景 ······················· 9
1.3.2 創(chuàng)建游戲角色 ······················10
1.4 移動(dòng)小球 ································11
1.4.1 改變小球坐標(biāo)·······································11
1.4.2 游戲循環(huán)···················································································11
1.4.3 朝其他方向移動(dòng) ···················13
1.4.4 移動(dòng)得快一些 ······················14
1.5 實(shí)現(xiàn)小球反彈 ··························14
1.5.1 檢測小球的位置 ···················14
1.5.2 將小球反彈回來 ···················15
1.6 加入更多的小球 ·······················17
1.6.1 添加兩個(gè)小球 ······················18
1.6.2 使用列表 ····························19
1.7 回顧與總結(jié) ·····························21
第 2章用鼠標(biāo)控制游戲:拼圖 ········24 2.1
添加圖片塊 ·····························24
2.1.1 準(zhǔn)備圖片資源 ······················24
2.1.2 創(chuàng)建游戲場景 ······················25
2.1.3 用列表管理圖片塊 ················26
2.2 打亂圖片塊 ·····························27
2.2.1 使用隨機(jī)函數(shù) ······················27
2.2.2 將圖片塊顯示出來 ················28
2.3 移動(dòng)圖片塊 ·····························30
2.3.1 處理鼠標(biāo)單擊事件 ················30
2.3.2 選取圖片塊 ·························31
2.3.3 判斷圖片塊能否移動(dòng) ·············31
2.3.4 采用模塊化編程方法 ·············32
2.3.5 改變圖片塊的位置 ················33
2.3.6 減少程序的縮進(jìn)層級 ·············33
2.4 實(shí)現(xiàn)游戲結(jié)束 ··························34
2.4.1 檢查拼圖是否完成 ················35
2.4.2 顯示最后一張圖片 ················36
2.4.3 播放聲音效果 ······················37
2.4.4 顯示文字信息 ······················38
2.5 回顧與總結(jié) ·····························39
第 3章遞歸函數(shù)的威力:掃雷 ········42
3.1 創(chuàng)建方塊陣列 ··························42
3.1.1 準(zhǔn)備圖片資源 ······················42
3.1.2 創(chuàng)建游戲場景 ······················43
3.1.3 生成方塊陣列 ······················43
3.1.4 埋設(shè)地雷 ····························45
3.2 給方塊插上旗子 ·······················46
3.2.1 使用鼠標(biāo)右鍵來操作 ·············46
3.2.2 定義函數(shù)執(zhí)行插旗操作 ··········47
3.3 打開方塊 ································49
3.3.1 完善鼠標(biāo)事件處理 ················49
3.3.2 獲取周圍的方格 ···················50
3.3.3 統(tǒng)計(jì)地雷數(shù)量 ······················52
3.3.4 遞歸調(diào)用打開方塊函數(shù) ··········52
3.4 判定游戲勝負(fù) ··························54
3.4.1 游戲失敗的處理 ···················54
3.4.2 游戲勝利的處理 ···················55
3.5 回顧與總結(jié) ·····························57
第 4章用鍵盤控制游戲:貪食蛇 ·····60
4.1 創(chuàng)建場景和角色 ·······················60
4.1.1 創(chuàng)建游戲場景 ······················60
4.1.2 創(chuàng)建貪食蛇 ·························61
4.2 移動(dòng)蛇頭 ································62
4.2.1 處理鍵盤按鍵事件 ················62
4.2.2 讓蛇頭持續(xù)移動(dòng) ···················63
4.2.3 另一種鍵盤控制方式 ·············64
4.2.4 延緩貪食蛇的移動(dòng) ················65
4.2.5 旋轉(zhuǎn)蛇頭的圖像 ···················66
4.2.6 使用字典類型 ······················68
4.3 添加食物 ································69
4.3.1 讓食物隨機(jī)出現(xiàn) ···················69
4.3.2 讓貪食蛇“吃”食物 ·············70
4.3.3 增長貪食蛇的身體 ················71
4.4 實(shí)現(xiàn)游戲結(jié)束 ··························74
4.4.1 判斷貪食蛇碰到窗口邊界 ·······74
4.4.2 判斷蛇頭碰到自己身體 ··········74
4.5 回顧與總結(jié) ·····························76
第 5章隨機(jī)數(shù)的妙用:打字 ············79
5.1 創(chuàng)建一個(gè)字母氣球 ····················79
5.1.1 創(chuàng)建游戲場景 ······················79
5.1.2 創(chuàng)建氣球角色 ······················80
5.2 添加多個(gè)氣球 ··························81
5.2.1 創(chuàng)建多個(gè)氣球角色 ················81
5.2.2 隨機(jī)生成氣球的坐標(biāo) ·············83
5.2.3 隨機(jī)生成氣球的速度 ·············85
5.2.4 隨機(jī)生成氣球的字母 ·············87
5.3 實(shí)現(xiàn)打字功能 ··························89
5.3.1 匹配字母的按鍵 ···················89
5.3.2 消除氣球 ····························89
5.3.3 修補(bǔ)游戲的 Bug ···················92
5.4 完善游戲規(guī)則 ··························94
5.4.1 添加游戲積分 ······················94
5.4.2 實(shí)現(xiàn)游戲倒計(jì)時(shí) ···················95
5.4.3 判定游戲結(jié)束 ······················97
5.5 回顧與總結(jié) ·····························98
第 6章碰撞檢測及處理:打磚塊 ··· 103
6.1 創(chuàng)建場景及角色 ····················· 103
6.1.1 創(chuàng)建游戲場景 ···················· 103
6.1.2 創(chuàng)建游戲角色 ···················· 104
6.2 讓角色動(dòng)起來 ························ 106
6.2.1 移動(dòng)擋板 ·························· 106
6.2.2 移動(dòng)小球 ·························· 107
6.3 處理角色間的碰撞 ·················· 110
6.3.1 碰撞檢測的原理 ················· 110
6.3.2 小球與擋板的碰撞 ·············· 112
6.3.3 小球與磚塊的碰撞 ·············· 114
6.4 完善游戲規(guī)則 ························ 116
6.4.1 設(shè)置游戲積分 ···················· 117
6.4.2 添加生命值 ······················· 117
6.4.3 實(shí)現(xiàn)游戲結(jié)束 ···················· 118
6.5 回顧與總結(jié) ··························· 120
第 7章讓游戲更加生動(dòng): Flappy Bird ······················ 124
7.1 創(chuàng)建游戲場景 ························ 124
7.1.1 設(shè)置背景圖像 ···················· 124
7.1.2 滾動(dòng)背景圖像 ···················· 126
7.2 添加障礙物 ··························· 128
7.2.1 設(shè)置地面 ·························· 128
7.2.2 設(shè)置水管 ·························· 129
7.3 添加小鳥 ······························ 131
7.3.1 創(chuàng)建小鳥角色 ···················· 131
7.3.2 模擬重力下的飛行 ·············· 132
7.3.3 播放飛行動(dòng)畫 ···················· 133
7.4 小鳥與障礙物的交互 ··············· 135
7.4.1 小鳥與地面碰撞 ················· 135
7.4.2 小鳥與水管碰撞 ················· 136
7.4.3 小鳥飛越水管 ···················· 137
7.5 設(shè)計(jì)圖形用戶界面 ·················· 139
7.5.1 顯示 GUI圖像 ··················· 139
7.5.2 單擊“開始”按鈕 ·············· 141
7.5.3 播放背景音樂 ···················· 141
7.6 回顧與總結(jié) ··························· 142
第 8章實(shí)現(xiàn)復(fù)雜的移動(dòng):飛機(jī)大戰(zhàn) ·························· 146
8.1 創(chuàng)建游戲場景 ························ 146
8.1.1 設(shè)置背景圖像 ···················· 146
8.1.2 滾動(dòng)背景圖像 ···················· 148
8.2 添加英雄戰(zhàn)機(jī) ························ 148
8.2.1 控制戰(zhàn)機(jī)移動(dòng) ···················· 148
8.2.2 播放戰(zhàn)機(jī)動(dòng)畫 ···················· 149
8.3 添加子彈 ······························ 151
8.3.1 實(shí)現(xiàn)子彈射擊 ···················· 151
8.3.2 設(shè)置增強(qiáng)道具 ···················· 152
8.3.3 使用三角函數(shù)計(jì)算坐標(biāo) ········ 154
8.4 添加敵機(jī) ······························ 157
8.4.1 設(shè)置緩動(dòng)效果 ···················· 157
8.4.2 敵機(jī)與子彈的交互 ·············· 160
8.4.3 敵機(jī)與戰(zhàn)機(jī)的交互 ·············· 161
8.5 完善游戲效果 ························ 165
8.5.1 設(shè)置 HUD ························ 165
8.5.2 播放背景音樂 ···················· 166
8.6 回顧與總結(jié) ··························· 167
第 9章添加多個(gè)游戲關(guān)卡:推箱子 ····························· 173
9.1 創(chuàng)建場景和角色 ····················· 173
9.1.1 設(shè)置游戲關(guān)卡 ···················· 173
9.1.2 加載游戲關(guān)卡 ···················· 175
9.2 實(shí)現(xiàn)角色的交互 ····················· 177
9.2.1 控制玩家角色的移動(dòng) ··········· 177
9.2.2 處理玩家角色的碰撞 ··········· 178
9.2.3 處理箱子角色的碰撞 ··········· 179
9.3 添加新的關(guān)卡 ························ 181
9.3.1 從文件載入關(guān)卡 ················· 181
9.3.2 切換關(guān)卡 ·························· 184
9.4 完善游戲功能 ························ 186
9.4.1 重置關(guān)卡 ·························· 186
9.4.2 判定游戲結(jié)束 ···················· 187
9.5 回顧與總結(jié) ··························· 188
第 10章人工智能的奧秘:五子棋 ···························· 193
10.1 創(chuàng)建棋盤和棋子 ···················· 193
10.1.1 繪制棋盤 ························ 193
10.1.2 設(shè)置棋子 ························ 195
10.2 執(zhí)行走棋操作 ······················· 195
10.2.1 使用鼠標(biāo)下棋 ·················· 195
10.2.2 交換下棋雙方 ·················· 197
10.3 完善游戲規(guī)則 ······················· 199
10.3.1 判定棋局勝負(fù) ·················· 199
10.3.2 添加悔棋功能 ·················· 202
10.4 實(shí)現(xiàn)人機(jī)對弈 ······················· 203
10.4.1 游戲中的人工智能 ············ 203
10.4.2 讓計(jì)算機(jī)學(xué)會(huì)下棋 ············ 204
10.5 回顧與總結(jié) ·························· 209
附錄 A 配置開發(fā)環(huán)境 ···················· 215
附錄 B Python基礎(chǔ)語法參考 ········· 220