خرید بک لینک
Hello, currently I am working on the project in college. My task is to do ball going around the roulette wheel. I've done most important parts and now I have to down ComboBox with numbers 1-36 and if person wants to play the game, then he has to chose number from the list between 1-36 in comboBox and click Spin. If the ball stops at number that he has put his bet on then he wins and messagebox pops up with something like "Congratulations! You won!". Below is my code for Roulette wheel game.

Code:

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

namespace Lucky_7
{
    public partial class frmRoulette : Form
    {
        private int speed;

        // This piece of code is responsible for creating private int speed

        public frmRoulette()
        {
            InitializeComponent();
        }

        private void btnPlay_Click(object sender, EventArgs e)
        {
            int[] x = { 183, 201, 217, 235, 252, 266, 278, 287, 293, 295, 294, 293, 288, 276, 264, 248, 232, 213, 195, 176, 157, 139, 123, 108, 94, 89, 82, 77, 76, 74, 81, 88, 100, 115, 129, 147, 163 };
            int[] y = { 68, 68, 75, 80, 88, 100, 112, 127, 146, 162, 180, 197, 211, 226, 241, 251, 259, 262, 267, 269, 267, 260, 251, 240, 229, 212, 199, 182, 166, 147, 133, 116, 102, 87, 80, 74, 69 };
            int speed = 30;

            int pos = int.Parse(txtPos.Text);
            //This line of code converts the string representation of a number to its 32-bit signed integer equivalent

            picBall.Location = new Point(x[pos], y[pos]);

            // This piece of code is reponsible for creating feature that will check if coordinates are correct
        }

        Random rnd = new Random(36);
        //Generates random seed of numbers between 0-36
       

        private void btnRoll_Click(object sender, EventArgs e)
        {
            int[] x = { 183, 201, 217, 235, 252, 266, 278, 287, 293, 295, 294, 293, 288, 276, 264, 248, 232, 213, 195, 176, 157, 139, 123, 108, 94, 89, 82, 77, 76, 74, 81, 88, 100, 115, 129, 147, 163 };
            int[] y = { 68, 68, 75, 80, 88, 100, 112, 127, 146, 162, 180, 197, 211, 226, 241, 251, 259, 262, 267, 269, 267, 260, 251, 240, 229, 212, 199, 182, 166, 147, 133, 116, 102, 87, 80, 74, 69 };

            // These are the coordinates which are essential to make the ball go around the circle

            int stop = rnd.Next(1, 36);

            // This short piece of code generates random number generator between 1-36

            for (int loopCount = 0; loopCount < 5; loopCount++)

                // This is responsible for creating a loop so ball will go around exactly five times
            {
               

                for (int i = 0; i < x.Length; i++)

                    // This short piece of code represents the total numbers  of elements in all the dimensions of the array
                {
                   
                    picBall.Location = new Point(x[i], y[i]);
                    this.Refresh();
                    int speed = 30;
                    Thread.Sleep(speed);

                    speed = speed + 250;

                    // this piece of code is responsible for speed of the ball so every lap ball will go faster

                    if (i == stop && loopCount == 4)
                    {
                        break;
                    }
                        // This piece of code is responsible for stopping a ball at random position
                }
            }
        }

        private void picBall_Click(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}

Attached Thumbnails
Click image for larger version. 

Name:	roulette.jpg 
Views:	N/A 
Size:	38.1 KB 
ID:	17666  

برچسب: نویسنده: آیلین رضوانی تاريخ: چهارشنبه 22 آذر 1396 ساعت: 18:28

صفحه بندی