系統識別號 | U0002-2202201915005200 |
---|---|
DOI | 10.6846/TKU.2019.00670 |
論文名稱(中文) | 軟體重組案例: 2D 手機遊戲 |
論文名稱(英文) | Case Study of software Refactoring: A 2D Mobile game |
第三語言論文名稱 | |
校院名稱 | 淡江大學 |
系所名稱(中文) | 資訊管理學系碩士班 |
系所名稱(英文) | Department of Information Management |
外國學位學校名稱 | |
外國學位學院名稱 | |
外國學位研究所名稱 | |
學年度 | 107 |
學期 | 1 |
出版年 | 108 |
研究生(中文) | 王朋申 |
研究生(英文) | Peng-Shen Wang |
學號 | 603630624 |
學位類別 | 碩士 |
語言別 | 繁體中文 |
第二語言別 | |
口試日期 | 2019-01-05 |
論文頁數 | 62頁 |
口試委員 |
指導教授
-
廖賀田(htliaw@mail.tku.edu.tw)
委員 - 陳國棟(chen@csie.ncu.edu.tw) 委員 - 張昭憲(jschang@mail.im.tku.edu.tw) 委員 - 廖賀田(htliaw@mail.tku.edu.tw) |
關鍵字(中) |
手機遊戲 軟體工程 狀態機 重構。 |
關鍵字(英) |
Mobile Game Software Engineering State Machine Refactoring |
第三語言關鍵字 | |
學科別分類 | |
中文摘要 |
本論文對一個手機遊戲做重構(refactoring)的真實案例研究。在軟體工程學裡,重構(refactoring)通常是指在不改變程式碼的外部行為情況下而修改原始碼,重構既不修正錯誤,又不增加新的功能性。反而它是用於提高程式碼的可讀性或者改變程式碼內部結構與設計,並且移除死程式碼,使其在將來更容易被維護。這個程式本來是專題課程的成品,本系統結構完整,可以正常執行。但整個程式充滿語言上的不當使用,嚴重違反工程規則。原設計者無法解釋程式,也寫不出程式文件。遊戲是即時互動的系統,有許多的遊戲狀態需要切換。本論文引用Folwer等人在《Refactoring: Improving the Design of Existing Code》一書所提之重構方法對這個程式進行重構(refactoring)。並試圖建立系統文件。目前完成的了基本重組,並整理出遊戲狀態,然後使用繼承機制來重組遊戲的狀態機。藉著各個類別的責任歸屬,讓模糊的設計理念明確化,成為可維護的軟體。 |
英文摘要 |
This paper is a real case study of refactoring a mobile game. In software engineering, refactoring usually means modifying the source code without changing the external behavior of the code, and the reconstruction does not correct the error without adding new functionality. Instead, it is used to improve the readability of the code or to change the internal structure and design of the code, and to remove the dead code, making it easier to maintain in the future. This program was originally the finished product of the special course. The system is structurally complete and can be executed normally. However, the entire program is full of illogical misuse, which is a serious violation of engineering rules. The original designer could not interpret the program and could not write the program file. The game is an instant interactive system with many game states that need to be switched. This paper uses the refactoring method proposed by Folwer et al. in "Refactoring: Improving the Design of Existing Code" to refactor the program. And tried to create a system file. The basic reorganization is now completed, and the game state is sorted out, and then the inheritance mechanism is used to reorganize the state machine of the game. Through the attribution of responsibility in each category, the fuzzy design concept is clarified and becomes a maintainable software. |
第三語言摘要 | |
論文目次 |
目錄 壹、緒論 1 1.1. 研究動機 1 貳、系統總覽 2 2.1.系統概觀 2 2.1.1. 遊戲的故事及關卡 2 2.1.2. 場景架構 2 2.1.3戰鬥 4 2.1.4.選單 6 2.2. 開發與重組的工具 6 2.3參考文獻 6 參、全面性的初步重組 7 3.1. 調整魔法數(Magic Number): 7 3.2.調整不當的命名 9 3.3. 某些只用0,1的int型態改為boolean 10 3.4.調整初始值的設定方式 10 3.5. 將重複的程式碼抽出為函數 11 3.6. 調整雜亂的流程邏輯 14 3.7.由工作太多的函數內拆出函數 16 3.8. 將過大的類別瘦身 19 3.9.調整類別變數 24 3.10. switch改成虛擬呼叫 26 肆、重組狀態圖 30 4.1 遊戲的總狀態圖 30 4.1.1 開始狀態圖 31 4.1.2 戰鬥狀態圖 33 4.1.3 選單流程圖 34 4.1.4 劇情狀態圖 35 4.1.5 魔王對話狀態圖 36 4.1.6 遊戲結束狀態圖 36 4.2 自定義按鈕類別 37 4.3 狀態類別 39 4.3.1 AbsGameState類別 40 4.3.2 WelcomeState類別 41 4.3.3 SceneStoryState和SceneWinState類別 43 4.3.4 MoveState類別 46 4.3.5 BattleState類別 50 4.3.6 OptionState類別 58 4.3.7 BossDiaLogState類別 58 4.3.8 GameOverState類別 60 伍、結論 61 陸、參考文獻 62 圖目錄 圖 1.草原地圖全圖 3 圖2.平常行走時 3 圖3 進入陷阱時的畫面 4 圖4. 戰鬥截圖 5 圖5.選單系統 5 圖6.MagicNumber案例之一 7 圖7.重組後的MagicNumber 7 圖8.MagicNumber案例之二 8 圖9.變數取名不當實例 9 圖10.修改之後圖例 9 圖11.alive欄位重組前 10 圖12.alive欄位重組後 10 圖13.重組前的Map類別 11 圖14.重組後的Map類別 11 圖15.重複的程式碼 12 圖16. 抽象類別AbsGameButton及子類別DirectionButton 13 圖17.在MoveState裡新增類別變數 13 圖18.重組後示意圖 14 圖19.減少if的層數 15 圖20.交換if部與else部後 16 圖21.過長的函數 17 圖22.PngCollection類別裡的array 18 圖23.類別Skill 18 圖24.簡化後示意圖 19 圖25.過大類別 21 圖26.類別AbsGameState 21 圖27. 類別MoveState 22 圖28.類別BattleRolling 23 圖29. 類別Map 24 圖30.調整類別變數 25 圖31.類別GameCharacter 25 圖32.重組後示意圖 26 圖33.類別Battle 27 圖34.類別BattleInfo 28 圖35.類別CpxBattleInfo 28 圖36.重組後示意圖 29 圖37.遊戲的總狀態圖 30 圖38.開始介面狀態圖 32 圖39.戰鬥狀態圖 33 圖40 選單流程圖 34 圖41.劇情一狀態圖 35 圖42.劇情二狀態圖 35 圖43.魔王對話狀態圖 36 圖44.遊戲結束狀態圖 36 圖45.AbsGameButton繼承圖 37 圖46.類別AbsGameButton 38 圖47.類別DirectionButton 39 圖48. AbsGameState類別繼承圖 40 圖49.類別AbsGameState的抽象函數 40 圖50. WelcomeState的enterState 41 圖51.WelcomeState的myOnDraw 41 圖52.WelcomeState的myActionDown 42 圖53.SceneStoryState的enterState 43 圖54. SceneStory的enterState 43 圖55. SceneStory的myOnDraw 44 圖56. SceneStoryState的myActionDown 44 圖57. SceneWinState的myActionDown 45 圖58.MoveState的enterState 46 圖59.MoveState的myOnDraw 46 圖60.MoveState的myActionDown(一) 47 圖61.MoveState的myActionDown(二) 48 圖62.keepOnMoving函數 49 圖63. deleteMovingTimer函數 49 圖64. startMoveTimerTask函數 49 圖65.BattleState的enterState 50 圖66.BattleState的myOnDraw 50 圖67. BattleState的myActionDown 51 圖68.BattleBegin的enterState 51 圖69. BattleBegin的myActionDown 52 圖70.BattleRolling的enterState 53 圖71.diceRandom函數 53 圖72.startDiceTask函數 54 圖73.stopRandom函數 54 圖74.battleAnime函數 54 圖75.startAnimeTask函數 55 圖76.stopAnime函數 55 圖77.battleResult 55 圖78.BattlePick的enterState 56 圖79.BattlePick的myActionDown 56 圖80.BattleEnd的enterState 57 圖81.BattleEnd的myActionDown 57 圖82.OptionState的enterState 58 圖83. OptionState的myOnDraw 58 圖84. BossDiaLogState的enterState 59 圖85. BossDialog的myOnDraw 59 圖86. BossDialog的myActionDown 59 圖87.GameOverState的enterState 60 圖88.GameOverState的myOnDraw 60 圖89. GameOverState的myActionDown 60 |
參考文獻 |
Wiki, Code refactoring, 網址: https://zh.wikipedia.org/wiki/%E4%BB%A3%E7%A0%81%E9%87%8D%E6%9E%84, 上網日期:2017年11月20日。 陳子俊等, 亞瑟 - 2D冒險解迷RPG, 專題製作程式及系統文件, 2016年10月 Wiki, 有限狀態機, 網址:https://zh.wikipedia.org/wiki/%E6%9C%89%E9%99%90%E7%8A%B6%E6%80%81%E6%9C%BA, 上網日期:2017年11月20日 Wiki, Paint to SAI, 網址:https://zh.wikipedia.org/wiki/Paint_Tool_SAI,上網日期:2017年11月20日。 Wiki, Android Studio,網址: https://zh.wikipedia.org/wiki/Android_Studio,上網日期: 2017年11月20日 M. Fowler et al. Refactoring: Improving the Design of Existing Code, Addison-Wesley, 1999 |
論文全文使用權限 |
如有問題,歡迎洽詢!
圖書館數位資訊組 (02)2621-5656 轉 2487 或 來信