本文介绍了指数数组的边界之外 !的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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;
using System.IO;
using System.Reflection;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        bool khoa;
        bool check = new bool();

        Button[] Radombutton = new Button[7];
        Image[] RadomImage = new Image[7];
        int ClicksMouse;
        int[] Checks = new int[3];
        int[] List1 = new int[7];
        int[] List2 = new int[7];
        private void Form2_Load(object sender, EventArgs e)
        {
            Radombutton[1] = button1;
            Radombutton[2] = button2;
            Radombutton[3] = button3;
            Radombutton[4] = button4;
            Radombutton[5] = button5;
            Radombutton[6] = button6;
            NewGame();
        }
        public void LoadRadombutton()
        {
            for (int i = 1; i <= 6; i++)
            {
                Radombutton[i].Visible = true;
            }
        }

        public void Image()
        {

            RadomImage[List1[1]] = WindowsFormsApplication1.Properties.Resources.Q;
            RadomImage[List1[2]] = WindowsFormsApplication1.Properties.Resources.Q;
            List2[List1[1]] = 1;
            List2[List1[2]] = 1;

            RadomImage[List1[3]] = WindowsFormsApplication1.Properties.Resources.U;
            RadomImage[List1[4]] = WindowsFormsApplication1.Properties.Resources.U;
            List2[List1[3]] = 2;
            List2[List1[4]] = 2;

            RadomImage[List1[5]] = WindowsFormsApplication1.Properties.Resources.Y;
            RadomImage[List1[6]] = WindowsFormsApplication1.Properties.Resources.Y;
            List2[List1[5]] = 3;
            List2[List1[6]] = 3;


        }
        public void NewGame()
        {
            Random rnd = new Random();
            for (int i = 1; i <= 6; i++)
            {
                // RandomButton is a collection, right?
                Radombutton[i].Image = null;
            }
            for (int i = 1; i <= 6; i++)
            {
                bool checkSuccessful = true;
                int randomNumber = 6 * rnd.Next() + 1;
                // Kiểm tra trùng này !
                for (int j = 1; j < i - 1; j++)
                {
                    // Also List1 is a collection?
                    if (randomNumber == List1[j])
                    {
                        // Never use "GOTO"! use a variable to check.
                        checkSuccessful = false;
                        // Not nice but this is the only short solution I found for.
                        break;
                    }
                }
                // Check if the inner-loop-check was not failing.
                if (checkSuccessful)
                {
                    List1[i] = randomNumber;
                }
            }
            Image();
            LoadRadombutton();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            if (ClicksMouse == 1)
                return;

            if (List2[Checks[1]] == List2[Checks[2]])
            {
                Radombutton[Checks[2]].Visible = false;
                Radombutton[Checks[1]].Visible = false;
                int i = 0;
                bool Match = true;
                for (i = 1; i <= 6; i++)
                {
                    if (Radombutton[i].Visible == true)
                    {
                        Match = false;
                        break; // TODO: might not be correct. Was : Exit For
                    }
                }
                if (Match == true)
                {
                    MessageBox.Show(" ho ho ho");
                }
            }
            else
            {
                Radombutton[Checks[1]].Image = null;
                Radombutton[Checks[2]].Image = null;
            }
            Checks[1] = 0;
            Checks[2] = 0;
            ClicksMouse = 0;
        }

        private void button6_Click(object sender, EventArgs e)
        {

            if (khoa == false)
                return;

            if (timer1.Enabled == true)
                return;

            if (Checks[1] == 6)
                return;

            ClicksMouse += 1;
            Checks[ClicksMouse] = 6;
            button6.Image = RadomImage[6];

            if (ClicksMouse == 2)
                timer1.Enabled = true;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (khoa == false)
                return;

            if (timer1.Enabled == true)
                return;

            if (Checks[1] == 5)
                return;

            ClicksMouse += 1;
            Checks[ClicksMouse] = 5;
            button5.Image = RadomImage[5];


            if (ClicksMouse == 2)
                timer1.Enabled = true;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (khoa == false)
                return;

            if (timer1.Enabled == true)
                return;

            if (Checks[1] == 4)
                return;

            ClicksMouse += 1;
            Checks[ClicksMouse] = 4;
            button4.Image = RadomImage[4];
            if (ClicksMouse == 2)
                timer1.Enabled = true;
        }

        private void button3_Click(object sender, EventArgs e)
        {

            if (khoa == false)
                return;

            if (timer1.Enabled == true)
                return;

            if (Checks[1] == 3)
                return;

            ClicksMouse += 1;
            Checks[ClicksMouse] = 3;
            button3.Image = RadomImage[3];
            if (ClicksMouse == 2)
                timer1.Enabled = true;


        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (khoa == false)
                return;
            if (timer1.Enabled == true)
                return;
            if (Checks[1] == 2)
            {
                return;
            }
            ClicksMouse += 1;
            Checks[ClicksMouse] = 2;
          button2.Image = RadomImage[2];
            if (ClicksMouse == 2)
            {
               timer1.Enabled = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (khoa == false)
                return;
            if (timer1.Enabled == true)
                return;
            if (Checks[1] == 1)
                return;
            ClicksMouse += 1;
            Checks[ClicksMouse] = 1;
            button1.Image = RadomImage[1];
            if (ClicksMouse == 2)
                timer1.Enabled = true;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            khoa = true;
            NewGame();
           button7.Enabled = false;
           button7.Text = " Th?y th? nào :) ";
           check = true;
        }
    }
}




请帮我Pr0s!
错误:索引超出数组的范围!
在此:WindowsFormsApplication1.Properties.Resources.Q;
T_T帮帮我!



这是我的专案!
http://www.mediafire.com/?9bhl42t6wug27a4 [ ^ ]




Pls help me Pr0s !
Error :Index was outside the bounds of the array !
In this :WindowsFormsApplication1.Properties.Resources.Q;
T_T help me pls !



This is my Project !
http://www.mediafire.com/?9bhl42t6wug27a4[^]

推荐答案



这篇关于指数数组的边界之外 !的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 15:53