954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Turorial: Making a penalty shootout game

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");
            }
        }
    }
}
edgareatis
Newbie Poster
9 posts since May 2010
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: