java 猜拳小遊戲(3)

來源:互聯網
上載者:User
import java.util.Scanner;/** * 遊戲類 *  * @author  *  */public class game {person user = new person();computer com = new computer();;int count;/** * 遊戲初始化 */public void gameBegin() {System.out.print("*******************歡迎進入遊戲世界***********************"+ "\n\n\n");System.out.print("\t\t" + "********************" + "\n\n\n");System.out.print("\t\t" + "**    猜拳&開始        **" + "\n\n\n");System.out.print("\t\t" + "********************" + "\n\n\n");Scanner input = new Scanner(System.in);System.out.println("出拳規則:1.剪刀 2.石頭 3.布");System.out.println("請選擇人物:1.劉備 2.曹操 3.孫權");int num = input.nextInt();switch (num) {case 1:user.name = "劉備";break;case 2:user.name = "曹操";break;case 3:user.name = "孫權";break;}System.out.println("要開始遊戲嗎(y/n)");String answer = input.next();if (!answer.equals("y")) {System.exit(0);}}/** * 計算對戰結果 */public int calcResult() {count++;return count;}/** * 顯示對戰結果 */public void showResult() {int numA = user.showFlst();// 擷取使用者選擇的結果int numB = com.showflst();if (numA == numB) {System.out.println("結果:打成平手,下次再和你一分高下");} else if ((numA == 1 && numB == 2) || (numA == 2 && numB == 3)|| (numA == 3 && numB == 1)) {System.out.println("結果:電腦贏!!!呵呵,笨笨,下次加油啊");user.score++;} else {System.out.println("結果:" + user.name + "獲勝!!!恭喜恭喜");com.score++;}}}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.