//需要使用的命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace GameSelector_Win {

//正文 created by season of yanhua
public partial class Form1 : Form {

    //System.Timers.Timer TimingFly = new System.Timers.Timer();
    
    public Random r = new Random();
    public static string path = "列表.ini";
    public static bool ExaminationFileExist = File.Exists("列表.ini");
    public string[] context = File.ReadAllLines(path, Encoding.GetEncoding("GB2312"));
    //为txt文件中的元素建立数组
    public List<object> list = new List<object>();

    public Form1() {
        InitializeComponent();
    }

    public void ExamFile() {
        if (ExaminationFileExist) return;
        else File.Create("列表.ini");
    
    }

    private void button1_Click(object sender, EventArgs e) {

        //TimingFly.Interval = 100;
        //TimingFly.Enabled = true;
        //TimingFly.Start();

        if (button1.Text == "开始") {
            button1.Text = "停止";
            timer1.Start();
        }
        else {
            button1.Text = "开始";
            timer1.Stop();
            for (var i = 0; i < context.Length; i++) {
                if (textBox1.Text == "→  " + list[i]) textBox1.Text = list[i].ToString();
                else throw new Exception();
            }
        }

    }

    private void timer1_Tick(object sender, EventArgs e) {

        int i = r.Next(0, context.Length);
        textBox1.Text = "→  " + list[i];

    }

    //程序启动时自动执行
    private void Form1_Load(object sender, EventArgs e) {

        for (var i = 0; i < context.Length; i++) {
            listBox1.Items.Add(context[i]);
        }
        
        textBox1.ReadOnly = true;
        textBox1.Text = "抽取结果将会显示在这里";
        foreach (var result in listBox1.Items) {
            list.Add(result);
        }

    }

    private void label1_Click(object sender, EventArgs e) {

    }

    private void listBox1_SelectedIndexChanged(object sender, EventArgs e) {

    }

    private void textBox1_TextChanged(object sender, EventArgs e) {

    }
}

}