如何在C#中为我的骰子游戏添加一个得分保持系统 [英] How do I add a score keeping system to my dice game in C#

查看:109
本文介绍了如何在C#中为我的骰子游戏添加一个得分保持系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



这是我在社区的第二篇帖子,感谢您帮助解决我的问题。



我有一个很好的骰子游戏项目,但只在每次滚动后在一个句子中写入的文本框中显示点值。

Hello All!

This is my 2nd Post to the Community and thanks for looking into helping with my Question.

I have a dice game project that works well but only displays point values to a text box written in a sentence after each roll.

if (oneThroughSix)
                lbl_displayResults.Text = "One through Six is worth 2000 points!";
            else if (allDoubles)
                lbl_displayResults.Text = "All Doubles are worth 1500 points!";
            else if (threeOnes)
                lbl_displayResults.Text = "Three Ones are worth 1000 points!";

等等...



我想让节目跟踪自己的分数,根据每次掷骰后选择的骰子通过复选框(我在之前的帖子中询问过)重新计算选中每个复选框后总计的是什么,但只有在按下滚动按钮后才将分数发布到gameTotal(当前在我的项目中未定义 - 应该是int还是字符串?)之类的内容。我确实有一个'ResetResults()'变量(下面),每次调用btn_RollDice函数时都会执行该变量。在这种情况下,我认为可能会妨碍我。真的吗。如果是这样,如何最好地纠正它?



and so on...

I would like to have the program keep track of its own score based on what dice have been chosen after each roll via checkboxes (which I have asked about in my previous post) that recalculate what is totaled after each checkbox is selected, but only post the score to the something like gameTotal (which is not currently defined in my project -should it be an int or a string?) after the roll button has been pressed. I do have a 'ResetResults()' variable (below) that is performed each time the btn_RollDice function is called. Which I think may be getting in the way in this case. Is that true. And, if so How best to correct it?

private void ResetResults()
        {
            for (int i = 0; i < diceResults.Length; i++)
                diceResults[i] = 0;
        }





问题2:我还想添加一个单独的streakCounter(尚未在项目中定义)作为示例要使用的变量只是保持连续多少卷的计数器,直到调用变量'aBust'来显示GameOver文本。有任何想法,请告诉我。



再次感谢!



我尝试了什么:



我还没有尝试过多,因为我仍然想弄清楚如何在得分保持之前将'checkBoxes'连接到骰子这里提出的系统甚至可以融入我的游戏中。只是向社区提出这个问题,因为我可以看到这是我的下一个障碍,使这个游戏功能性和参与,因为我记得几年前与朋友一起玩。我想从多个角度或想法途径接近最终用于游戏的内容,以便尽快获得完整功能的最终结果。希望很快能收到社区的消息!



谢谢!



RC



Question 2: I would also like to add a separate streakCounter (not yet defined in project) as an example variable to use that will just keep a counter of how many rolls in a row have happened until variable 'aBust' is called which displays the GameOver text. Any ideas, please let me know.

Thanks Again!

What I have tried:

I have not yet tried much as I am still trying to figure out how to even link the 'checkBoxes' to the dice before the Score keeping system proposed herein can even become incorporated into my game. Just posing this question to the community as I can see it being my next hurdle into making this game as functional and involved as I remember when playing it with friends years ago. I figure approaching what is ultimately intended for the game from multiple angles or avenues of thought to get to the end result of full functionality sooner than later. Hope to hear from the community Soon!

Thanks!

RC

推荐答案

就像我对上一组问题的回答一样:如何使用C#将Visual Studio 2010中的复选框链接到图像/随机结果? [ ^ ],您可以在课堂上保存与分数相关的玩家相关数据。如果有多轮,那么你将有一个Round类。

Like my answer to the previous set of questions here: How do I link a checkbox to an image/random result in visual studio 2010 using C# .....[^], you would hold the player related data, like the score, in a class. If there are multiple rounds, then you would have a Round class.
public class Round
{
    public int Score { get; set; }
    public List<Die> Dice { get; } = new List<Die>
    {
       new Die(),
       new Die(),
       new Die(),
       new Die(),
       new Die(),
       new Die()
    };
}

public class Player
{
    public string Name { get; set; }
    public List<Round> Rounds { get; set; } = new List<Round>();
    public int TotalScore { get { return Rounds.Sum(x => x.Score); } }
    public Round CurrentRound { get { return Rounds.LastOrDefault(); } }
}



然后使用...


Then to use...

public readonly List<Player> Players = new List<Player>();

Players.Add(new Player { Name = "Fred });

Player currentPlayer = Players[0];

' add a new round
currentPlayer.Rounds.Add(new Round ());

' current round
Round currentRound = currentPlayer.CurrentRound;

' current score
int currentPlayerScore = currentPlayer.TotalScore;



现在你可以拥有一个多人游戏。


Now you can have a multi-player game.


这篇关于如何在C#中为我的骰子游戏添加一个得分保持系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆