hi pls I need someones help. i am not good at programming and i have this subject ; but i am a BSBA major. it is like free section for me and i want to learn it to so i can be flexible. but this project is getting all my soul. We where told to create a game using a C# . a very simple game . then the prof listed games to pick like snake, tictactoe, etc. i picked the slot machine figuring that i already thought that its using timer , and bunch of if statements so i picked it. I am already done with the timer part and pictures part but the if statement is what i have been troubled. i dont know what to do. i thought that its only if pic1.image== pic2.image. /// so on so forth.....
can you help me i want it to be when the picturebox hit lets say 3 banana the amount bet is multiplied.... here i will post my codes as well as a linked to download my project.... i really badly need some1 help.

in the downloadable is forgot to put a \ on the end part of the path.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Resources;
namespace Project_final
{

    public partial class Form1 : Form
    {
        Random r = new Random();
        string path = @"C:\Users\KiDkArDeL\Documents\Visual Studio 2012\Projects\Project_final\Project_final\obj\Debug\pikapika\";
        List<int> RemainNums;
        List<int> RemainNums2;
        List<int> RemainNums3;
        int ARandomNumber;
        int ARandomNumber2;
        int ARandomNumber3;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            if (MessageBox.Show("Only age of 18+ are allowed to play application. Is your age 18+?", "Player Verifyer", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.No)
            {
                MessageBox.Show("APPLICATION DISABLED!", "warning", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                button1.Visible = false;
                label1.Visible = false;
                numericUpDown1.Visible = false;
            }
            else
            {
                this.Enabled = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if (numericUpDown1.Value > 0)
            {
                numericUpDown2.Visible = true;
                label7.Visible = true;
                pic7.Visible = true;
                pic8.Visible = true;
                pic9.Visible = true;
                button1.Enabled = false;
                button1.Hide();
                label1.Hide();
                label3.Text = numericUpDown1.Value.ToString();
                numericUpDown1.Hide();
                label3.Visible = true;
                label2.Visible = true;
                pictureBox2.Visible = true;
                pictureBox6.Visible = true;
                pictureBox7.Visible = true;
                pictureBox8.Visible = true;
                pictureBox9.Visible = true;
                label10.Visible = true;
                label18.Visible = true;
                label12.Visible = true;
                pic6.Visible = true;
                pic5.Visible = true;
                pic4.Visible = true;
                pic3.Visible = true;
                pic2.Visible = true;
                pic1.Visible = true;
                label14.Visible = true;
                label16.Visible = true;
                label5.Visible = true;
                button2.Visible = true;
                label8.Visible = true;
                textBox1.Visible = true;
                radioButton1.Visible = true;
                radioButton2.Visible = true;
                timer1.Start();
                button3.Visible = true;
            }
            else
            {
                MessageBox.Show("You cannot play with no money! Comeback when you have one!", "Too Poor to Play", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.Close();

            }
        }
        private void pictureBox2_Click(object sender, EventArgs e)
        {

        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

            if (numericUpDown2.Value > numericUpDown1.Value)
            {

                MessageBox.Show("Invalid, You don't have enough money.", "NO MONEY", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else if (numericUpDown2.Value == 0)
            {
                MessageBox.Show("Remember. Minimum bet is 1 while maximum is 100", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            else if (numericUpDown2.Value >= 101)
            {
                MessageBox.Show("Remember. Minimum bet is 1 while maximum is 100", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                label3.Text = (numericUpDown1.Value - numericUpDown2.Value).ToString();
                numericUpDown2.Value = 0;
                numericUpDown1.Value = Convert.ToInt32(label3.Text);
                SLOTMECH.Start();
                button2.Enabled = false;

            }

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            textBox1.Text = "1.) Place the amount of bet you want in the box provided. The minimum bet is 1 while the maximum is 100. \r\n" + "2.)Press Bet button to start the roll \r\n" + "3.) Press Stop to stop the roll\r\n" + "4.)ENJOY!\r\n";
        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            textBox1.Text = "1.) Ilagay ang halaga ng pera na iyong gustong itaya sa kahon.1 ang pinakamababang halaga at 100 ang pinakamataas. \r\n" + "2.)Pindutin ang Bet para magsimula \r\n" + "3.)Pindutin ang Stop upang tumigil\r\n" + "4.)MAGSAYA!\r\n";

        }

        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            label18.Text = (DateTime.Now.ToShortDateString() + "   " + DateTime.Now.ToLongTimeString());
        }

        private void numericUpDown2_ValueChanged(object sender, EventArgs e)
        {

        }

        private void numericUpDown2_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void SLOTMECH_Tick(object sender, EventArgs e)
        {
            if (SLOTMECH.Interval > 26)
            {
                SLOTMECH.Interval = SLOTMECH.Interval -25;
            }
            else {
                SLOTMECH.Interval = 1;
            }

            RemainNums = new List<int>();
            RemainNums.AddRange(new int[] { 0,1,2,3,4 });
            RemainNums2 = new List<int>();
            RemainNums2.AddRange(new int[] { 1,4,0,2,3 });
            RemainNums3 = new List<int>();
            RemainNums3.AddRange(new int[] { 3,4,1,2,0 });

            int index = r.Next(0, RemainNums.Count - 1);
            ARandomNumber = RemainNums[index];
            RemainNums.RemoveAt(index);
            ARandomNumber2 = RemainNums2[index];
            RemainNums2.RemoveAt(index);
            pic1.Image = Image.FromFile(path + ARandomNumber + ".jpg");
            index = r.Next(0, RemainNums.Count - 1);
            ARandomNumber = RemainNums[index];
            RemainNums.RemoveAt(index);
            pic4.Image = Image.FromFile(path + ARandomNumber + ".jpg");
            index = r.Next(0, RemainNums.Count - 1);
            ARandomNumber = RemainNums[index];
            RemainNums.RemoveAt(index);
            pic7.Image = Image.FromFile(path + ARandomNumber + ".jpg");
            pic2.Image = Image.FromFile(path + ARandomNumber2 + ".jpg");
            index = r.Next(0, RemainNums2.Count - 1);
            ARandomNumber2 = RemainNums2[index];
            RemainNums2.RemoveAt(index);
            pic5.Image = Image.FromFile(path + ARandomNumber2 + ".jpg");
            index = r.Next(0, RemainNums2.Count - 1);
            ARandomNumber2 = RemainNums2[index];
            RemainNums2.RemoveAt(index);
            pic8.Image = Image.FromFile(path + ARandomNumber2 + ".jpg");
            ARandomNumber3 = RemainNums3[index];
            RemainNums3.RemoveAt(index);
            pic3.Image = Image.FromFile(path + ARandomNumber3 + ".jpg");
            index = r.Next(0, RemainNums3.Count - 1);
            ARandomNumber3 = RemainNums3[index];
            RemainNums3.RemoveAt(index);
            pic6.Image = Image.FromFile(path + ARandomNumber3 + ".jpg");
            index = r.Next(0, RemainNums3.Count - 1);
            ARandomNumber3 = RemainNums3[index];
            RemainNums3.RemoveAt(index);
            pic9.Image = Image.FromFile(path + ARandomNumber3 + ".jpg");         
            }
        private void button3_Click_1(object sender, EventArgs e)
        {
            SLOTMECH.Stop();
            SLOTMECH.Interval = 300;
            button2.Enabled = true;
           //insert if statement here for when pic1 is "0.jpg" and pic2 is 0.jpg and pic3 is 0.jpg bet amount is multipled to 2. pls just give me one if sample and ill figure it out

        }

        private void pictureBox12_Click(object sender, EventArgs e)
        {

        }
    }

}

the link: http://www.4shared.com/zip/1bJpVMk4/project_final_2.html

really appreciate the help.

Recommended Answers

All 5 Replies

how can i delete this thread. or can som1 delete this thread pls. tnx

Sorry, we do not delete posts on request. Please see the DaniWeb Terms of Service statement:

Posts contributed to the community immediately become the property of DaniWeb upon submission. Members may edit their posts for a limited time period immediately after, for the purpose of correcting spelling and grammar mistakes and accidental ommissions. After this initial period expires, posts may only be edited or deleted by DaniWeb team members, and only in cases where they do not comply with our forum rules for the purpose of making said content comply with all rules. As a discussion community, posts contributed by many members work together to form coherent discussions. Altering or deleting individual posts may have consequences that unfairly extend to other members of the community. All members are held responsible for their actions. As always, think before you permanently post something on the public Internet.

ok..... tnx... well to share... i havent still found a way to solve my problem . Instead I used textbox in place of the pictureboxes and numbers instead of pictures. that way it would be easier to do the if statements.... but if anyone is still willing to put what they have in mind pls do so.
(i hope my prof doesnt see this site....)

You could do this if you create your own Image class. Something like:

public class MyImage
{
    string Path { get; private set; }
    Image Image { get; private set; }

    public MyImage (string path, Image image)
    {
        Path = path;
        Image = image;
    }

    public bool Equals(MyImage secondImage)
    {
        if (secondImage == null)
        {
            return false;
        }
        return string.Compare(Path, secondImage.Path) == 0;
    }
}

What this does is compare the paths used by two MyImages and if they are the same returns true;

Here's one way to do it, not fancy but it works. I use an imagelist to hold the images, and 3 labels to display them. I used 6 images, but you can add as many as you want, also you can have as many labels as you want to mimic reels. It will probably work best if all the images and the labels are the same size. I found Paint useful since it uses pixels the same as visual studio.

This is set up to only look at one line, and uses standard slot criterium for determining a winning line, namely winners can only count the same image from the left hand side, for instance apple, apple, lemon, is a winner but lemon, apple, apple is not. Hope this will help you.

First the designer code to show the controls and their properties:

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.label1 = new System.Windows.Forms.Label();
            this.imageList1 = new System.Windows.Forms.ImageList(this.components);
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.button1 = new System.Windows.Forms.Button();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.label1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.label1.Location = new System.Drawing.Point(2, 110);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(73, 68);
            this.label1.TabIndex = 0;
            // 
            // imageList1
            // 
            this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
            this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
            this.imageList1.Images.SetKeyName(0, "Apple.JPG");
            this.imageList1.Images.SetKeyName(1, "Heart.JPG");
            this.imageList1.Images.SetKeyName(2, "Lemon.JPG");
            this.imageList1.Images.SetKeyName(3, "Plum.JPG");
            this.imageList1.Images.SetKeyName(4, "Seven.JPG");
            this.imageList1.Images.SetKeyName(5, "Bell.JPG");
            // 
            // label2
            // 
            this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.label2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.label2.Location = new System.Drawing.Point(81, 110);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(73, 68);
            this.label2.TabIndex = 1;
            // 
            // label3
            // 
            this.label3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.label3.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
            this.label3.Location = new System.Drawing.Point(160, 110);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(73, 68);
            this.label3.TabIndex = 2;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(79, 228);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 3;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // comboBox1
            // 
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Items.AddRange(new object[] {
            ".10",
            ".25",
            ".50",
            "1.00"});
            this.comboBox1.Location = new System.Drawing.Point(2, 12);
            this.comboBox1.MaxDropDownItems = 4;
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(56, 21);
            this.comboBox1.TabIndex = 4;
            this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedValueChanged);
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(115, 13);
            this.textBox1.Name = "textBox1";
            this.textBox1.ReadOnly = true;
            this.textBox1.Size = new System.Drawing.Size(46, 20);
            this.textBox1.TabIndex = 5;
            this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(115, 56);
            this.textBox2.Name = "textBox2";
            this.textBox2.ReadOnly = true;
            this.textBox2.Size = new System.Drawing.Size(46, 20);
            this.textBox2.TabIndex = 6;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 273);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.comboBox1);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.ImageList imageList1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.ComboBox comboBox1;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.TextBox textBox2;

Here's the Form code:

namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        double Stake = 100;
        double Bet = .10;
        Random Rnd = new Random();
        //A list to mirror the controls on the form
        List<Label> Reels = new List<Label>();
        public Form1()
        {
            InitializeComponent();
            comboBox1.SelectedItem = comboBox1.Items[0];
            textBox1.Text = Stake.ToString();
            Reels = this.Controls.OfType<Label>().ToList<Label>();
            Reels = Reels.OrderBy(l => l.Name).ToList<Label>();
        }

        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
                bool Test = double.TryParse(comboBox1.Items[comboBox1.SelectedIndex].ToString(), out Bet);
                textBox2.Text = Bet.ToString("N2");
        }

        private void button1_Click(object sender, EventArgs e)
        {
        if (Stake > Bet)
        {
            Stake -= Bet;
            textBox1.Text = Stake.ToString();
            button1.Enabled = false;
            comboBox1.Enabled = false;
            int max = Rnd.Next(10);
            for (int i = 0; i < max; i++)
            {
                foreach (Label Reel in Reels)
                {
                    Reel.Tag = Rnd.Next(0,imageList1.Images.Count-1);
                    Reel.Image = imageList1.Images[int.Parse(Reel.Tag.ToString())];
                    this.Refresh();
                }

                Thread.Sleep(350);
            }
            Stake += CheckWinner();
            textBox1.Text = Stake.ToString();
            comboBox1.Enabled = true;
            button1.Enabled = true;
        }
        }
        private double CheckWinner()
        {
            int Multiplier = 0;            
            for (int i = 0; i < Reels.Count-1; i++)
            {
                if (Reels[i].Tag.ToString() == Reels[i+1].Tag.ToString())
                {
                    Multiplier = (i + 1)* 2;
                }
                else
                    break;
            }

            return Bet * Multiplier;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            textBox1.Text = String.Format("{0:N2}",textBox1.Text);
        }

    }
}
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.