Re: [問題] 一個不會形容的問題(新手 附程式碼)

看板java作者 (nothing here)時間16年前 (2008/04/03 14:09), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
顯然是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
文章代碼(AID): #17z7ILdI (java)
文章代碼(AID): #17z7ILdI (java)