Re: [問題] 一個不會形容的問題(新手 附程式碼)
顯然是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
推
04/03 14:31, , 1F
04/03 14:31, 1F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):