I';我正在尝试用java创建一个21点游戏。(准备编写IDE)如何将11变成像I';我想在下面做什么?

I';我正在尝试用java创建一个21点游戏。(准备编写IDE)如何将11变成像I';我想在下面做什么?,java,Java,这是我的全部代码。如果总数超过21,我似乎找不到一种方法来挑出a并把它们变成1。 /********************************************************************************************************************************************************************* Name: BlackJack_Mason_Haddock Description

这是我的全部代码。如果总数超过21,我似乎找不到一种方法来挑出a并把它们变成1。 /*********************************************************************************************************************************************************************

Name:
BlackJack_Mason_Haddock

Description:
The famous known game "BlackJack" created in Java.

History:
Nov 16 2016 / M. Haddock / Created: Code skeleton
Nov 17 2016 / M. Haddock / Created: Random number generator from 1 to 10



*********************************************************************************************************************************************************************/
import java.awt.*;              // Used in graphics
import java.awt.event.*;        // For mouse stuff
import java.applet.*;           // For mouse/music stuff
import java.io.*;               // For input and output
import java.util.*;             // For date and time stuff
import java.lang.*;             // For point stuff

import hsa.Console;             // Special console input output commands



class BlackJack_Mason_Haddock
{
    public static void Title (Console c)
    {

    }


    public static void Game (Console c)
    {
        int givenNumber[] = new int [52];   // Makes an empty array of integers of 52. Used for 52 cards in the deck
        int i;                              // Used for any for loops of drawing cards
        int total = 0;                      // Sets a base number for the total number of card scores
        char next;                          // Used to catch the first letter of the string "string"
        String string;                      // Used for a string given by the user
        int ace = 11;                       // Setting aces to 11
        int ace2 = 1;                       // Setting aces to 1 if 11 is over 21


        for (i = 0 ; i < 1 ; i++)  // Runs through the code below twice, once at a time.
        {
            givenNumber [i] = (int) (Math.random () * (11 - 1)) + 1;    // Picks a random number from 1 to 10
            c.print (givenNumber [i] + " ");                            // Outputs the random number picked above, adds a space for the second number
            total = total + givenNumber [i];

            if ((total < 22) && (givenNumber [i] == 1))
            {
                givenNumber [i] = ace;
                total = total + 10;

            }

            if ((total > 21) && (givenNumber [i] == ace))
            {
                givenNumber [i] = ace2;
            }

            givenNumber [i] = (int) (Math.random () * (11 - 1)) + 1;    // Picks a random number from 1 to 10
            c.print (givenNumber [i] + " ");                            // Outputs the random number picked above, adds a space for the second number
            total = total + givenNumber [i];
            for (i = 0 ; i < 51 ; i++)
            {
                if ((total < 22) && (givenNumber [i] == 1))
                {
                    givenNumber [i] = ace;
                    total = total + 10;

                }
            }
            for (i = 0 ; i < 51 ; i++)
            {

                if ((total > 21) && (givenNumber [i] == ace))
                {
                    givenNumber [i] = ace2;
                }
            }
            if (total == 21)

                {
                    c.print ("BlackJack! You Win!");
                    return;
                }


            do
            {

                c.println ("");
                c.print ("Will you hit or stand?");
                c.println ("");

                string = c.readString ();
                next = string.charAt (0);

                c.println ("");


                if ((total < 21) && (next == 'S') || (next == 's'))
                {
                    c.print ("You stand at " + total);
                    return;
                }
                else if ((total < 21) && (next == 'H') || (next == 'h'))
                {

                    givenNumber [i] = (int) (Math.random () * (11 - 1)) + 1;
                    c.print (givenNumber [i] + " ");
                    for (i = 0 ; i < 51 ; i++)
                    {
                        if ((total > 22) && (givenNumber [i] == 11))
                        {
                            total = total - 10;

                        }

                    }
                    total = total + givenNumber [i];
                    c.println ("");
                    c.print ("Total " + total + " ");

                    if (total == 21)
                    {
                        c.print ("You Win!");
                        return;

                    }
                    if (total > 21)
                    {
                        c.println ("");
                        c.print ("You bust!");
                        return;
                    }
                } //End of the if statement
            } //End of the for statement

            while (true);

        }

    }



    public static void main (String[] args)
    {
        Console c = new Console (32, 167, "BlackJack");
        Title (c);
        Game (c);
    }
}
名称:
二十一点黑线鳕
说明:
著名的游戏“21点”是用Java创建的。
历史:
2016年11月16日/M.黑线鳕/已创建:代码框架
2016年11月17日/M.黑线鳕/已创建:从1到10的随机数生成器
*********************************************************************************************************************************************************************/
导入java.awt.*;//用于制图
导入java.awt.event.*;//老鼠的东西
导入java.applet.*;//鼠标/音乐的东西
导入java.io.*;//用于输入和输出
导入java.util.*;//日期和时间的东西
导入java.lang.*;//为了点东西
导入hsa.Console;//特殊控制台输入输出命令
21点、梅森、黑线鳕
{
公共静态无效标题(控制台c)
{
}
公共静态无效游戏(控制台c)
{
int givenNumber[]=new int[52];//生成一个52的整数空数组。用于牌组中的52张牌
int i;//用于绘图卡的任何for循环
int total=0;//设置卡分数总数的基数
char next;//用于捕获字符串“string”的第一个字母
String;//用于用户给定的字符串
int ace=11;//将aces设置为11
int ace2=1;//如果11大于21,则将aces设置为1
for(i=0;i<1;i++)//一次运行两次下面的代码。
{
givenNumber[i]=(int)(Math.random()*(11-1))+1;//从1到10选择一个随机数
c、 print(givenNumber[i]+“”);//输出上面选择的随机数,为第二个数字添加一个空格
总计=总计+给定编号[i];
如果((总数<22)和&(给定编号[i]==1))
{
给定编号[i]=ace;
总计=总计+10;
}
如果((总计>21)和&(给定编号[i]==ace))
{
给定编号[i]=ace2;
}
givenNumber[i]=(int)(Math.random()*(11-1))+1;//从1到10选择一个随机数
c、 print(givenNumber[i]+“”);//输出上面选择的随机数,为第二个数字添加一个空格
总计=总计+给定编号[i];
对于(i=0;i<51;i++)
{
如果((总数<22)和&(给定编号[i]==1))
{
给定编号[i]=ace;
总计=总计+10;
}
}
对于(i=0;i<51;i++)
{
如果((总计>21)和&(给定编号[i]==ace))
{
给定编号[i]=ace2;
}
}
如果(总数=21)
{
c、 打印(“21点!你赢了!”);
返回;
}
做
{
c、 println(“”);
c、 打印(“你会打还是站?”);
c、 println(“”);
string=c.readString();
next=string.charAt(0);
c、 println(“”);
如果((总数<21)和&(下一个='S')| |(下一个='S'))
{
c、 打印(“您站在”+总计);
返回;
}
如果((总数<21)和&(下一个='H')| |(下一个='H'))
{
givenNumber[i]=(int)(Math.random()*(11-1))+1;
c、 打印(给定编号[i]+“”);
对于(i=0;i<51;i++)
{
如果((总计>22)和&(给定编号[i]==11))
{
总数=总数-10;
}
}
总计=总计+给定编号[i];
c、 println(“”);
c、 打印(“总计”+总计+”);
如果(总数=21)
{
c、 打印(“你赢了!”);
返回;
}
如果(总数>21)
{
c、 println(“”);
c、 打印(“你的胸脯!”);
返回;
}
}//if语句的结尾
}//for语句的结尾
虽然(正确);
}
}
公共静态void main(字符串[]args)
{
控制台c=新控制台(32167,“21点”);
标题(c);
游戏(c);
}
}

简单的回答是,不要将11改为1,只需包含如何添加11的逻辑,特别是因为您已经有了if语句。值为11并不意味着必须加11


编辑:事实上,考虑到你正在尝试重新创建21点,没有理由在你的游戏中同时使用11和1,因为aces是唯一具有这两种值的牌。您可以很容易地从代码中删除11个

,正如Tosh所说,不必从总数中减去,而是得到一段类似

if (draws an ace) {
    if (total + 11 > 21) {
        total++;
    else {
        total += 11;
    }
}

那里有很多代码,但是(
for(i=0;i<1;i++)
for-start只循环一次,而不是您的评论声明的两次