我正在研究一個輪盤遊戲,並且我的輪盤類中的makeDecision方法出現錯誤。原因是因爲我在Player類中的updatePot方法遇到問題,不知道該怎麼做。我使用的4類,這是我對每個代碼:麻煩製作Java輪盤遊戲
public class Assign3 {
public static void main(String[] args) {
Roulette roulette = new Roulette();
roulette.run();
}
}
和
public class Roulette {
private String decision;
Player player = new Player();
Wheel wheel = new Wheel();
private void makeDecision(){
String bet = player.getBet();
try {
int value = Integer.parseInt(bet);
if (value == wheel.getValue()){
decision = " you win 40 times your bet";
player.updatePot(40);
} else {
decision = "you lose the game";
player.updatePot(0);
}
} catch (NumberFormatException e){
if (bet.equals("odd")){
if (wheel.getValue() %2 == 0){
decision = "you lose the game";
player.updatePot(0);
} else {
decision = "you win double your bet";
player.updatePot(2);
}
} else if (bet.equals("equals")){
if (wheel.getValue() %2 == 0){
decision = "you win double your bet";
player.updatePot(2);
}
}
}
}
private void displayDecision(){
}
public void run(){
System.out.println("Welcome to Cache Creek style Roulette..bet an amount and type\n"
+ " if you select the correct colour, you win double your bet\n"
+ " if you select the correct odd/even, you win double your bet\n"
+ " if you select the right number, you win 40 times your bet\n"
+ " otherwise you lose your bet\n"
+ " If you lose all your money, the game is over");
do {
player.setBetAmount();
player.setBet();
wheel.spin();
wheel.display();
makeDecision();
displayDecision();
} while (true);
}
}
和
package Assignment3;
import java.util.Scanner;
public class Player {
private int pot = 0;
private int amount = 0;
Scanner input = new Scanner(System.in);
public void setBetAmount() {
System.out.print("\nHow much do you want to bet? ");
amount = input.nextInt();
int pot =100;
if (amount > pot || amount < 1){
System.out.print("Invalid bet amount..How much do you want to bet? ");
amount = input.nextInt();
}
}
public void setBet() {
System.out.print("What is your bet? (odd/even/red/black/exact number)");
}
public String getBet() {
return null;
}
public void updatePot(int i) {
}
}
和
package Assignment3;
import java.util.Random;
public class Wheel {
private int value;
private String colour;
Random random;
public Wheel(){
value = 0;
colour = null;
random = new Random();
}
public int getValue(){
return value;
}
public void setValue(int value){
this.value = value;
}
public String getColour(){
return colour;
}
public void spin(){
value = random.nextInt(39)+1;
colour = (random.nextInt(1)==0)?"red":"black";
}
public void display(){
System.out.print(value+" "+colour);
}
}
你能描述'updatePot'應該做什麼嗎? – 2014-11-14 21:53:51
如果玩家做出正確的選擇,updatePot應該增加他們贏得的獎金到他們現有的底池。 – James 2014-11-14 21:56:48
'鍋+ =我;'..... – 2014-11-14 21:57:59