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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

重游java(猜拳项目)

發布時間:2025/3/21 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 重游java(猜拳项目) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

記錄生活吧,自己亂搞的,肯定有很多需要優化的地方,各位大佬多多諒解

游戲規則
猜拳游戲
玩家和電腦進行猜拳(石頭剪刀布)
每回合分別由玩家和電腦依次出拳
打印顯示雙方出拳的結果,并對結果進行判定
回合結束后詢問玩家是否要繼續游戲
如果玩家選擇繼續游戲則開啟下一個回合的猜拳
否則游戲結束
游戲結束后統計前面回合的數據
數據要求顯示游戲的總局數,玩家勝利的場數,平局的場數以及失敗的場數并顯示勝率
根據勝利的場數打印顯示最終結果(玩家勝場大于電腦勝場則表示玩家勝利)

import java.io.Serializable; import java.util.Random; import java.util.SplittableRandom;/*** 電腦類*/ public class Computer {/*** 出拳的方法*/public int showFinger(){//使用隨機數(1-3)出拳Random a= new Random();int b=a.nextInt(3)+1;return b;}}package com.igeek.demo1;import javax.xml.stream.events.StartDocument; import java.awt.image.PixelInterleavedSampleModel; import java.util.Scanner;/*** 游戲類 封裝了游戲的業務內容*/ public class Game {//玩家private Player player = new Player();//電腦private Computer cpu = new Computer();int players;int cpus;/*** 開啟游戲*/public void start() {player.setWinCount(0);player.setLoseCount(0);player.setDogfallCount(0);//執行游戲回合gameLogic();//顯示游戲統計結果}/*** 每個回合的游戲內容*/public void gameLogic() {players = player.showFinger();//玩家出拳cpus = cpu.showFinger();//電腦出拳//顯示出拳結果System.out.println("玩家 :"+changeFinger(players));System.out.println("電腦 :"+changeFinger(cpus));//判定出拳結果//詢問玩家是否繼續游戲showResult();while(continues()==1){gameLogic();}}/*** 將出拳的數值轉換為字符信息(石頭剪刀布)的方法** @param figer* @return*/public String changeFinger(int figer) {if (figer == 1) {return "石頭";} else if (figer == 2) {return "剪刀";} else {return "布";}}/*** 游戲結果的顯示統計*/public void showResult () {pandingResult(players,cpus);System.out.println("平局為:"+player.getDogfallCount());System.out.println("勝局為:"+player.getWinCount());System.out.println("敗局為:"+player.getLoseCount());}public int continues(){System.out.println("是否繼續:繼續則輸1;退出則輸0" );Scanner input =new Scanner(System.in);int b=input.nextInt();return b;}public void pandingResult (int a,int b) {if(a==1&&b==1){player.setDogfallCount(player.getDogfallCount()+1);}else if(a==2&&b==2){player.setDogfallCount(player.getDogfallCount()+1);}else if(a==3&&b==3){player.setDogfallCount(player.getDogfallCount()+1);}else if(a==1&&b==2){player.setWinCount(player.getWinCount()+1);}else if(a==1&&b==3){player.setLoseCount(player.getLoseCount()+1);}else if(a==2&&b==1){player.setLoseCount(player.getLoseCount()+1);}else if(a==2&&b==3){player.setWinCount(player.getWinCount()+1);}else if(a==3&&b==1){player.setWinCount(player.getWinCount()+1);}else if(a==3&&b==2){player.setLoseCount(player.getLoseCount()+1);}}}package com.igeek.demo1;import com.sun.jdi.PathSearchingVirtualMachine;import java.util.Scanner;/*** 玩家類*/ public class Player {//勝場private int winCount;//平場private int dogfallCount;//輸場private int loseCount;/*** 出拳的方法*/public int showFinger(){System.out.println("請輸入1:石頭;2:剪刀;3:布");Scanner input =new Scanner(System.in);int b=input.nextInt();return b;}public int getWinCount() {return winCount;}public void setWinCount(int winCount) {this.winCount = winCount;}public int getDogfallCount() {return dogfallCount;}public void setDogfallCount(int dogfallCount) {this.dogfallCount = dogfallCount;}public int getLoseCount() {return loseCount;}public void setLoseCount(int loseCount) {this.loseCount = loseCount;} }package com.igeek.demo1;public class main {public static void main(String[] args) {Game am=new Game();am.start();}}

總結

以上是生活随笔為你收集整理的重游java(猜拳项目)的全部內容,希望文章能夠幫你解決所遇到的問題。

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