Thursday, June 23, 2011

How to create a Simple Game ?

 
 '===========================================================
'====   Programmed by:     Er. Ranjeet khune
'====   Email:             ddkhune@gmail.com
'==== 
'==== 
'====   Note:               Send me feedback regarding
'====                       this application
'====
'==== 
'==== 
'===========================================================

#region Using directives;
using System;

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


#endregion
namespace Ranjeet_MindBlowing_Game
{
    public partial class Game : Form
    {
        public Game()
        {
            InitializeComponent();
        }
        int bankroll;
        int[] final = new int[4];
        SoundPlayer spinSound = new SoundPlayer();
        SoundPlayer noWin = new SoundPlayer();
        SoundPlayer win = new SoundPlayer();
        SoundPlayer oraju = new SoundPlayer();
        PictureBox[] choices = new PictureBox[7];
        Random myRandom = new Random();
        const int lemon = 1;
        const int cherry = 2;
        const int orange = 3;
        const int plum = 4;
        const int bell = 5;
        const int star = 6;

        private int NewIndex()
        {
            return (myRandom.Next(6) + 1);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("You ended up with " + Convert.ToString(bankroll) + " dollars.", "Game Over", MessageBoxButtons.OK);
            this.Close();
        }

        private void picChoice1_Click(object sender, EventArgs e)
        {

        }

        private void btnSpin_Click(object sender, EventArgs e)
        {
            if (bankroll == 0)
            {
                MessageBox.Show("Out of Cash!", "Game Over", MessageBoxButtons.OK);
                this.Close();
            }
            bankroll -= 1;
            //******* friend this is coding of Start timers
            timSpin.Enabled = true;
            timStop1.Enabled = true;
            timStop2.Enabled = true;
            timStop3.Enabled = true;
            grpGame.Text = "Spinning ...";
        }

        private void timStop1_Tick(object sender, EventArgs e)
        {
            //  friend    please this is coding of Stop spinning of first display
            timStop1.Enabled = false;
            final[1] = NewIndex();
            pic1.Image = choices[final[1]].Image;
            pic1.Refresh();
        }

        private void timStop2_Tick(object sender, EventArgs e)
        {
            // friend this is coding of Stop spinning of first display
            timStop1.Enabled = false;
            final[1] = NewIndex();
            pic1.Image = choices[final[1]].Image;
            pic1.Refresh();
        }

        private void timStop3_Tick(object sender, EventArgs e)
        {
            int winnings = 0;
            // friend this is coding of Stop spinning of third display
            timStop3.Enabled = false;
            final[3] = NewIndex();
            pic3.Image = choices[final[3]].Image;
            pic3.Refresh();
            timSpin.Enabled = false;
            //  friend khune this is coding of Check for winnings
            if (final[1] == cherry)
            {
                winnings = 2;
                if (final[2] == cherry)
                {
                    winnings = 4;
                    if (final[3] == cherry)
                    {
                        winnings = 6;
                    }
                }
            }
            else if (final[1] == orange && final[2] == orange && final[3] == orange)
            {
                winnings = 10;
            }
            else if (final[1] == plum && final[2] == plum && final[3] == plum)
            {
                winnings = 20;
            }
            else if (final[1] == bell && final[2] == bell && final[3] == bell)
            {
                winnings = 30;
            }
            else if (final[1] == star && final[2] == star && final[3] == star)
            {
                winnings = 50;
            }
            bankroll += winnings;
            if (winnings == 50)
            {
                grpGame.Text = "oraju! Won $50";
                oraju.Play();
            }
            else if (winnings > 0)
            {
                grpGame.Text = "Won $" + Convert.ToString(winnings);
                win.Play();
            }
            else
            {
                grpGame.Text = "Sorry";
                noWin.Play();
            }
            grpGame.Text += " - Bankroll $" + Convert.ToString(bankroll);
        }

        private void timSpin_Tick(object sender, EventArgs e)
        {
            //  friend this is coding of Randomly display pictures
            //  friend  thsis  is coding of play spin sound
            spinSound.Play();
            if (timStop1.Enabled)
            {
                pic1.Image = choices[NewIndex()].Image;
            }
            if (timStop2.Enabled)
            {
                pic2.Image = choices[NewIndex()].Image;
            }
            if (timStop3.Enabled)
            {
                pic3.Image = choices[NewIndex()].Image;
            }
        }

        private void Game_Load(object sender, EventArgs e)
        {
            bankroll = 100; // Start with 100 dollars
            // load images
            picChoice1.Image = Image.FromFile(Application.StartupPath + "\\lemon.wmf");
            picChoice2.Image = Image.FromFile(Application.StartupPath + "\\cherry.wmf");
           picChoice3.Image = Image.FromFile(Application.StartupPath + "\\orange.wmf");
            picChoice4.Image = Image.FromFile(Application.StartupPath + "\\plum.wmf");
            picChoice1.Image = Image.FromFile(Application.StartupPath + "\\ra.wmf");
            picChoice5.Image = Image.FromFile(Application.StartupPath + "\\bell.wmf");
            picChoice6.Image = Image.FromFile(Application.StartupPath + "\\star.wmf");

            //picChoice8.Image = Image.FromFile(Application.StartupPath + "\\ranjeet.wmf");
            //picChoice9.Image = Image.FromFile(Application.StartupPath + "\\ais.wmf");
            //picChoice10.Image = Image.FromFile(Application.StartupPath + "\\rose.wmf");




            // image choices
            choices[1] = picChoice1;
            choices[2] = picChoice2;
            choices[3] = picChoice3;
            choices[4] = picChoice4;
            choices[5] = picChoice5;
            choices[6] = picChoice6;
            ////choices[7] = picChoice7;
            ////choices[8] = picChoice8;
            //choices[9] = picChoice9;
            //choices[10] = picChoice10;


            // Put random pictures in display
            pic1.Image = choices[NewIndex()].Image;
            pic2.Image = choices[NewIndex()].Image;
            pic3.Image = choices[NewIndex()].Image;
            spinSound.SoundLocation = Application.StartupPath + "\\spin.wav";
          
            noWin.SoundLocation = Application.StartupPath + "\\dilwale.wav";
            //noWin.SoundLocation = Application.StartupPath + "\\uhoh.wav";
          
        win.SoundLocation = Application.StartupPath + "\\BOLE MORA KANGNA_0_converted.wav";
          //win.SoundLocation = Application.StartupPath + "\\tada.wav";
             oraju.SoundLocation = Application.StartupPath + "\\oraju.wav";
            btnSpin.Focus();
        }

      
    }
}

No comments:

Post a Comment