I wish to program a Skateboard Trick Generator for me and some friends and I can't seem to get the List to show on the Label and randomly pick a trick.
private void btnClick_Click(object sender, EventArgs e)
{
//new random
static Random rnd = new Random();
string[] words = { "Kick Flip", "Heel Flip", "Tre Flip" };
lblTrick.Show(words[rnd.Next(0, words.Length)];
If anyone could help I would love that.
Thanks.
CodePudding user response:
Looks like you are confusing a few different language implementations.
For help on anything .Net, you should consult the MS Docs first, try this for Random.Next.
In .Net we assign the content of a Label using the .Text property:
private void btnClick_Click(object sender, EventArgs e)
{
//new random
static Random rnd = new Random();
string[] words = { "Kick Flip", "Heel Flip", "Tre Flip" };
lblTrick.Text = words[rnd.Next(words.Length)];
}
CodePudding user response:
This is the new code that works with Stances, Rotations, and Tricks. I also added buttons to hide the rotations because some tricks are way too hard with it.
{
//new random
Random rnd = new Random();
//tricks, stances, rotations
string[] rotation = { "BS 180", "FS 180", "BS 360", "FS 360" };
string[] stance = { "Goofy", "Regular", "Nollie", "Fakie" };
string[] tricks = { "Kick Flip", "Heel Flip", "Tre Flip", "Varial Flip", "Varial Heel", "Lazer Flip", "Ollie", "BS-Shuv", "FS-Shuv", "3-Shuv", "FS 3-Shuv", "Hard Flip", "Inward Heel", "Double Flip", "Double Heel", "" };
//random display of tricks and stance
lblTrick.Text = (tricks[rnd.Next(0, tricks.Length - 1)]);
lblStance.Text = (stance[rnd.Next(0, stance.Length - 1)]);
lblRotation.Text = (rotation[rnd.Next(0, rotation.Length - 1)]);'
Thank you for help, now I will finish this and get my friends to give it a go:)
