public class Player {
private int chip;
private int maxChip;
private String state;
public Player(int chip) {
super();
setChip(chip);
setMaxChip(chip);
setState();
}
public int getChip() {
return chip;
}
public void setChip(int chip) {
if(chip > 0){
this.chip = chip;
}
else{
this.chip = 0;
}
}
public String getState() {
return state;
}
public void setState() {
if(this.maxChip>this.chip){
this.state = "负";
}
else if(this.maxChip<this.chip){
this.state = "胜";
}
else{
this.state = "保本";
}
}
public int getMaxChip() {
return maxChip;
}
private void setMaxChip(int maxChip) {
this.maxChip = maxChip;
}
}
---------------------------------------------------------------------------------------------------------------------------------------
package game;
public class Stake {
private String name;
private int odds;
public Stake(String name, int odds) {
super();
setName(name);
setOdds(odds);
}
public String getName() {
return name;
}
private void setName(String name) {
this.name = name;
}
public int getOdds() {
return odds;
}
private void setOdds(int odds) {
this.odds = odds;
}
}
--------------------------------------------------------------------------------------
package game;
import java.util.Scanner;
import com.sun.xml.internal.ws.api.pipe.NextAction;
public class Turntable {
private Player player;
private Stake[] stake = new Stake [6];
public Turntable(Player player) {
super();
setPlayer(player);
setStake();
}
private Player getPlayer() {
return player;
}
private void setPlayer(Player player) {
this.player = player;
}
private Stake[] getStake() {
return stake;
}
private void setStake() {
this.stake[0] = new Stake("牛",2);
this.stake[1] = new Stake("虎",2);
this.stake[2] = new Stake("象",6);
this.stake[3] = new Stake("龙",10);
this.stake[4] = new Stake("羊",0);
this.stake[5] = new Stake("兔",0);
}
public void play(){
Scanner scan = new Scanner(System.in);
while(true){
System.out.println("--------------------------------------------------------------");
System.out.println("当前拥有筹码:"+this.player.getChip()+"\t\t状态:"+this.player.getState());
System.out.println("--------------------------------------------------------------");
for (int i = 0; i < 4; i++) {
System.out.print(i+1+"."+this.stake[i].getName()+" 赔率("+this.stake[i].getOdds()+")\t");
}
System.out.println();
int n,s;
while(true){
System.out.print("请选择(1-4):");
int num = scan.nextInt();
if(num>0&&num<=4){
n = num;
break;
}
else{
System.out.println("输入错误!");
}
if(this.stake[num-1].getOdds()>this.player.getChip()){
System.out.println("筹码不足!");
}
}
while(true){
System.out.print("你要押多少筹码(1-"+this.player.getChip()+"):");
int stake = scan.nextInt();
if(stake>0&&stake<=this.player.getChip()){
s = stake;
break;
}
else{
System.out.println("筹码不足!");
}
}
result(n,s);
System.out.println("按回车键继续");
Scanner s1 = new Scanner(System.in);
s1.nextLine();
if(this.player.getChip() == 0){
break;
}
this.player.setState();
}
System.out.println("你输掉了所有筹码,游戏结束!");
}
private void result(int num,int stake){
this.player.setChip(this.player.getChip()-stake);
System.out.println("你在“"+this.stake[num-1].getName()+"”上押入了"+stake+"个筹码,剩余"+this.player.getChip()+"个筹码");
System.out.print("轮盘开始转动");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print(".");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print(".");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(".");
int n = (int)((Math.random()*(54-35)+35));
int j = 1,temp=1;
int[] a = new int[n];
for (int i = 1; i <= n; i++) {
j+=temp;
if(i%2==0){
temp++;
}
try {
Thread.sleep(j);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int t = (int)((Math.random()*(6-0)+0));
while(true){
if(i == 1){
a[i-1]=t;
break;
}
a[i-1] = t;
if(a[i-1] != a[i-2]){
break;
}
t = (int)((Math.random()*(6-0)+0));
}
System.out.print(this.stake[t].getName()+" ");
if(i%18==0){
System.out.println();
}
if(i == n){
System.out.println();
System.out.println("轮盘指向"+"“"+this.stake[t].getName()+"”");
if(num-1 == t){
System.out.println("恭喜你,押注成功!");
System.out.println("获得了"+this.stake[t].getOdds()*stake+"筹码");
this.player.setChip(this.player.getChip()+(this.stake[t].getOdds()*(stake+1)));
}
else{
}
}
}
}
}
package game;
import java.util.Scanner;
public class StartUp {
public static void main(String[] args) {
Player p = new Player(20);
Turntable e = new Turntable(p);
e.play();
}
}