日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java 编写程序 创建一个游戏【5、6两章的内容】【第5章】

發布時間:2023/12/9 java 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java 编写程序 创建一个游戏【5、6两章的内容】【第5章】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

每次使用單邊大腦的時間不要太久, 連續使用左邊腦30 分鐘如同使用左臂 30 分鐘一樣,

周期性性地交換讓大腦兩側輪流休息。

左腦活動包括了循序漸進的工作,解決邏輯問題與分析;

右腦的活動包括了陰雨、創造性思考、模式匹配與可視化。?




?

【自頂行下的設計】【首先進行高層設計,判斷需要用到的類和方法】

【了解實現的流程】【專注于程序中出現的事物,并設想出需要哪些對象】【流程圖】

? ? ? ? ? ? ? ? ? ? ? ? ?【面向對象的方式思考;專注于程序中出現的“事物”,而不是“過程”】

【開始編寫程序時】【遵循良好的面向對象的原則,并且沒有讓單一的類執行過多的任務】

? ? ? ? ? ? ? ? ? ? ? ? ? ? 你要決定哪個類先創建出來?假設某個類需要用到多個類,又該從哪里開始?

Key Points:

? ? ? ? ? ?創建新的類的時候需要寫出下列3種東西:【偽代碼——>測試碼——>真實碼】:

  • 【偽代碼】大致上包括實例變量的聲明、方法的聲明、和方法的邏輯(邏輯最重要,定義了會發生什么事情)
  • ? ? ? ? ? ? ? ? ? ? ? ? 常用偽代碼語句:Declare ?Make ?Compute ?Invoke ?Repeat/While ?If ? ? ? ?Get ? ? ? ? Set ? Print

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?聲明 ? ? ?定義 ? ?計算 ? ? ? ??調用 ? ? ?循環 ? ? ? ? ? ? ??判斷 ? ?獲得輸入 ??設置 ?打印

  • 偽代碼描述的是要做什么事情而不是如何做;
  • 使用偽代碼來幫助測試碼的設計;
  • 實現方法之前應該要編寫測試碼;



  • ?

    創建Java類:

    • 找出類應該做的事
    • 列出實例變量和方法
    • 編寫方法的偽代碼
    • 編寫方法的測試用程序
    • 實現類
    • 測試方法
    • 除錯或者重新設計
    • 不靠譜之 邀請辣妹參加慶功派對,如家??七天酒店來一發??

    給你聚一個栗子

    • 游戲目標:以最少的猜測次數打掉計算機安排的 dot com目標。
    • 游戲規則:在7*7的網格上,創建3個達康公司的目標。命中3次,則擊沉。
    • 游戲進行:【由于欠缺圖形接口的程序設計,所以在這一次的命令欄上進行。】
    • ? ? ? ? ? ? ? ? 計算機要求你輸入所猜測的位置(如,A3,B2),計算機反饋hit或者miss或者sunk等回應。清除所有的戰艦之后,游戲結束。

    ?




    • ?【列出實例變量和方法】

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?實例變量的聲明? ??Declare an int array to hold the location cells.Call it locationCell.

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Declare an int to hold the numble of hits.Call it numofHits and set it to 0.


    ?

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??方法的聲明 ? ??Declare?a checkYourelf() method that ?takes a String for the user's guess ("1","3" ,etc), checks ?it. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?and?returns a result ?representing a "hit" ?"kill" ?"miss".

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Declare a setLocationCells() setter method that takes an int array(which has the three cell location as ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ints (2.3.4.etc))




    • 【編寫方法的偽代碼】

    ? ? ? ? ? ? ? ? ? ? ? ?Method : String checkYourself(String userGuess)

    ? ? ? ? ? ? ? ? ? ? ? ?Get ?the user's guess as a string parameter

    ? ? ? ? ? ? ? ? ? ? ? ?Convert the guess to an int

    ? ? ? ? ? ? ? ? ? ? ? ??Repeat with each of the location cells in the int array?

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?// Compare the user guess to the location cell

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if the user guess to matches

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?increment the numbers of hits ? ??

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//find out if it was the last location cell;

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if number of ?hits is 3

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return "kill"?

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else return "hit"

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?end if

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? else return "miss"

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? end if

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? end repeat

    ? ? ? ? ? ? ? ? ? ? ? end method


    ?

    ? ? ? ? ? ? ? ? ? ? ?Method :?void?setLocationCells?(int[] cellLocation)

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Get the cell location as an array parameter

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Assign the cell locations parameter to the cell locations instance variable

    ? ? ? ? ? ? ? ? ? ??end method




    概念:極限編程(XP)?建議閱讀專門的書籍,以免一知半解。

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 在編寫真正可用的方法之前,首先編寫出測試方法用的代碼。

    • 【編寫方法的測試用程序?】:創建對象并加以測試其實測試某一個方法;實現并正確執行;

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

    ?

    轉載于:https://www.cnblogs.com/Chuichui233/p/5153880.html

    總結

    以上是生活随笔為你收集整理的Java 编写程序 创建一个游戏【5、6两章的内容】【第5章】的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。