基于Android平臺的五子棋游戲的設計與實現(xiàn).doc
Android平臺五子棋游戲的設計與實現(xiàn)Android平臺五子棋游戲的設計與實現(xiàn)摘 要在如今這個智能手機系統(tǒng)群雄角逐的時候,2007年Google推出了一款名為Android的開源智能手機操作系統(tǒng),它采用Linux內(nèi)核,開放手機聯(lián)盟成員可以任意使用和修改SDK包,系統(tǒng)的開源性使其具有良好的拓展性。這款軟件包括了操作系統(tǒng)、用戶界面和應用程序,即智能手機工作所需要的全部軟件。Android的最大特點是其開放性體系架構(gòu),不僅具有非常好的開發(fā)、調(diào)試環(huán)境,而且還支持各種可擴展的用戶體驗,包括豐富的圖形組件、多媒體支持功能以及強大的瀏覽器。因此,對于軟件從業(yè)人員來說,Android平臺具有無限的吸引力。本文圍繞一個“基于Android平臺的五子棋游戲設計與開發(fā)”程序的設計和應用系統(tǒng)的開發(fā)課題為背景,介紹了在Android平臺上以Java為語言編寫游戲的過程。五子棋游戲的開發(fā)不僅是一個簡單游戲的編寫過程,更重要的是在系統(tǒng)分析和設計階段所做的工作。本程序主要講述了程序的概要設計、核心設計階段,利用SQlite、SharedPreferences等數(shù)據(jù)存儲功能,直到形成一個完善的可行性系統(tǒng)?!娟P鍵字】Android、五子棋、游戲開發(fā)、JavaAbstractIn the intelligent mobile phone system to compete against the top when, in 2007 Google launched a Android open source intelligence mobile phone operating system, it uses the Linux kernel, open mobile phone union members can use and modify SDK package, system open source so that it has good expansibility. This software includes the operating system, the user interface and the application of intelligent mobile phone work, which required all software. Android is the biggest characteristic of its open architecture, not only has the very good development, debugging environment, but also supports a variety of extensible user experience, including a rich graphical components, multimedia support and powerful browser. Therefore, for software professionals, the Android platform has the infinite attraction.This paper focuses on a platform based on the Android Gobang game design and development program design and development of application system project as background, introduced in the Android platform based on Java language game process. Gobang game development is not only a simple game of the preparation process, but more importantly in the system analysis and design phase work. This program focuses on the overall design of the procedure, a summary of the design phase, using the data storage function of SQlite, SharedPreferences and so on, until the feasibility of forming a perfect system.Key words: Android, Java, Gobang, game development1. 引言隨著智能手機的快速普及,智能手機操作系統(tǒng)市場風生水起。為了讓智能手機用戶能夠隨時隨地查詢互聯(lián)網(wǎng)所提供的服務,一種高效的辦法就是將應用系統(tǒng)的功能拓展到手機終端上,讓手機能夠通過移動網(wǎng)以及互聯(lián)網(wǎng)訪問Web網(wǎng)站并處理各種各樣的業(yè)務。因此,智能手機的應用軟件及其需要的服務將有廣闊的發(fā)展前景。1.1 人機對弈五子棋開發(fā)背景每個手機上都有手機游戲,上下班以及無聊閑暇時游戲是人們娛樂的一種方式。Android平臺下的手機游戲更是受顧客的親睞,手機游戲不僅玩起來比較方便,還有助于開發(fā)我們的思維,使大家在娛樂的同時也增長了見識,拓展了思維。五子棋對思維及協(xié)調(diào)能力有益,能使我們注意力集中,耐心也有明顯的提升,培養(yǎng)我們的邏輯思維能力,對智力以及記憶力都很有幫助。1.2 相關知識的介紹Android是Google于07年發(fā)布的基于Linux平臺的開源手機操作系統(tǒng),號稱是首個為移動終端打造的真正開放和完整的移動軟件。自從Google發(fā)布智能手機Android操作系統(tǒng)平臺以來,Android平臺一直以驚人速度挺進,并支持Android智能手機迅速進入領先行列。Android在全球的智能手機市場的份額從10年第五位躍進到11年的第一位。目前,智能手機市場份額中Android仍然排名第一,占市場份額的46.3%,iOS系統(tǒng)只占30%。迄今Android是智能機市場上最大的贏家,是銷售增長最快、最成功的競爭者。本游戲采用當前很熱的Android系統(tǒng), 以Java語言為基礎的2D手機游戲。用戶游戲界面通過手機終端來實現(xiàn),較強的人際交互。這樣就大大簡化了用戶的操作,該游戲為免費游戲,用戶可以放心使用。此外,本系統(tǒng)采用了SharedPreferences作為應用程序的數(shù)據(jù)存儲,用來存儲簡單的配置信息,簡單快捷,占用系統(tǒng)資源少。背景音樂采用媒體播放功能實現(xiàn),控制也比較方便。1.2.1 開發(fā)工具簡介該系統(tǒng)的開發(fā)環(huán)境是MyEclipse8.5、JDK1.6、Android SDK,運用了Java語言。 Java是Android的基礎開發(fā)語言,java是一門各方面性能都很好的編程語言,它的基本特點是簡單、面象對象、分布式、解釋的、健壯的、安全的、結(jié)構(gòu)中立的、可移植的、性能很優(yōu)異的、多線程的、動態(tài)的,適合在internet環(huán)境上開發(fā)應用系統(tǒng)。java可以制作大部分網(wǎng)絡應用程序系統(tǒng),而且與當今流行的WWW瀏覽器結(jié)合得很好。Java也是一種與平臺無關的語言,因此用Java開發(fā)的網(wǎng)絡應用系統(tǒng)可以在各種平臺上運行,大大增加了開發(fā)效率,減少重復勞動。而且,Java集成的網(wǎng)絡功能有利于開發(fā)網(wǎng)絡應用系統(tǒng)。JDK(Java Development Kit)是Sun Microsystems針對Java開發(fā)員的產(chǎn)品。自從Java推出以來,JDK已經(jīng)成為使用最廣泛的Java SDK。JDK 是整個Java的核心,包括了Java運行環(huán)境,Java工具和Java基礎的類庫。JDK是學好Java的第一步。而專門運行在x86平臺的Jrocket在服務端運行效率也要比Sun JDK好很多。從SUN的JDK5.0開始,提供了泛型等非常實用的功能,其版本也不斷更新,運行效率得到了非常大的提高。MyEclipse企業(yè)級工作平臺(MyEclipse Enterprise Workbench ,簡稱MyEclipse)是對EclipseIDE的擴展,利用它我們可以在數(shù)據(jù)庫和JavaEE的開發(fā)、發(fā)布以及應用程序服務器的整合方面極大的提高工作效率。它是功能豐富的JavaEE集成開發(fā)環(huán)境,包括了完備的編碼、調(diào)試、測試和發(fā)布功能,完整支持HTML,Struts,JSP,CSS,Javascript,Spring,SQL,Hibernate。在結(jié)構(gòu)上,MyEclipse的特征可以被分為7類:1 JavaEE模型2 WEB開發(fā)工具 3 EJB開發(fā)工具4 應用程序服務器的連接器5 JavaEE項目部署服務6 數(shù)據(jù)庫服務7 MyEclipse整合幫助對于以上每一種功能上的類別,在Eclipse中都有相應的功能部件,并通過一系列的插件來實現(xiàn)它們。MyEclipse結(jié)構(gòu)上的這種模塊化,可以讓我們在不影響其他模塊的情況下,對任一模塊進行單獨的擴展和升級。簡單而言,MyEclipse是Eclipse的插件,也是一款功能強大的JavaEE集成開發(fā)環(huán)境,支持代碼編寫、配置、測試以及除錯,MyEclipse6.0以前版本需先安裝Eclipse。MyEclipse6.0以后版本安裝時不需安裝Eclipse。SDK(software development kit)軟件開發(fā)工具包。被軟件開發(fā)工程師用于為特定的軟件包、軟件框架、硬件平臺、操作系統(tǒng)等建立應用軟件的開發(fā)工具的集合。1.2.2 系統(tǒng)運行配置操作系統(tǒng):Android 2.1以上。開發(fā)包:JDK 1.6、Android SDK。數(shù)據(jù)存儲:SharedPreferences、SQlite。2. 需求分析2.1 功能需求1.適合不同階段的玩家(新手和熟手)。2.玩家與手機對弈。3.可以為新手提供游戲解說。4.可以紀錄玩家的最高游戲紀錄(以玩家游戲勝利的時間為標準。)。2.2 性能需求1硬件環(huán)境 :PC2軟件環(huán)境 :Windows XP、Android 2.1以上3. 概要設計3.1 功能設計五子棋分為五個模塊:開始游戲、游戲設置、最高紀錄、游戲說明、退出游戲。1.開始游戲:.點擊進入游戲。2. 游戲設置:.音效設置:開啟/關閉音效、背景音樂的開/關。 .難度設置:簡單,中等,較難。3.最高紀錄:.紀錄不同難度獲勝的最短時間,可清空。 4. 游戲說明: .五子棋游戲規(guī)則的說明及操作說明。5.退出游戲: .退出游戲。3.2 系統(tǒng)功能結(jié)構(gòu)及流程圖根據(jù)系統(tǒng)功能的要求,可以將系統(tǒng)分解成幾個功能模塊來分別設計。系統(tǒng)結(jié)構(gòu)如圖3.1所示:五 子 棋游戲退出游戲說明最高紀錄游戲設置游戲開始(默認簡單)簡單、中級、困難紀錄修改(可清空)3.1系統(tǒng)結(jié)構(gòu)圖3.3 數(shù)據(jù)存儲設計SharePreference主要用來保存應用程序的屬性設置,在Android平臺常用于存儲較簡單的參數(shù)設置。其采用了Map數(shù)據(jù)結(jié)構(gòu)來存儲數(shù)據(jù),以鍵值的方式存儲,可以簡單的讀取與寫入。最高紀錄則用此存儲方式進行存儲。通過getPreferences()方法來獲得Preferences對象,通過“SharePreferences.Editor editor=uiState.edit();”取得編輯對象,然后通過“deitor.putPreferences()方法添加數(shù)據(jù),最后用commit()方法保存這些數(shù)據(jù),如果不需要與其它模塊共享數(shù)據(jù),可以使用Activity.getPreferences()方法保持私有。SQlite是一個開源的關系型數(shù)據(jù)庫,功能非常強大,可以存儲大量的數(shù)據(jù),能夠很容易地對數(shù)據(jù)進行使用、更新、維護等操作。根據(jù)系統(tǒng)所做的需求分析和系統(tǒng)設計,SharedPreferences為本系統(tǒng)最有效的存儲方式。4. 棋盤、棋子的繪制本設計中棋盤的設置采用drawLine(float startX, float startY, float stopX, float stopY, Paint paint)/畫線,參數(shù)一起始點的x軸位置,參數(shù)二起始點的y軸位置,參數(shù)三終點的x軸水平位置,參數(shù)四y軸垂直位置,最后一個參數(shù)為Paint畫刷對象。本設計中棋子是用drawCircle在坐標上繪制一個經(jīng)典幾何圖形。先判斷是否有棋,是黑子還是白子,然后判斷是哪個坐標,然后調(diào)用drawCircle繪制棋子canvas.drawCircle(float,float, float, Paint)方法用于畫圓,前兩個參數(shù)代表圓心坐標,第三個參數(shù)為圓半徑,第四個參數(shù)是畫筆;5. 游戲核心設計5.1游戲的三種不同難度等級的設計與輸贏判斷手機與玩家的勝負判斷:每走一步,調(diào)用判斷方法。其思想為:是根據(jù)當前最后一個落子的情況來判斷勝負的。實際上需要從四個位置判斷,以該子為出發(fā)點的水平,豎直和兩條分別為 45度角和135度角的線,目的是看在這四個方向是否最后落子的一方構(gòu)成連續(xù)五個的棋子,如果是的話,就表示該盤棋局已經(jīng)分出勝負。本游戲中最重要的是難度設計,游戲流程如圖5.1所示。NYYNNYNY游戲開始電腦落子電腦下棋玩家下棋勝負判斷結(jié)束是否玩家勝玩家勝利的時間小于最高紀錄的時間刷新最高紀錄玩家勝電腦勝玩家選擇執(zhí)子顏色5.1游戲流程圖三大難度的算法設計,算法的主體思想分三個步驟:第一步:根據(jù)雙方的當前的形勢循環(huán)地假設性的分別給自己和對方下一子(在某個范圍內(nèi)下子),并判斷此棋子能帶來的形勢上的變化。第二步:根據(jù)上一步結(jié)果,組合每一步棋子所帶來的所有結(jié)果(包括電腦和玩家的)。第三步:根據(jù)用戶給的游戲難度對上一步結(jié)果進行排序,并選子(有進攻形、防守形規(guī)則)。名詞解析:活四棋:在(橫、豎或斜角)方向有同色四子不間隔連成一線,兩端都可落子活三棋:在(橫、豎或斜角)方向有同色三子不間隔連成一線,兩端都可落子單活棋:即在某方向上連成一線的棋只有一端可落子四沖棋:除活四外的,再下一著棋便可形成五連,并且存在五連的可能性的局面搜索方法舉例(活三棋):OYX5.2活三棋的示例圖棋盤上的坐標都為大于等于0,想要判斷活三棋,先判斷在哪個方向上有同色的連棋:1) 如圖黑子此種情況下在與Y/X軸成45。角的方向上有同色連棋,接下來判斷三棋子的坐標是否依次相鄰遞增1,如果是,再判斷,最小坐標(非原點)減1和最大坐標(非棋盤最大坐標)加1的兩坐標點上是否為空,為空則是活三,否則,不是2) 如圖白子與X/Y軸成135。角的方向上有同色連棋,接下來判斷三棋子的X坐標是否依次相鄰遞增1,Y坐標是否依次遞減1,如果是,再判斷,最小坐標(非原點)X坐標減1,Y坐標加1后和最大坐標(非棋盤最大坐標)X坐標加1,Y坐標減1后的兩坐標點上是否為空,為空則是活三,否則,不是3) 如果平行于X/Y軸,則只需根據(jù)X/Y坐標來判斷即可。注:最小坐標、最大坐標根據(jù)各點的X坐標判斷。簡單:簡單難度的實現(xiàn),只有當電腦為活四棋的時候才進攻,其他情況離玩家最近下棋棋子最近的8個位置上的空位上隨機下棋。中等:中等難度的實現(xiàn),電腦只防守,少攻擊。當玩家有“三活棋”以及“四沖”時,防守;否則選擇自己最長連棋并且可下棋的空位下棋。流程圖如圖5.3所示:YYYYYY防守玩家活四棋機活四棋機四沖棋玩家四沖棋機活三棋玩家活三棋進攻結(jié)束5.3中等難度流程圖較難:較難難度的實現(xiàn),機有強烈的防守,有猛烈的攻擊。雙方都不可以制造活4棋,找活3棋子,不行就找半活4(四沖),再不行就找單活3,活2的攻守模式。流程圖如圖5.4所示:YYYYYNNNNNNNNNYYYY開始玩家是否有活四棋玩家是否有活三棋玩家是否有沖四棋能否制造活四棋能否制造沖四棋能否制造單活三能否制造活三棋玩家是否有活三棋能否制造活二能否制造單活二防守下棋5.4較難難度流程圖結(jié)束語經(jīng)過這一段時間的不斷探索,自己對Android的研究,對Android游戲有了進一步的了解和學習。這段時間的不懈努力,五子棋游戲系統(tǒng)設計已初步完成。系統(tǒng)設計為整個游戲構(gòu)建了框架,各個功能模塊實現(xiàn)各個細節(jié)部分。難,中,易三種游戲難度的選擇。 系統(tǒng)的詳細設計將根據(jù)系統(tǒng)分析階段的結(jié)論具體化,并完成各個模塊的相關功能,從而實現(xiàn)Android五子棋。隨著3G智能機的普及,人們對游戲的要求也越來越高,人機對戰(zhàn)的實現(xiàn)往往是不夠的。現(xiàn)在網(wǎng)絡越來越好,網(wǎng)絡雙人對戰(zhàn)也是一個很不錯的研究方向。參考文獻1 吳亞峰,索光亞.Android 2.0游戲開發(fā)實戰(zhàn)寶典M.北京:人民郵電出版社2 楊豐盛.Android應用開發(fā)揭秘M.北京:機械工業(yè)出版社3 高煥堂.Android應用框架原理與程式設計36技M/OL4 裴佳迪,馬超,孫仁貴.Android開發(fā)全程實錄M.人民郵電出版社5 馬越.Android的架構(gòu)與應用D.北京:中國地質(zhì)大學(北京)碩士學位論文.g an employment tribunal claiEmployment tribunals sort out disagreements between employers and employees.You may need to make a claim to an employment tribunal if: you dont agree with the disciplinary action your employer has taken against you your employer dismisses you and you think that you have been dismissed unfairly.For more information about dismissal and unfair dismissal, seeDismissal.You can make a claim to an employment tribunal, even if you haventappealedagainst the disciplinary action your employer has taken against you. However, if you win your case, the tribunal may reduce any compensation awarded to you as a result of your failure to appeal.Remember that in most cases you must make an application to an employment tribunal within three months of the date when the event you are complaining about happened. If your application is received after this time limit, the tribunal will not usually accept i.If you are worried about how the time limits apply to you, take advice from one of the organisations listed underFurther help.Employment tribunals are less formal than some other courts, but it is still a legal process and you will need to give evidence under an oath or affirmation.Most people find making a claim to an employment tribunal challenging. If you are thinking about making a claim to an employment tribunal, you should get help straight away from one of the organisations listed underFurther help.If you are being represented by a solicitor at the tribunal, they may ask you to sign an agreement where you pay their fee out of your compensation if you win the case. This is known as adamages-based agreement. In England and Wales, your solicitor cant charge you more than 35% of your compensation if you win the case.If you are thinking about signing up for a damages-based agreement, you should make sure youre clear about the terms of the agreement. It might be best to get advice from an experienced adviser, for example, at a Citizens Advice Bureau. To find your nearest CAB, including those that give advice by e-mail, click onnearest CAB.For more information about making a claim to an employment tribunal, seeEmployment tribunals.The (lack of) air up there Watch mCayman Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associations 150th anniversary celebrations and will attend Citys Premier League match at Chelsea on Sunday.I am going to be at the match tomorrow and I have asked to meet Yaya Toure, he told BBC Sport.For me its about how he felt and I would like to speak to him first to find out what his experience was.Uefa hasopened disciplinary proceedings against CSKAfor the racist behaviour of their fans duringCitys 2-1 win.Michel Platini, president of European footballs governing body, has also ordered an immediate investigation into the referees actions.CSKA said they were surprised and disappointed by Toures complaint. In a statement the Russian side added: We found no racist insults from fans of CSKA.Age has reached the end of the beginning of a word. May be guilty in his seems to passing a lot of different life became the appearance of the same day; May be back in the past, to oneself the paranoid weird belief disillusionment, these days, my mind has been very messy, in my mind constantly. Always feel oneself should go to do something, or write something. Twenty years of life trajectory deeply shallow, suddenly feel something, do it.一字開頭的年齡已經(jīng)到了尾聲?;蛟S是愧疚于自己似乎把轉(zhuǎn)瞬即逝的很多個不同的日子過成了同一天的樣子;或許是追溯過去,對自己那些近乎偏執(zhí)的怪異信念的醒悟,這些天以來,思緒一直很凌亂,在腦海中不斷糾纏??傆X得自己自己似乎應該去做點什么,或者寫點什么。二十年的人生軌跡深深淺淺,突然就感覺到有些事情,非做不可了。The end of our life, and can meet many things really do?而窮盡我們的一生,又能遇到多少事情是真正地非做不可?During my childhood, think lucky money and new clothes are necessary for New Year, but as the advance of the age, will be more and more found that those things are optional; Junior high school, thought to have a crush on just means that the real growth, but over the past three years later, his writing of alumni in peace, suddenly found that isnt really grow up, it seems is not so important; Then in high school, think dont want to give vent to out your inner voice can be in the high school children of the feelings in a period, but was eventually infarction when graduation party in the throat, later again stood on the pitch he has sweat profusely, looked at his thrown a basketball hoops, suddenly found himself has already cant remember his appearance.童年時,覺得壓歲錢和新衣服是過年必備,但是隨著年齡的推進,會越來越發(fā)現(xiàn),那些東西根本就可有可無;初中時,以為要有一場暗戀才意味著真正的成長,但三年過去后,自己心平氣和的寫同學錄的時候,突然就發(fā)現(xiàn)是不是真正的成長了,好像并沒有那么重要了;然后到了高中,覺得非要吐露出自己的心聲才能為高中生涯里的懵懂情愫劃上一個句點,但畢業(yè)晚會的時候最終還是被梗塞在了咽喉,后來再次站在他曾經(jīng)揮汗如雨的球場,看著他投過籃球的球框時,突然間發(fā)現(xiàn)自己已經(jīng)想不起他的容顏。Originally, this world, can produce a chemical reaction to an event, in addition to resolutely, have to do, and time.原來,這個世界上,對某個事件能產(chǎn)生化學反應的,除了非做不可的堅決,還有,時間。A persons time, your ideas are always special to clear. Want, want, line is clear, as if nothing could shake his. Also once seemed to be determined to do something, but more often is he backed out at last. Dislike his cowardice, finally found that there are a lot of love, there are a lot of miss, like shadow really have been doomed. Those who do, just green years oneself give oneself an arm injection, or is a self-righteous spiritual.一個人的時候,自己的想法總是特別地清晰。想要的,不想要的,界限明確,好像沒有什么可以撼動自己。也曾經(jīng)好像已經(jīng)下定了決心去做某件事,但更多的時候是最后又打起了退堂鼓。嫌惡過自己的怯懦,最終卻發(fā)現(xiàn)有很多緣分,有很多錯過,好像冥冥之中真的已經(jīng)注定。那些曾經(jīng)所謂的非做不可,只是青蔥年華里自己給自己注射的一支強心劑,或者說,是自以為是的精神寄托罷了。At the moment, the sky is dark, the air is fresh factor after just rained. Suddenly thought of blue plaid shirt; Those were broken into various shapes of stationery; From the corner at the beginning of deep friendship; Have declared the end of the encounter that havent start planning. Those years, those days of do, finally, like youth, will end in our life.此刻,天空是陰暗的,空氣里有著剛下過雨之后的清新因子。突然想到那件藍格子襯衫;那些被折成各種各樣形狀的信紙;那段從街角深巷伊始的友誼;還有那場還沒有開始就宣告了終結(jié)的邂逅計劃那些年那些天的非做不可,終于和青春一樣,都將在我們的人生中謝幕。Baumgartner the disappointing news: Mission aborted. r plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.The supersonic descent could happen as early as Sunda.The weatheThe balloon will slowly drift to the edge of space at 120,000 feet ( Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, hell be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end. Skydiver preps for the big jumpWhen he jumps, he is expected to reach the speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enough to stop him completely.If he goes too fast or spins out of control, he has a stabilization parachute that can be deployed to slow him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).In order to deploy this chute successfully, he will have to slow to 172 mph (277 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it wont. Baumgartner still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 feet (7,620 meters).cause there14