问题描述
自己从网上找的有关21点游戏代码但是复制到了myeclipse9上面一直跑老是报错希望高手们帮我修改一下让它能跑起来报错的一句话是Exceptioninthread"main"java.lang.Error:Unresolvedcompilationproblem:atGame.TPoint.main(TPoint.java:104)
解决方案
解决方案二:
packageGame;importjava.util.ArrayList;importjava.util.Random;importjava.util.Scanner;publicclassTPoint{privateint[]pai=newint[52];//52张牌privateString[]huase={"黑","红","梅","方"};privateString[]paiM={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};//牌面显示privateArrayList<Integer>al=newArrayList<Integer>();//存储玩家手中的牌privateintcurrentPoint;privateintcomputerPoint=0;privateintcurrentPage=0;publicTPoint(){super();xipai();//洗牌fapai();//发牌needPai();//是否要牌computerPai();//电脑发牌result();//计算结果}privatevoidxipai(){for(inti=0;i<52;i++){pai[i]=i;//52张牌赋值}for(intj=0;j<26;j++){//打乱26次Randomr=newRandom();inti1=Math.abs(r.nextInt()%52);//在52张中牌中找到第一张inti2=Math.abs(r.nextInt()%52);//在52张中牌中找到第二张inttemp=pai[i2];pai[i2]=pai[i1];pai[i1]=temp;}}privatevoidfapai(){/*for(inti=0;i<52;i++){System.out.print(pai[i]+"t");}*///先发两张给玩家al.add(pai[0]);al.add(pai[1]);currentPoint+=calPoint(pai[0]);currentPoint+=calPoint(pai[1]);currentPage=2;}privateintcalPoint(inti){//计算牌的点数inttemp=0;if(i%13+1>10){//JQK都是10temp=10;}else{temp=(i+1)%13;}returntemp;}privatevoidneedPai(){while(true){xianshi();//显示牌面if(currentPoint>=21){//玩家点数大于21则不能再要牌break;}System.out.println("是否还要牌,输入N不要!");Scannersc=newScanner(System.in);if(sc.next().equalsIgnoreCase("N")){break;//输入N则结束}else{al.add(pai[currentPage]);//继续添加牌currentPoint+=calPoint(pai[currentPage]);//牌点数+currentPage++;}}}privatevoidxianshi(){for(Integerin:al){//显示玩家手中的牌System.out.print(huase[in/13]+""+paiM[in%13]+"t");//显示花色和牌面}System.out.println("当前总分:"+currentPoint);}privatevoidcomputerPai(){Randomr=newRandom();computerPoint=Math.abs(r.nextInt())%10+16;//电脑的点数在16点到26点System.out.println("n电脑的牌面:"+computerPoint);}privatevoidresult(){if(currentPoint>21){//玩家点数大于21则不能再要牌System.out.println("youlost!");}elseif(currentPoint==computerPoint){System.out.println("youlost!");}elseif(computerPoint>21){System.out.println("youWin!");}elseif(currentPoint>computerPoint){System.out.println("youWin!");}else{System.out.println("youLost!");}}publicstaticvoidmain(String[]args){newTPoint();}}}
解决方案三:
程序没有问题,你把原来的类删了,重新新那建个helloword运行正常后,再把这个代码贴进去。
解决方案四:
额,为毛我运行着着没问题呢。。。你看看包名和运行环境有没有问题。最后吐槽下方法名,好有喜感