java游戏中人物升级获取金币_编了一个拿金币的小游戏 请大家多多指教

ca56232b3bbedf9a539d07f37fffb99a.gif

3144d8b7615c79d9f638db40d5689d26.gif

a218af6549b45ee526caf607ebff1358.gif

0f8df0e29816ae721419de940fb833d1.gif

编了一个拿金币的小游戏 请大家多多指教

游戏规则是这样的:桌上有一堆金币(30-40枚),玩家和电脑先后从桌上取走金币,最多可以取走3枚,最少取1枚,不能不取,通过猜金币的正反来决定先后顺序,最后桌上留下的最后一枚金币轮到谁取,谁就输了。

PS 我是初学者,接触JAVA才两个星期,请大家指教。

import java.util.Random;

import java.util.Scanner;

public class Playgames

{

static int coinscope, result;

static int coinNum;

static String side;

public static String selection;

static int i;

static int c;

static int d;

static int e;

static int f;

static int g = 0;

public static void main(String[] args)

{

Scanner input = new Scanner(System.in);

coinNum = new Random().nextInt(10)+30;

System.out.println("\nThe number of coins is " + coinNum);

c = coinNum;

System.out.println("\nPlease choose the side of the coin:(1.head or 2.tail) ");

int Num = input.nextInt();

while(Num>2 | Num<1)

{

System.out.println("\nInvaild selection, please choose 1 or 2");

Num = input.nextInt();

}

if(Num == 1)

{

selection="head";

}

else if(Num == 2)

{

selection="tail";

}

System.out.println("\nThe side you chose is " + selection);

int RandomNum = new Random().nextInt(2)+1;

if(RandomNum == 1)

{

side="head";

}

else if(RandomNum == 2)

{

side="tail";

}

System.out.print("\nThe side of coin is " + side);

if(selection==side)

{

result = 1;

}

else

{

result =2;

}

if(coinNum<=33&&coinNum>29)

{

i=8;

}

else if(coinNum<=37&&coinNum>33)

{

i=9;

}

else

{

i=10;

}

switch (result)

{

case 1:

System.out.print("\n\nYou have chosen the right side, please take the coins");

while(c != 1)

{

g++;

System.out.println("\nRound "+g);

System.out.println("\nPlease take coins (1-3): ");

d = input.nextInt();

while(d>3|d<0)

{

System.out.println("\nYou can not take more than 3 coins or less than 1 coin, please take coins again.");

System.out.println("Please take coins (1-3): ");

d = input.nextInt();

}

c-=d;

System.out.println("You took " + d + "coins, there are " + c + "coins left");

e = 4*i - 3;

if(c1)

{

i-=2;

f = c - e;

c-=f;

System.out.println("The user took " + f + " coins, there are "+ c +" coins left.");

}

else if(c>e&&e>1)

{

f = c - e;

c-=f;

i--;

System.out.println("The user took " + f + " coins, there are "+ c +" coins left.");

}

else if(c==e&&e>4)

{

f = new Random().nextInt(3)+1;

c-=f;

i--;

System.out.println("The user took " + f + " coins, there are "+ c +" coins left.");

}

else if(c<=4&&c>1)

{

f=c-1;

g++;

c=1;

System.out.println("The user took " + f + " coins, there are "+ c +" coins left.");

}

else if(c==1)

{

System.out.println("\n1 coin left for user to take.\nCongratulations, you win.");

return;

}

}

System.out.println("\nYou lose, there is only 1 coin left for you to take.");

break;

case 2:

System.out.print("\nSorry, wrong side, please wait...");

while(c != 1)

{

e = 4*i - 3;

if(c1)

{

i-=2;

f = c - e;

c-=f;

g++;

System.out.println("\nRound "+g);

System.out.println("The user took " + f + " coins, there are "+ c +" coins left.");

System.out.println("\nPlease take coins (1-3): ");

d = input.nextInt();

c-=d;

System.out.println("You took " + d + "coins, there are " + c + "coins left");

while(d>3|d<0)

{

System.out.println("\nYou can not take more than 3 coins or less than 1 coin, please take coins again.");

System.out.println("Please take coins (1-3): ");

d = input.nextInt();

}

}

else if(c>e&&e>1)

{

f = c - e;

c-=f;

i--;

g++;

System.out.println("\nRound "+g);

System.out.println("The user took " + f + " coins, there are "+ c +" coins left.");

System.out.println("\nPlease take coins (1-3): ");

d = input.nextInt();

c-=d;

System.out.println("You took " + d + "coins, there are " + c + "coins left");

while(d>3|d<0)

{

System.out.println("\nYou can not take more than 3 coins or less than 1 coin, please take coins again.");

System.out.println("Please take coins (1-3): ");

d = input.nextInt();

}

}

else if(c==33|c==37|c==e&&e>4)

{

f = new Random().nextInt(3)+1;

c-=f;

i--;

g++;

System.out.println("\nRound "+g);

System.out.println("\nThe user took " + f + " coins, there are "+ c +" coins left.");

c-=d;

System.out.println("\nPlease take coins (1-3): ");

d = input.nextInt();

while(d>3|d<0)

{

System.out.println("\nYou can not take more than 3 coins or less than 1 coin, please take coins again.");

System.out.println("Please take coins (1-3): ");

d = input.nextInt();

}

}

else if(c<=4&&c>1)

{

f=c-1;

c=1;

g++;

System.out.println("\nRound "+g);

System.out.println("The user took " + f + " coins, there are "+ c +" coins left.");

System.out.println("\n You lose, there is only 1 coin left for you to take.");

return;

}

System.out.println("\n1 coin left for user to take.\nCongratulations, you win.");

break;

}

}

}

[本帖最后由 pauli 于 2010-2-4 17:59 编辑]

搜索更多相关主题的帖子:

金币 指教 小游戏

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值