Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
C#
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!";
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?

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


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
Posted
Updated 2-Sep-17 16:55pm

1 solution

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.
C#
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...
C#
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.
 
Share this answer
 
Comments
BillWoodruff 3-Sep-17 15:53pm    
What's the OP going to do when you are not available to write code for him ?
Graeme_Grant 3-Sep-17 18:26pm    
No, I am not going to write his code for him, just showing him how to structure his data. He still needs to write the game logic himself. Part of the journey of learning... ;)
RCEditor 5-Sep-17 0:37am    
Thank you Graeme_Grant I would not want it any other way but to write the logic myself so I appreciate the comment indicating we are on the same page. I am sorry if I offended anyone in this post I thought this was intended to be a collaborative environment so thought I would ask if anyone wanted to help add new features to this little dice game, and I made suggestions. It has been a good five years since I worked directly manipulating code until this little game and I was surprised I was able to make sense of as much of it as I did by watching others to see how I could adjust what they made to fit for this little game I wanted to put together to have again.

So I know some things but willing to learn as much as I can, so that is why I posted here. If that is not the intention of the site I apologize to those who may think I would like others to write the code for me. That is why I shared the whole code for others to reference or use in exchange for the information to see where I was lacking, having not already written it in to the game on my own. I know what I wanted but reached out for help to gain insight on how best to accomplish it with the help of others.

Anyway, Thanks!

Been distracted with life's responsibilities to post last couple days. I will re- post when I have an update on the program.
Graeme_Grant 5-Sep-17 0:50am    
It is all good. Bill is only touching on the fact that there are a lot of lazy devs out there that try to use this platform as a method to get others to do their work, class homework & assignments even!

"Quick Answers" is just that, when you are stuck and looking for pointers and Google search has no answers for you. This is the context of my replies.

Above, I give you structure and show you how to access it. It is incomplete and may not be exactly how you want to do it, only a reference point and brain fodder to work from. The rest is up to you.

Once you complete the project, and you are looking for ways to expand it, post it as an article, and maybe include a "Future Goals" section of what is in the pipeline and what other could suggest to expand it.

Good luck with your project.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900