作者kyoby (nothing here)
站内java
标题Re: [问题] 一个不会形容的问题(新手 附程式码)
时间Thu Apr 3 14:09:24 2008
显然是setLocation方法有误啊...
按你的方法,随机出来的三个数要互不相等才赋上去的,如果其中有两个相等就根本没
进行赋值操作,
你可以加个循环,如果没有赋值的话就从来....
恕删
: public void setLocations() //0-9间随机指定三个数字放置地雷
: {
: int a=(int)(Math.random()*10);
: int b=(int)(Math.random()*10);
: int c=(int)(Math.random()*10);
: boolean checkNum=(a!=b && a!=c && b!=c);
: if(checkNum==true) //避免三个地雷放再同一个位置
: {
: locations.add(a);
: locations.add(b);
: locations.add(c);
: }
: }
: locations.remove(playerguess);
: }
: else if (guessedNum.contains(playerguess))
: {
: System.out.println("The place has been checked");
: guessedNum.remove(playerguess);
: numOfGuess--;
: }
: else
: {
: System.out.println("Wrong! Please guess again");
: }
: guessedNum.add(playerguess); //将使用者猜的数字存起来
: }
: System.out.println("Congratulations! You took "+numOfGuess+" ti
: mes to finish the game");
: }
: public void getRank() //根据使用者猜测的次数评分
: {
: int grade=(int)((100*(10-numOfGuess))/7);
: System.out.println("Your grade is "+grade);
: }
: }
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.108.28.85
1F:推 yDoOw:谢谢你 我知道该怎麽改了 :) 04/03 14:31