小遊戲一般在一個類裡就可以完成,先介紹兩個類:
Random:
随機數類,用于生成随機數
currenTimeMillis:
時間類,可以得到毫秒機關的時間
先完成一個簡單的說明界面:
導入類,建構好類的對象友善一會得使用
<a href="https://s3.51cto.com/oss/201710/19/36b650a310c49f1feb8be9d89d80cf28.png" target="_blank"></a>
接下來代碼的作用與說明都寫在注釋裡:
字元的輸出:
<a href="https://s4.51cto.com/oss/201710/19/339caf9e878995667a4d2649e31ad0b5.png" target="_blank"></a>
字元的輸入:
<a href="https://s2.51cto.com/oss/201710/19/ffb5fde80df0af57714869f624cb69bd.png" target="_blank"></a>
列印得分:
<a href="https://s1.51cto.com/oss/201710/19/2eacf957e317728e8ac4b5899668fbfa.png" target="_blank"></a>
完成效果:
<a href="https://s3.51cto.com/oss/201710/19/754d35610f645bbac243bbae776526bb.png" target="_blank"></a>
<a href="https://s2.51cto.com/oss/201710/19/4c63dbf0280ca90d31c26a07b7f14c06.png" target="_blank"></a>
本文轉自 ZeroOne01 51CTO部落格,原文連結:http://blog.51cto.com/zero01/1974356,如需轉載請自行聯系原作者