如何将我的骰子游戏中每一轮的分数相加?

时间:2018-11-19 16:46:03

标签: python

我创建了这个骰子游戏。用户说他们不想再次滚动后,如何计算每个回合的分数?谢谢!!!

    public static byte[] GetZipArchive(List<InMemoryFile> files)
        {
            byte[] archiveFile;
            using (var archiveStream = new MemoryStream())
            {
                using (var archive = new ZipArchive(archiveStream, ZipArchiveMode.Create, true))
                {
                    foreach (var file in files)
                    {
                        var zipArchiveEntry = archive.CreateEntry(file.FileName, CompressionLevel.Fastest);
                        using (var zipStream = zipArchiveEntry.Open())
                            zipStream.Write(file.Content, 0, file.Content.Length);
                    }
                }

                archiveFile = archiveStream.ToArray();
            }

            return archiveFile;
        }

public class InMemoryFile
    {
        public string FileName { get; set; }
        public byte[] Content { get; set; }
    }

2 个答案:

答案 0 :(得分:2)

只需将总和存储在变量中,然后打印出来,就像这样:

var test = {
   value: 1,
   children: {
    value: 10,
    children:{
      value: 2,
      children: {}
    }
   }
}
function findMaxValue(obj) {
  if (Object.keys(obj.children).length === 0) {
    return obj.value;
  }
  return Math.max(obj.value, findMaxValue(obj.children))
}
console.log(findMaxValue(test))

答案 1 :(得分:0)

只需将分数相加即可。然后在他们决定不再滚动时打印总和。

import colorama
colorama.init()

print_in_green = "\x1b[32m"
print_in_red = "\x1b[31m"
print_in_blue = "\x1b[36m"
print_in_pink = "\x1b[35m"
print_default = "\x1b[0m"

import random
min = 1
max = 6
sum = 0
game_response = input("Would you like to roll your dice (y/n)? ")

if game_response == "y":
    roll_again = "yes"

    while roll_again == "yes" or roll_again == "y":
        print("Rolling the dices...")
        print("The values are:")
        dice1 = random.randint(min, max)
        dice2 = random.randint(min, max)
        print(print_in_pink)
        print(int(dice1))
        print(int(dice2))
        print(print_default)
        score = (int(dice1) + int(dice2))
        sum = sum + score
        roll_again = input("Your score for this round is " + str(score) + ". Roll the dices again (y/n)? ")
else:
    print("Ok!")

print(sum)