edgareatis 0 Newbie Poster

Ok this will be a easy to make game for pros but for new users it will improve your understanding of c#.

Ok start my setting up your GUI(Generall User Interface) by selecting a trackerbar, 2 buttons, a label and a trackerbar. Place the trackerbar at the top of your form with a button beside it. On the trackerbar set the maximum to 99 and minimum to 1. Rename button1 to set.

Input this code into the button along with a intiger.

int ChanceOfGoal = 50;
        private void button1_Click(object sender, EventArgs e)
        {
            ChanceOfGoal = trackBar1.Value;
        }

Now you have setup your "difficulty" selector you can go on to code button2.

Random rnd = new Random();
            if (rnd.Next(1, 100) > ChanceOfGoal)
            {
                label1.Text = "Goal";
                listbox1.Items.Add("You Scored");
            }
            else
            {
                Label1.Text = "Saved";
                listbox1.Items.Add("Your shot was saved");
            }

Now click on the listbox and select dock to bottom from the properties window, then put the button2 just above that.
Now put your label1 in the middel of your form and try it out.
Thanks for reading, happy coding.

FULL CODE

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int ChanceOfGoal = 50;
        private void button1_Click(object sender, EventArgs e)
        {
            ChanceOfGoal = trackBar1.Value;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Random rnd = new Random();
            if (rnd.Next(1, 100) > ChanceOfGoal)
            {
                label1.Text = "Goal";
                listbox1.Items.Add("You Scored");
            }
            else
            {
                Label1.Text = "Saved";
                listbox1.Items.Add("Your shot was saved");
            }
        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.