2015年4月8日 星期三

[2015][Homework]Team01 - Hw06

以下為類別Form1的程式碼

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 homework6;

namespace Homework6
{
    public partial class Form1 : Form
    {                                
        public Form1()
        {
            InitializeComponent();
        }

        public int[] symbolIndex = new int[4] { 1, 2, 3, 4 };
        public int[] cardCharacterIndex = new int[13] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
        public int operater = 1;
        public string Arrangement = "";
        Random indexGenerater = new Random();
        public string Symbol()
        {
            switch (operater)
            {
                case 1:
                    return "\u2663";  //梅花                  
                case 2:
                    return "\u2666";  //方塊                  
                case 3:
                    return "\u2665";  //愛心            
                default:
                    return "\u2660";  //黑桃            
            }
        }
        public string CardCharacter()
        {
            switch (operater)
            {
                case 1:
                    return "A";
                case 11:
                    return "J";
                case 12:
                    return "Q";
                case 13:
                    return "K";
                default:
                    return Convert.ToString(operater);
            }
        }
        public void ArrangeBySymbol()
        {
            for (int i = 0; i <= 3; i++)
            {
                for (int j = 0; j <= 12; j++)
                {
                    operater = symbolIndex[i];
                    Arrangement += Symbol();
                    operater = cardCharacterIndex[j];
                    Arrangement += CardCharacter();
                }
                Arrangement += "\n";
            }
        }
        public void ArrangeByRandom()
        {
            int i = 1;
            for (; i <= 52; i++)
            {
                operater = symbolIndex[indexGenerater.Next(4)];
                Arrangement += Symbol();
                operater = cardCharacterIndex[indexGenerater.Next(13)];
                Arrangement += CardCharacter();
                if (i % 13 == 0)
                {
                    Arrangement += "\n";
                }
            }
        }
        public void ArrangeByValue()
        {
            for (int j = 0; j <= 12; j++)
            {
                for (int i = 0; i <= 3; i++)
                {
                    operater = symbolIndex[i];
                    Arrangement += Symbol();
                    operater = cardCharacterIndex[j];
                    Arrangement += CardCharacter();
                    if ((4 * j + i + 1) % 13 == 0 && !(i == 0 && j == 0))
                    {
                        Arrangement += "\n";
                    }
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            switch(comboBox1.SelectedIndex)
            {
                case 0:
                    ArrangeBySymbol();
                    textBox1.AppendText("ComboBox 按花色排列 已被選定");
                    MessageBox.Show(Arrangement);
                    break;
                case 1:
                    ArrangeByRandom();
                    textBox1.AppendText("ComboBox 亂數洗牌 已被選定");
                    MessageBox.Show(Arrangement);
                    break;
                case 2:
                    ArrangeByValue();
                    textBox1.AppendText("ComboBox 按點數大小排列 已被選定");
                    MessageBox.Show(Arrangement);
                    break;
            }
            Arrangement = "";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if(checkBox1.Checked)
            {
                ArrangeBySymbol();
                textBox1.AppendText("CheckBox 按花色排列 已被選定");
                MessageBox.Show(Arrangement);
            }
            if (checkBox2.Checked)
            {
                ArrangeByRandom();
                textBox1.AppendText("CheckBox 亂數洗牌 已被選定");
                MessageBox.Show(Arrangement);
            }
            if (checkBox3.Checked)
            {
                ArrangeByValue();
                textBox1.AppendText("CheckBox 按點數大小排列 已被選定");
                MessageBox.Show(Arrangement);
            }
            Arrangement = "";
        }
    }
}

沒有留言:

張貼留言