VC# ExpressでWindows Mobile開発 (1)に参加した

七誌さん主催の11/20に行われた「VC# ExpressでWindows Mobile開発 (1)」に参加しました
「勉強会」というものに一度参加してみたいと思っていて、これはと思い参加を決めました


なかなか全員初対面というところに入っていくので、会場に入るまえは緊張していましたが
みなさん優しい方で安心しました
まあみんな大人だし、あたりまですかね


いろんな人と一緒に土曜の昼間に仕事と関係なくコードをゴリゴリ書くというのはとても新鮮でした
IT業界に勤めていても趣味がプログラミングの人には以外に会えないのが不満でしたが
やっぱりこういう場に参加して自分から知り合って行くのが一番だと思いました
プログラミングは素晴らしい!!!


七誌さんはじめ、参加者皆さん、ありがとうございます!


これからも色々、外に出て行こうっと。


なんかの参考になればと思い
とりあえず私があの日作ったアプリケーションのソースをまとめて↓に掲載しました

// Form1.cs のソース
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.IO;

namespace wmee
{
    public class Status
    {
        public int AsCount;
        public string[] Qs = new string[4];
        public string[] As = new string[4];
        public int Score = 0;

        public Status()
        {
            Clear();
        }

        public void Clear()
        {
            AsCount = 0;
            ClearArray(Qs);
            ClearArray(As);
        }

        public void ClearArray(string[] ss)
        {
            for (int i = 0; i < ss.Length; i++)
            {
                ss[i] = " " + "_";
            }
        }

        public void SetA(string s)
        {
            if (AsCount >= As.Length) return;
            As[AsCount] = " " + s;
            AsCount++;
        }

        public string ToInline(string[] ss)
        {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < ss.Length; i++)
            {

                b.Append(ss[i]);
            }
            return b.ToString();
        }

        public bool IsMatch(int idx)
        {
            if (idx < 0 || idx >= Qs.Length) return false;
            return Qs[idx].Trim() == As[idx].Trim();
        }

        public override string ToString()
        {
            return ToInline(Qs) + " | " + ToInline(As) + " | Score: " + Score.ToString();
        }
    }

    public partial class Form1 : Form
    {
        public Form1()
        {
            Text = "アプリ";
            Size = new Size(240, 320);
            MinimizeBox = false;
            SuspendLayout();
            AutoScaleDimensions = new SizeF(96, 96);
            // emobile S21HT だと AutoScaleMode.Inheritにしないと画面サイズに調整されなかった
//            AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
            AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
            Menu = new MainMenu();
            InitializeComponent();       
            ResumeLayout(false);
        }

        enum State { Presentaion, Input }

        private Button[] bs = new Button[9];
        private Color orgBackColor;
        private Button prevBtn;
        private Label StateLabel;

        private Random rnd;

        private State ThisState;
        private int TickCount;
        private List<string> Qs;
        private List<string> As;
        private Status Status;

        private void InitializeComponent()
        {
            Button b;
            int idx;
            int size;
            int x, y, w, h;

            size = Width / 3;
            for (int r = 0; r < 3; r++)
            {
                for (int c = 0; c < 3; c++)
                {
                    b = new Button();
                    x = c * size;
                    y = r * size;
                    w = size;
                    h = size;
                    b.Bounds = new Rectangle(x, y, w, h);
                    b.Click += new EventHandler(button_Click);

                    idx = c + r * 3;
                    b.Text = "" + idx;

                    bs[idx] = b;
                }
            }

            prevBtn = bs[0];
            orgBackColor = prevBtn.BackColor;

            StateLabel = new Label();
            StateLabel.Left = 0;
            StateLabel.Top = size * 3;
            StateLabel.Width = Width;
            StateLabel.Text = "";

            foreach (Button bb in bs)
            {
                Controls.Add(bb);
            }
            Controls.Add(StateLabel);

            rnd = new Random(DateTime.Now.Millisecond);
            ThisState = Form1.State.Presentaion;
            TickCount = 0;
            Qs = new List<string>();
            As = new List<string>();
            Status = new Status();

            PrepareTimer();
            timer.Enabled = true;
        }

        void button_Click(object sender, EventArgs e)
        {
            Button b = sender as Button;
            As.Add(b.Text);

            Status.SetA(" " + b.Text);
            StateLabel.Text = Status.ToString();
        }

        private Timer timer;

        private void PrepareTimer()
        {
            timer = new Timer();
            timer.Interval = 700;
            timer.Tick += new EventHandler(timer_Tick);
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            prevBtn.BackColor = orgBackColor;

            if (TickCount >= 4)
            {
                if (ThisState == State.Presentaion)
                {
                    // to input
                    ThisState = State.Input;
                }
                else
                {
                    // to presentation
                    ThisState = State.Presentaion;
                    Qs.Clear();
                    As.Clear();
                    Status.Clear();
                }
                TickCount = 0;
            }

            if (ThisState == State.Presentaion)
            {
                int idx;
                idx = rnd.Next(9);
                prevBtn = bs[idx];
                prevBtn.BackColor = Color.GreenYellow;

                Status.Qs[TickCount] = " " + " " + idx.ToString();

                Qs.Add(idx.ToString());
            }
            else
            {
                if (Status.IsMatch(TickCount))
                {
                    Status.As[TickCount] = " ○";
                    Status.Score++;
                }
                else
                {
                    Status.As[TickCount] = " ×";
                }
            }

            StateLabel.Text = Status.ToString();
            TickCount++;
        }
    }

}