加入了:
1. 庄家可以使用道具
2.血量下限的完善
3.当对自己射击,无论是否中枪,都继续自己的回合。当对对方射击无论是否命中,都结束回合
import java.util.Random;
import java.util.Scanner;
public class SWE23070 {
private static final int MAX_HEALTH = 4;
private static int playerHealth = MAX_HEALTH;
private static int dealerHealth = MAX_HEALTH;
private static boolean isPlayerTurn = true;
private static int dealerHasCigarette = 0;
private static int dealerHasBeer = 0;
private static int dealerHasHandcuffs = 0;
private static int dealerHasSaw = 0;
private static int dealerHasMagnifyingGlass = 0;
private static int playerHasCigarette = 0;
private static int playerHasBeer = 0;
private static int playerHasHandcuffs = 0;
private static int playerHasSaw = 0;
private static int playerHasMagnifyingGlass = 0;
private static int playerSawCharge = 1;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
System.out.println("======欢迎来到恶魔轮盘赌游戏=====");
System.out.println("规则如下:");
System.out.println("每回合每人获得2个道具\n每回合子弹随机,由玩家先开始");
System.out.println("当对自己射击,无论是否中枪,都继续自己的回合\n当对对方射击无论是否命中,都结束回合");
System.out.println("道具及其功能如下:");
System.out.println("1、knife:下一发子弹伤害翻倍");
System.out.println("2、Cigarette:回一滴血:");
System.out.println("3、MagnifyingGlass:看到下一发子弹是什么");
System.out.println("4、Beer:退掉一发子弹");
System.out.println("5、Handcuffs:禁止对方行动");
while (playerHealth > 0 && dealerHealth > 0) {
if (isPlayerTurn) {
System.out.println("\n你的回合开始!");
useItems();
playerTurn(scanner, random);
} else {
System.out.println("\n庄家回合开始!");
useItem();
dealerTurn(random);
}
if(playerHealth > 0 && dealerHealth > 0)lifeForce();
}
scanner.close();
}
private static void playerTurn(Scanner scanner, Random random) {
boolean isBullet = random.nextBoolean();
isPlayerTurn = !isPlayerTurn;
while (playerHasCigarette>0&&playerHealth<4) {//香烟
System.out.print("请问要使用香烟吗?使用:1,不使用:0");
int isC = scanner.nextInt();
if(isC==1){
playerHasCigarette--;
playerHealth++;
lifeForce();
}else{
break;
}
}
if (playerHasMagnifyingGlass>0) {
System.out.print("请问要使用放大镜吗?使用:1,不使用:0");
int isfdj = scanner.nextInt();
if(isfdj==1){
playerHasMagnifyingGlass--;
System.out.println("你使用了放大镜,查看到下一发子弹是 " + (isBullet ? "实弹" : "空弹"));
}
}
while(playerHasBeer>0)
{
System.out.print("请问要使用啤酒吗?使用:1,不使用:0");
int isBeer = scanner.nextInt();
if(isBeer==1){
playerHasBeer--;
isBullet = random.nextBoolean();
if (playerHasMagnifyingGlass>0) {
System.out.print("请问要使用放大镜吗?使用:1,不使用:0");
int isfdj = scanner.nextInt();
if(isfdj==1){
playerHasMagnifyingGlass--;
System.out.println("你使用了放大镜,查看到下一发子弹是 " + (isBullet ? "实弹" : "空弹"));
}
}
}else{
break;
}
}
if(playerHasSaw>0)//手锯
{
System.out.print("请问要使用手锯吗?使用:1,不使用:0");
int isSAW = scanner.nextInt();
if(isSAW==1){
playerHasSaw--;
playerSawCharge = 2 ; // 手锯效果
}else{
playerSawCharge = 1;
}
}
System.out.print("选择攻击对象 (1-玩家, 2-庄家): ");
int target = scanner.nextInt();
if (target == 1) {
if (isBullet) {
playerHealth-= playerSawCharge;
System.out.println("你朝自己开了一枪,造成了 " + playerSawCharge + " 点伤害。");
System.out.println("你可以再进行一个回合");
isPlayerTurn = true;
if (playerHealth == 0) {
lifeForce();
System.out.println("你死了。");
deathSequence();
}
}
else {
System.out.println("虚弹没有对自己造成伤害,并且你可以再次进行一个回合");
isPlayerTurn = true;
}
}
else if (target == 2) {
if (isBullet) {
dealerHealth -= playerSawCharge;
System.out.println("你朝庄家开了一枪,造成了 " + playerSawCharge + " 点伤害。");
if (dealerHealth <= 0) {
lifeForce();
System.out.println("庄家死了。");
victorySequence();
}
}
else {
System.out.println("虚弹没有造成伤害。");
}
}
if(isPlayerTurn == false){
if(playerHasHandcuffs>0 &&playerHealth > 0 && dealerHealth > 0)
{
System.out.print("请问要使用手铐吗?使用:1,不使用:0");
int isHand = scanner.nextInt();
if(isHand==1)
{
isPlayerTurn = true;
playerHasHandcuffs--;
}
else
{
isPlayerTurn = false;
}
}
}
playerSawCharge = 1;
}
private static void dealerTurn(Random random) {
boolean isBullet = random.nextBoolean();
isPlayerTurn = !isPlayerTurn;
while (dealerHasCigarette>0 && dealerHealth<4) //香烟
{
dealerHasCigarette--;
dealerHealth++;
System.out.println("庄家使用香烟恢复一格生命值");
lifeForce();
}
if(dealerHasMagnifyingGlass>0){
dealerHasMagnifyingGlass--;
System.out.println("庄家使用放大镜查看下一发子弹");
if(isBullet){
if(dealerHasSaw>0){
dealerHasSaw--;
System.out.println("庄家使用手锯将枪管锯短,伤害*2");
playerSawCharge = 2 ; // 手锯效果
}
}
else{
if(dealerHasBeer>0){
dealerHasBeer--;
System.out.println("庄家使用啤酒进行退弹");
isBullet = random.nextBoolean();
}
else{//空弹庄家向自己开枪可以多进行一个回合
System.out.println("庄家朝自己开了一枪,空弹没有造成伤害并且庄家继续进行下一回合。");
isPlayerTurn = false;
}
}
}
System.out.println(isBullet ? "枪里是实弹" : "枪里是空弹");
if (isBullet) {
playerHealth-=playerSawCharge;
System.out.println("庄家朝你开了一枪,造成了"+playerSawCharge+"点伤害。");
if (playerHealth <= 0) {
lifeForce();
deathSequence();
}
} else {
System.out.println("没有造成伤害。");
}
if(isPlayerTurn==true)
{
if(dealerHasHandcuffs>0&&playerHealth > 0 && dealerHealth > 0)
{
System.out.println("庄家使用手铐,你被跳过一个回合");
isPlayerTurn = false;
dealerHasHandcuffs--;
}
else
{
isPlayerTurn = true;
}
}
playerSawCharge = 1;
}
private static void useItems() {
// 每回合开始时抽取两个道具
Random random = new Random();
int item1 = random.nextInt(5);
int item2 = random.nextInt(5);
switch (item1) {
case 0:
playerHasCigarette++;
System.out.println("你抽取的第一个道具是:香烟 ");
break;
case 1:
playerHasBeer ++;
System.out.println("你抽取的第一个道具是:啤酒 ");
break;
case 2:
playerHasHandcuffs ++;
System.out.println("你抽取的第一个道具是:手铐 ");
break;
case 3:
playerHasSaw ++;
System.out.println("你抽取的第一个道具是:锯子 ");
break;
case 4:
playerHasMagnifyingGlass ++;
System.out.println("你抽取的第一个道具是:放大镜 ");
break;
}
switch (item2) {
case 0:
playerHasCigarette ++;
System.out.println("你抽取的第二个道具是:香烟 ");
break;
case 1:
playerHasBeer++;
System.out.println("你抽取的第二个道具是:啤酒 ");
break;
case 2:
playerHasHandcuffs ++;
System.out.println("你抽取的第二个道具是:手铐 ");
break;
case 3:
playerHasSaw ++;
System.out.println("你抽取的第二个道具是:锯子 ");
break;
case 4:
playerHasMagnifyingGlass++;
System.out.println("你抽取的第二个道具是:放大镜 ");
break;
}
System.out.println("你现在拥有的道具为:香烟 *"+playerHasCigarette+" 啤酒*"+playerHasBeer+" 手铐*"+playerHasHandcuffs+" 锯子*"+playerHasSaw+" 放大镜*"+playerHasMagnifyingGlass);
}
private static void useItem() {
// 每回合开始时庄家抽取两个道具
Random random = new Random();
int item1 = random.nextInt(5);
int item2 = random.nextInt(5);
switch (item1) {
case 0:
dealerHasCigarette++;
System.out.println("庄家抽取的第一个道具是:香烟 ");
break;
case 1:
dealerHasBeer ++;
System.out.println("庄家抽取的第一个道具是:啤酒 ");
break;
case 2:
dealerHasHandcuffs ++;
System.out.println("庄家抽取的第一个道具是:手铐 ");
break;
case 3:
dealerHasSaw ++;
System.out.println("庄家抽取的第一个道具是:锯子 ");
break;
case 4:
dealerHasMagnifyingGlass ++;
System.out.println("庄家抽取的第一个道具是:放大镜 ");
break;
}
switch (item2) {
case 0:
dealerHasCigarette ++;
System.out.println("庄家抽取的第二个道具是:香烟 ");
break;
case 1:
dealerHasBeer++;
System.out.println("庄家抽取的第二个道具是:啤酒 ");
break;
case 2:
dealerHasHandcuffs ++;
System.out.println("庄家抽取的第二个道具是:手铐 ");
break;
case 3:
dealerHasSaw ++;
System.out.println("庄家抽取的第二个道具是:锯子 ");
break;
case 4:
dealerHasMagnifyingGlass++;
System.out.println("庄家抽取的第二个道具是:放大镜 ");
break;
}
System.out.println("庄家现在拥有的道具为:香烟 *"+dealerHasCigarette+" 啤酒*"+dealerHasBeer+" 手铐*"+dealerHasHandcuffs+" 锯子*"+dealerHasSaw+" 放大镜*"+dealerHasMagnifyingGlass);
}
private static void victorySequence() {
System.out.println("你赢了!你获得了一个装满钱的箱子!");
}
private static void deathSequence() {
System.out.println("你死了... ");
}
private static void lifeForce() {
if(playerHealth<0)playerHealth=0;
if(dealerHealth<0)dealerHealth=0;
System.out.println("你剩余的血量为:"+playerHealth);
System.out.println("庄家剩余的血量为:"+dealerHealth);
}
}
标签:int,System,private,轮盘,恶魔,3.0,println,static,out From: https://blog.csdn.net/2301_79885215/article/details/142864136