gpt4 book ai didi

ada - 成员值的静态引用 - Ada

转载 作者:行者123 更新时间:2023-12-04 06:43:31 30 4
gpt4 key购买 nike

你好
我正在尝试我在 Ada 中创建单人骰子游戏的第一个程序。
但面临着保持球员得分的问题。
目标:每个玩家有 10 个回合,如果 2 次掷骰总数为 7,则获得 10 分
问题:每次总分被重置并且 10 没有被添加到当前分数中。
Total_Score 是要显示的最终分数。
请帮忙!!!任何帮助表示赞赏!!!

谢谢 :)

我的代码如下:

with Ada.Numerics.Discrete_Random,Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;

procedure Game is

subtype Die is Integer range 1 .. 6;
subtype Dice is Integer range 2*Die'First .. 2*Die'Last;
package Random_Die is new Ada.Numerics.Discrete_Random (Die);
use Random_Die;

type MY_TYPE is range 1..10;
package My_Int_IO is new Ada.Text_IO.Integer_IO(MY_TYPE);
use My_Int_IO;

My_Range : MY_TYPE;
G : Generator;
Roll : Dice; -- Total Rolled
Roll_One : INTEGER; -- Roll 1
Roll_Two : INTEGER; -- Roll 2
Total_Score : INTEGER; -- Current Score
Choice : INTEGER; -- Game Choice
Total_Roll : INTEGER; -- Total Rolled Returned
Score : INTEGER; -- Static Score count

function Roll_Dice return INTEGER is
begin
-- Start the generator in a unique state in each run
Reset (G);
Total_Score := 0;
-- Roll a pair of dice
Roll_One := Random(G);
Roll_Two := Random(G);
Put(Roll_One,3);
Put(Roll_Two,3);
Roll := Roll_One + Roll_Two;
return Roll;
end Roll_Dice;

begin
Total_Score := 0;
for Index in MY_TYPE loop
Put("Roll Dice: Press 1 To Exit: Press 2 ");
New_Line;
Get(Item => Choice);
if Choice = 1 then
Total_Roll := Roll_Dice;
if Total_Roll = 7 then
Put("Current Score : ");
Put(Total_Score , 3);
Total_Score := Total_Score + 10;
New_Line;
Put("Your Score : ");
Put(Total_Score, 3);
else
New_Line;
Put("Sorry! you do not score");
end if;
elsif Choice = 2 then
Put("Score ");
Put(Total_Score, 3);
exit when Choice = 2;
else
Put("Wrong Choice! You lost one chance! Try Again");
end if;
end loop;
New_Line;
Put("Total Score for this game: ");
Put(Total_Score, 3);
end Game;

最佳答案

Every time total score gets reset and 10 does not get added to current score.



那是因为你设置了 Total_ScoreRoll_Dice 中归零功能:
Total_Score := 0;

10 加入 Total_Score :
Total_Score := Total_Score + 10;

但在随后的滚动中,总数重置为零。

关于ada - 成员值的静态引用 - Ada,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3954380/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com