package game; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Scanner; public class Game { static int vu = 0; static int wgold = 100; static int dgold = 100; public static void Hs(int hs){//计算花色 hs/=13; if(hs==4){ hs=3; } switch (hs) { case 0: System.out.print("黑桃"); break; case 1: System.out.print("梅花"); break; case 2: System.out.print("方块"); break; case 3: System.out.print("红桃"); break; } } public static void Enter() throws IOException {//停顿 System.out.println("按回车继续"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } private static void Pai(int pai) { switch (pai) { case 1: System.out.println("A"); break; case 11: System.out.println("J"); break; case 12: System.out.println("Q"); break; case 13: System.out.println("K"); break; default: System.out.println(pai); break; } } public static void main(String[] args) throws IOException { Scanner input = new Scanner(System.in); System.out.println(" 抽牌游戏 "); System.out.println("游戏规则"); System.out.println("比大小,A最大 。牌大小一样比花色,黑桃最大,其次是梅花,方块,红桃"); System.out.println("初始金币 玩家 100 电脑金币 100\n开始自动下注10金币"); while(wgold>0){ while(dgold>0){ Enter(); wgold-=10; dgold-=10; System.out.println("玩家金币 "+wgold+"\n电脑金币 "+dgold); System.out.println("玩家抽牌"); Enter(); int hs,pai;//玩家牌花色,牌数 int dhs,dpai;//电脑牌花色,牌数 hs=(int)(1+Math.random()*52);//玩家抽的花色 pai=(int)(1+Math.random()*13);//玩家抽的牌 Hs(hs); Pai(pai); System.out.println("请问是否加注 加注输入加注金币数(不能超过现有金币数) 不加注输入0 电脑自动跟"); jwvu(); if(pai==1){ pai=14;//A最大 } Enter(); System.out.println("电脑抽牌"); dhs=(int)(1+Math.random()*52); dpai=(int)(1+Math.random()*13); Hs(dhs); Pai(dpai); if(pai>dpai){ System.out.println("玩家胜利"); if(vu==0){ wgold+=10*2; }else{ wgold+=10*2+vu*2; } System.out.println("玩家金币"+wgold+"电脑金币"+dgold); Enter(); }else if(pai<dpai){ System.out.println("电脑胜利"); if(vu==0){ dgold+=10*2; }else{ dgold+=10*2+vu*2; } System.out.println("玩家金币"+wgold+"电脑金币"+dgold); Enter(); }else if(pai==dpai){ if(hs<dhs){ System.out.println("玩家胜利"); if(vu==0){ wgold+=10*2; }else{ wgold+=10*2+vu*2; } System.out.println("玩家金币"+wgold+"电脑金币"+dgold); Enter(); }else if(hs>dhs){ System.out.println("电脑胜利"); if(vu==0){ dgold+=10*2; }else{ dgold+=10*2+vu*2; } System.out.println("玩家金币"+wgold+"电脑金币"+dgold); Enter(); }else{ System.out.println("平局"); if(vu==0){ dgold+=10; wgold+=10; }else{ dgold+=10+vu; wgold+=10+vu; } System.out.println("玩家金币"+wgold+"电脑金币"+dgold); Enter(); } } if(wgold==0 || dgold==0)break; } if(wgold==0 || dgold==0)break; } if(wgold<=0)System.out.println("!!!电脑最终获胜!!!"); if(dgold<=0)System.out.println("!!!玩家最终获胜!!!"); } public static void jwvu(){//控制加注数输入 while(true){ Scanner input = new Scanner(System.in); if(input.hasNextInt()){ vu = input.nextInt(); }else{ System.out.println("... 金币用整数计算 重新输入"); jwvu(); break; } if(vu==0){ break; }else if(vu>0 && vu<=wgold){ System.out.println("已加注"); wgold-=vu; if(dgold>vu){ dgold-=vu; }else{ dgold-=dgold; }break; }else{ System.out.println("输入错误 重新输入"); continue; } } } }