public ClickDeKaishiState(EPuzzleWindow window, WindowState previousState, WindowState nextState, string text)
            : base(window)
        {
            if (null == nextState) throw new ArgumentNullException();
            if (null == previousState) throw new ArgumentNullException();

            PreviousStates.Add(previousState);
            NextStates.Add(nextState);
            var label = new EigoTestLabelItem()
            {
                Color = Color.Gray,
            //				Text = "クリックまたは打鍵で開始します",
                Text = text,
                Location = new Point(0, 0),
                Size = new SizeF(DrawingObjectRoot.Width, DrawingObjectRoot.Height),
                Font = EPuzzleFonts.クリックで開始します,
            };
            Items.Add(label);

            Action0 += (sender, e) =>
            {
                Window.State = NextState;
                Window.ChumonResult = new ChumonResult(window.EPuzzleData.CurrentUserInfo);
            };
            Action3 += (sender, e) =>
            {
                Window.State = PreviousState;
            };
        }
        public WindowState(EPuzzleWindow window)
        {
            Window = window;
            NextStates = new List<WindowState>(); //new EigoTestStateCollection(this);
            PreviousStates = new List<WindowState>();
            DrawingPreparers = new List<DrawingPreparer>();

            _drawingObjectRoot = new DrawingObjectContainer()
            {
                Width = 1024,
                Height = 768,
                Position = DrawingObjectPosition.Relative,
                Color = Color.FromArgb(0xff, 0x00, 0x00, 0x80),
            };
            _drawingObjectRoot.SetState(this);

            MoveUp += (sender, e) =>
            {
                if (null == CurrentItem)
                {
                    CorrectCurrentItem();
                    return;
                }
                MoveCursor(x => CurrentItem.BorderTop > x.BorderTop, x => CurrentItem.BorderLeft == x.BorderLeft);
            };
            MoveDown += (sender, e) =>
            {
                if (null == CurrentItem)
                {
                    CorrectCurrentItem();
                    return;
                }
                MoveCursor(x => CurrentItem.BorderTop < x.BorderTop, x => CurrentItem.BorderLeft == x.BorderLeft);
            };
            MoveLeft += (sender, e) =>
            {
                if (null == CurrentItem)
                {
                    CorrectCurrentItem();
                    return;
                }
                MoveCursor(x => CurrentItem.BorderLeft > x.BorderLeft, x => CurrentItem.BorderTop == x.BorderTop);
            };
            MoveRight += (sender, e) =>
            {
                if (null == CurrentItem)
                {
                    CorrectCurrentItem();
                    return;
                }
                MoveCursor(x => CurrentItem.BorderLeft < x.BorderLeft, x => CurrentItem.BorderTop == x.BorderTop);
            };
            Action0 += (sender, e) =>
            {
                if (null == CurrentItem) return;
                CurrentItem.OnClick(new MouseEventInfo(MouseButtons.Left));
            };
        }
 public FadeoutState(EPuzzleWindow window, int milliseconds, WindowState previousState, WindowState nextState, Color color)
     : base(window)
 {
     if (null == previousState) throw new ArgumentNullException("previousState");
     if (null == nextState) throw new ArgumentNullException("nextState");
     PreviousState = previousState;
     NextState = nextState;
     _milliseconds = milliseconds;
     _color0 = color;
 }
        public AnkimonState(EPuzzleWindow window, Ankimon ankimon)
            : base(window)
        {
            Ankimon = ankimon;
            _shomonStateHelper = new ShomonStateHelper(this);
            _ankimonBox = new AnkimonBox()
            {
                MarginLeft = 100f, MarginTop = 100f, MarginRight = 100f,
            };
            Items.Add(_ankimonBox);

            foreach (var container in ankimon.AnkimonItems.Select(ankimonItem =>
                {
                    var ankimonRowContainer = new AnkimonRowContainer()
                    {
                        MarginLeft = 10f, MarginTop = 0f,
                        AnkimonItem = ankimonItem,
                    };
                    ankimonRowContainer.Label.Text = ankimonItem.Name;
                    var collection = ankimonRowContainer.WordCardContainer.Items;
                    foreach (var word in ankimonItem.MondaiWords)
                    {
                        collection.Add(new WordCard(word));
                    }
                    ((DrawingObjectContainer.DrawingObjectCollection)collection).CollectionChanged += Handler0;
                    return ankimonRowContainer;
                }))
            {
                _ankimonBox.Items.Add(container);
            }
            int i = 0;
            do
            {
                Shuffle();
                if (i++ > 100)
                {
                    throw new ApplicationException("指定された回数を超えても問題がシャッフルできません: " + Ankimon.Id);
                }

            } while (正解判定());

            Action0 += (sender, e) =>
            {
                _subState.Action0((WindowState)sender);
            };
            Action1 += (sender, e) =>
            {
                _subState.Action1((WindowState)sender);
            };
            Action3 += (sender, e) =>
            {
                Window.State = new PauseState(Window, this);
            };
            CurrentItem = GetAllItems().First(x => x is WordCard);
        }
 //        private EigoTestLabelItem _answerBox;
 /*
 public event PropertyChangedEventHandler PropertyChanged;
 private void NotifyPropertyChanged(string propertyName)
 {
     if (null == PropertyChanged) return;
     PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
 }
 */
 public ShomonStateTyping(EPuzzleWindow window, Shomon shomon)
     : base(window, shomon)
 {
     // Back Space
     Action1 += (sender, e) =>
     {
         var answerBox = GetAnswerBox();
         if ("" == answerBox.Text) return;
         answerBox.Text = answerBox.Text.Substring(0, answerBox.Text.Length - 1);
     };
     UpdateItemsToBeDrawn();
 }
 public SampleState(EPuzzleWindow window, string text)
     : base(window)
 {
     var label = new EigoTestLabelItem()
     {
         Color = Color.Gray,
         Text = text,
         Location = new Point(0, 0),
         Size = new SizeF(DrawingObjectRoot.Width, DrawingObjectRoot.Height),
         Font = EPuzzleFonts.クリックで開始します,
     };
     label.Click += (sender, e) =>
     {
         Window.State = NextState;
     };
     Items.Add(label);
 }
        public InformationState(EPuzzleWindow window, WindowState parentState, string text)
            : base(window)
        {
            _parentState = parentState;
            var container = new DrawingObjectContainer()
            {
                Position = DrawingObjectPosition.Absolute,
                Width = DrawingObjectRoot.Width / 2f,
                Height = DrawingObjectRoot.Height / 2f,
            //				BackColor =
            };
            Items.Add(container);

            _textLabel = new EigoTestLabelItem()
            {
                Text = text,
            //				Width = container.Width,
                Height = container.Height * 0.8f,
                BackColor = EPuzzleColors.ColorAlpha01,
            };
            container.Items.Add(_textLabel);

            var okButton = new EigoTestButtonItem()
            {
                Text = "OK", Name = "ok",
            //				Width = 100,
                Height = 60,
            };
            container.Items.Add(okButton);
            container.水平方向に中央揃え();
            container.垂直方向に中央揃え();

            Action0 += (sender, e) =>
            {
                if (null == CurrentItem) return;
                if ("ok" == CurrentItem.Name)
                {
                    Window.State = parentState;
                }
            };
        }
		public ShomonStateHard(EPuzzleWindow window, Shomon shomon) : base(window, shomon)
		{
			((ObservableCollection<EigoTestDrawingObject>)_kaitouBox.Items).CollectionChanged += (sender, e) => 
			{
				if (e.Action != NotifyCollectionChangedAction.Add) return;
				foreach (var wordCard in e.NewItems.OfType<WordCard>())
				{
					wordCard.LettersThatAreShown = LettersThatAreShown.All;
				}
			};
			window.PropertyChanged += (sender, e) => 
			{
				if ("InputDevice" != e.PropertyName) return;
				foreach (var wordCard in _sentakuBox.Items.OfType<WordCard>())
				{
					if (object.ReferenceEquals(wordCard, CurrentItem)) continue;
					HideLettersOnCard(wordCard);
				}
				Invalidate();
			};
			_sentakuBox.AnyPropertyOfAnyChildChanged += (sender, e) => 
			{
				if ("IsClickable" != e.PropertyName) return;
				foreach (var wordCard in _sentakuBox.Items.OfType<WordCard>())
				{
					if (wordCard.IsClickable)
					{
						HideLettersOnCard(wordCard);
					}
					else
					{
						wordCard.LettersThatAreShown = LettersThatAreShown.All;
					}
				}
			};
			
			SetNullToCurrentItemWhenStoredItemBecomeInvalid = true;
		}
 public StartGameState(EPuzzleWindow window)
     : this(window, new string[0])
 {
 }
        public ShomonStateBase(EPuzzleWindow window, Shomon shomon)
            : base(window)
        {
            if (null == shomon) throw new ArgumentNullException();
            Shomon = shomon;
            _shomonStateHelper = new ShomonStateHelper(this);

            NeedToPlaySounds += (sender, e) =>
            {
            /*
                foreach (var sound in e.Sounds)
                {
                    Window.EPuzzleData.CurrentUserInfo.SoundPlayer.Play(sound.FileName);
                }
                */
                Window.EPuzzleData.CurrentUserInfo.SoundPlayer.Play(e.Sounds.Select(x => x.FileName), true);
            };
            Action0 += (sender, e) =>
            {
                if (null == CurrentItem) return;
                switch (CurrentItem.Name)
                {
                    case "info" :
                    {
                        _shomonStateHelper.ShowInformation();
                        break;
                    }
                    case "back" :
                    {
                        BackToChumonMenu();
                        break;
                    }
                    case "hajimekara" :
                    {
                        WindowState.Chumonを開始する((Chumon)Shomon.Parent, Window.WindowStateWhichHasStartedChumon);
                        break;
                    }
                    case "pause" :
                    {
                        Pause();
                        break;
                    }
                    case "showCorrectAnswer" :
                    {
                        _userHasSeenCorrectAnswer = true;
                        var text = string.Join(Environment.NewLine, shomon.CorrectAnswers.Select(x => string.Format(@"{0}", x.Text)).ToArray());
                        Window.State = new InformationState(Window, this, text);
                        break;
                    }
                    case "playSound" :
                    {
                        PlaySounds();
                        break;
                    }
                }
            };
            Action3 += (sender, e) =>
            {
                Pause();
            };
            Action4 += (sender, e) =>
            {
                PlaySounds();
            };
        }
        public PauseState(EPuzzleWindow window, WindowState previousState)
            : base(window)
        {
            if (null == previousState) throw new ArgumentNullException();
            PreviousState = previousState;

            var gameButton = new EigoTestButtonItem()
            {
                Text = "ゲームに戻る",
            };
            gameButton.Click += (sender, e) =>
            {
                ゲームに戻る();
            };

            var menuButton = new EigoTestButtonItem()
            {
                Text = "メニューに戻る",
            };
            menuButton.Click += (sender, e) =>
            {
                BackToChumonMenu();
            };
            var titleButton = new EigoTestButtonItem()
            {
                Text = "タイトルに戻る",
            };
            titleButton.Click += (sender, e) =>
            {
                MoveToStartGameState();
            };

            var desktopButton = new EigoTestButtonItem()
            {
                Text = "ディスクトップに戻る",
             			};
             			desktopButton.Click += (sender, e) =>
             			{
             				Window.QuitGame(this);
             			};

            float y = 0f;
             			foreach (var button in new [] { gameButton, menuButton, titleButton, desktopButton })
             			{
             				button.Top = y;
             				button.Height = 50f;
                button.MarginBottom = 20f;
            //				button.PaddingTop = button.PaddingBottom = 10f;

                button.Color = Color.White;
                button.BackColor = Color.FromArgb(255, 80, 80, 80);
                button.BorderLine = true;
                button.Font = EPuzzleFonts.PauseStateButton;

                y += button.OuterHeight;
             			}

            var container = new DrawingObjectContainer()
            {
                MarginLeft = 300,
                MarginRight = 300,
            };
            container.MarginTop = (DrawingObjectRoot.Height - y) / 2;

            container.Items.Add(gameButton);
            container.Items.Add(menuButton);
            container.Items.Add(titleButton);
            container.Items.Add(desktopButton);
            Items.Add(container);

            Action1 += (sender, e) =>
            {
                ゲームに戻る();
            };
            Action3 += (sender, e) =>
            {
                ゲームに戻る();
            };
        }
        public DaimonState(EPuzzleWindow window, Daimon daimon, int numberOfItemsToBeShown = 16)
            : base(window)
        {
            _helpWithScroll = new HelpWithScroll<Chumon>(numberOfItemsToBeShown);
            Daimon = daimon;
            DrawingObjectRoot.BackColor = EPuzzleColors.DaimonStateBackColor;

            PropertyChanged += (sender, e) =>
            {
                if ("CurrentItem" != e.PropertyName) return;
                var chumonButton = CurrentItem as ChumonButton;
                if (null != chumonButton)
                {
                    _kirokuBox.Chumon = chumonButton.Chumon;
                    _kirokuInfoBox.Chumon = chumonButton.Chumon;
                }
            };
            Action0 += (sender, e) =>
            {
                var chumonButton = CurrentItem as ChumonButton;
                if (null != chumonButton)
                {
                    Chumonを開始する(chumonButton.Chumon, this);
                    return;
                }
                var daimonButton = CurrentItem as DaimonButton;
                if (null != daimonButton)
                {
                    Window.State = FoFi(this, new DaimonState(Window, daimonButton.Daimon));
                    return;
                }
                var button = CurrentItem as EigoTestButtonItem;
                if (null != button)
                {
                    switch (button.Name)
                    {
                        case "upButton" :
                        {
                            _helpWithScroll.ScrollUp();
                            return;
                        }
                        case "downButton" :
                        {
                            _helpWithScroll.ScrollDown();
                            return;
                        }
                    }
                    var chumon = button.Tag as Chumon;
                    if (null != chumon)
                    {
                        Chumonを開始する(chumon, this);
                        return;
                    }
                }
            };
            ActionLeft += (sender, e) =>
            {
                MoveToPreviousDaimon();
            /*				if (null == Daimon.PreviousItem) return;
                Window.State = FoFi(this, new DaimonState(Window, (Daimon)Daimon.PreviousItem));
                */
            };
            ActionRight += (sender, e) =>
            {
                MoveToNextDaimon();
            /*				if (null == Daimon.NextItem) return;
                Window.State = FoFi(this, new DaimonState(Window, (Daimon)Daimon.NextItem));
                */
            };
            ActionUp += (sender, e) =>
            {
                if (null == Daimon.Parent.PreviousItem) return;
                MoveTo((MondaiDocument)Daimon.Parent.PreviousItem);
            };
            ActionDown += (sender, e) =>
            {
                if (null == Daimon.Parent.NextItem) return;
                MoveTo((MondaiDocument)Daimon.Parent.NextItem);
            };
            _helpWithScroll.UpdateScreen += (sender, e) =>
            {
                UpdateItemsToBeDrawn();
            };
            UpdateItemsToBeDrawn();
        }
        public StartGameState(EPuzzleWindow window, string[] mondaiDocumentIdsWhichAreUsedInTutorState)
            : base(window)
        {
            if (null == mondaiDocumentIdsWhichAreUsedInTutorState) throw new ArgumentNullException();

            var button_color = Color.FromArgb(0xff, 0x00, 0x00, 0x80);
            var button_background_color = Color.FromArgb(0xff, 0xb0, 0xc4, 0xde);
            var button_size = new SizeF(260, 45);
            var button_left = (DrawingObjectRoot.Width - button_size.Width) / 2;
            var button_top = button_size.Height + 200;

            var title_label = new EigoTestLabelItem()
            {
                MarginTop = 100,
                MarginBottom = 80,
                Color = button_color,
            //				Text = "英 文 復 習 ゲ ー ム",
                Text = Application.ProductName,
                Height = 72f,
            };
            title_label.Font = EPuzzleFonts.GetMsGothic((int)(title_label.Height / 2f));
            Items.Add(title_label);

            // 問題ファイルを選ぶ
            _start_game_button = new EigoTestButtonItem()
            {
                MarginTop = button_size.Height / 3f,
                MarginLeft = button_left,
                Name = "StartGameButton",
                Text = "問題を選択する",
                Color = button_color,
                BackColor = button_background_color,
                Size = button_size,
                HelpText = "プレイする問題ファイルを選択します。",
            };
            _start_game_button.Click += (sender, e) =>
            {
                if (e.Info.Button != MouseButtons.Left) return;
                MoveToMondaiDocumentMenuState();
            };

            /*			_switch_profile_button = new EigoTestButtonItem()
            {
                MarginTop = button_size.Height / 3f,
                MarginLeft = button_left,
                Text = "Switch Profile",
                Color = button_color,
                BackColor = button_background_color,
                Size = button_size,
            };*/

            _quit_button = new EigoTestButtonItem()
            {
                MarginTop = button_size.Height / 3f,
                MarginLeft = button_left,
                Text = "終了する",
                Color = button_color,
                BackColor = button_background_color,
                Size = button_size,
                HelpText = "ゲームを終了してWindowsに戻ります。",
            };
            _quit_button.Click += (sender, e) =>
            {
                if (e.Info.Button != MouseButtons.Left) return;
                Window.QuitGame(this);
            };

            Items.Add(_start_game_button);

            var daimon = window.EPuzzleData.GetLastDaimon();
            if (null != daimon)
            {
                var continueButton = new EigoTestButtonItem()
                {
                    MarginTop = button_size.Height / 3f,
                    MarginLeft = button_left,
                    Text = "前回の続きから",
                    Name = "tsudukiKara",
                    Color = button_color,
                    BackColor = button_background_color,
                    Size = button_size,
                    HelpText = "最後にプレイしていた問題から再開します。",
                };
                Items.Add(continueButton);
            }

            if (mondaiDocumentIdsWhichAreUsedInTutorState.Any())
            {
                var tutorButton = new EigoTestButtonItem()
                {
                    MarginTop = button_size.Height / 3f,
                    MarginLeft = button_left,
                    Text = "復習する",
                    Name = "tutorButton",
                    Color = button_color,
                    BackColor = button_background_color,
                    Size = button_size,
                    HelpText = "復習が必要な問題を提案します。",
                };
                Items.Add(tutorButton);
            }

            //			Items.Add(_switch_profile_button);
            Items.Add(_quit_button);

            DrawingObjectRoot.BackColor = EPuzzleColors.Color00;

            Items.Add(CreateHelpTextBox());

            Action0 += (sender, e) =>
            {
                switch (CurrentItem.Name)
                {
                    case "tsudukiKara" :
                    {
                        if (null == daimon) throw new ApplicationException();
                        Window.State = WindowState.FoFi(this, new DaimonState(Window, daimon));
                        break;
                    }
                    case "tutorButton" :
                    {
                        Window.State = WindowState.FoFi(this, Window.GetTutorState(mondaiDocumentIdsWhichAreUsedInTutorState));
            //						Window.State = WindowState.FoFi(this, new TutorState(Window, mondaiDocumentIdsWhichAreUsedInTutorState));
                        break;
                    }
                    default :
                        break;
                }
            };
        }
        public ChumonResultState(EPuzzleWindow window, EigoTestMondai mondai, ChumonResult chumonResult, MondaiResult mondaiResult)
            : base(window)
        {
            _mondai = mondai;
            _chumonResult = chumonResult;

            DrawingObjectRoot.BackColor = EPuzzleColors.Color109;

            //			var imageFile = ResultImageManager.Instance.GetFile(_mondai.Parent.GetGradeString(mondaiResult.所要時間));
            //			var imageFile = ResultImageManager.Instance.GetImage(_mondai.Parent.GetGradeString(mondaiResult.所要時間));
            var image = window.EPuzzleData.CurrentUserInfo.ResultImageManager.GetImage(_mondai.Parent.GetGradeString(mondaiResult.所要時間, window.EPuzzleData.CurrentUserInfo));
            if (null != image)
            {
            //				var imageItem = new ImageItem(imageFile, true);
                var imageItem = new ImageItem(image.Shrink((int)DrawingObjectRoot.Width, (int)DrawingObjectRoot.Height));
                imageItem.Left = 0f;
                imageItem.Top = 0f;
                imageItem.Position = DrawingObjectPosition.Absolute;
                Items.Add(imageItem);

            #if DEBUG
                { // 使用したファイルの記録
                    var imagePath = (string)image.Tag;
                    Clipboard.SetText(imagePath);

                    var path = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "usedImages.txt");
                    File.AppendAllText(path, imagePath + Environment.NewLine);
                }
            #endif // DEBUG

            //				ResultImageManager.Instance.UpdateAccessTime(fileName);
            //				ResultImageManager.Instance.SaveFileIfItPassed(TimeSpan.FromMinutes(10d));
            }

            var w1 = 180f;
            var h1 = EPuzzleFonts.ChumonResultState_Default.Height;
            var backColor = EPuzzleColors.Color107;

            var kirokuBox = new KirokuBox2()
            {
                BorderLine = false,
                Position = DrawingObjectPosition.Absolute,
                Width = 200,
                UserInfo = Window.EPuzzleData.CurrentUserInfo,
                Chumon = (Chumon)_mondai.Parent,
                Color = EPuzzleColors.ChumonResultState_KirokuBox2_Color,
                BackColor = EPuzzleColors.ChumonResultState_KirokuBox2_BackColor,
                BackColorA = EPuzzleColors.ChumonResultState_KirokuBox2_BackColorA,
                BackColorB = EPuzzleColors.ChumonResultState_KirokuBox2_BackColorB,
                LineColor = EPuzzleColors.ChumonResultState_KirokuBox2_LineColor,
                NodeColor = EPuzzleColors.ChumonResultState_KirokuBox2_NodeColor,
            };
            Items.Add(kirokuBox);

            var box = new DrawingObjectContainer()
            {
                Position = DrawingObjectPosition.Absolute,
                Color = EPuzzleColors.Color108,
                BackColor = backColor,
                Width = w1,
                PaddingLeft = 10f, PaddingRight = 10f,
                PaddingTop = 10f, PaddingBottom = 10f,
                BorderLine = false,
            };
            Items.Add(box);

            {
                var item = new EigoTestLabelItem()
                {
                    Color = EPuzzleColors.Color108,
                    Text = mondai.Parent.LongName,
                    Font = EPuzzleFonts.ChumonResultState_Default,
                    Width = w1,
                    Height = h1,
                    StringFormat = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, },
                };
                box.Items.Add(item);
            }
            {
                var item = new EigoTestLabelItem()
                {
                    Color = EPuzzleColors.Color108,
                    Text = string.Format("グレード: {0}({1:0.00})", mondai.Parent.GetGradeString(mondaiResult.所要時間, window.EPuzzleData.CurrentUserInfo), mondai.Parent.GetGrade(mondaiResult.所要時間, window.EPuzzleData.CurrentUserInfo)),
                    Font = EPuzzleFonts.ChumonResultState_Default,
                    Width = w1,
                    Height = h1,
                    StringFormat = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, },
                };
                box.Items.Add(item);
            }
            {
                var duration = mondai.Parent.復習までの猶予期間を取得(window.EPuzzleData.CurrentUserInfo);
                if (null != duration)
                {
                    var item = new EigoTestLabelItem()
                    {
                        Color = EPuzzleColors.Color108,
                        Text = string.Format("復習猶予期間: {0:0.0}日", ((TimeSpan)duration).TotalDays),
                        Font = EPuzzleFonts.ChumonResultState_Default,
                        Width = w1,
                        Height = h1,
                        StringFormat = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, },
                    };
                    box.Items.Add(item);
                }
            }
            {
                var item = new EigoTestLabelItem()
                {
                    Color = EPuzzleColors.Color108,
                    Text = string.Format("基準時間: {0}", EigoTestMondai.符号無時間文字列(_mondai.Parent.GetTimeLimit(window.EPuzzleData.CurrentUserInfo))),
                    Font = EPuzzleFonts.ChumonResultState_Default,
                    Width = w1,
                    Height = h1,
                    StringFormat = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, },
                };
                box.Items.Add(item);
            }
            {
                var item = new EigoTestLabelItem()
                {
                    Color = EPuzzleColors.Color108,
                    Text = string.Format("所要時間: {0}", EigoTestMondai.符号無時間文字列(mondaiResult.所要時間)),
                    Font = EPuzzleFonts.ChumonResultState_Default,
                    Width = w1,
                    Height = h1,
                    StringFormat = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, },
                };
                box.Items.Add(item);
            }
            {
                var item = new EigoTestLabelItem()
                {
                    Color = EPuzzleColors.Color108,
                    Text = string.Format("基準との差: {0}", EigoTestMondai.符号付時間文字列(mondaiResult.所要時間 - _mondai.Parent.GetTimeLimit(window.EPuzzleData.CurrentUserInfo))),
                    Font = EPuzzleFonts.ChumonResultState_Default,
                    Width = w1,
                    Height = h1,
                    StringFormat = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, },
                };
                box.Items.Add(item);
            }
            /*			{
                var item = new EigoTestLabelItem()
                {
                    Color = EPuzzleColors.Color108,
                    Text = string.Format("Perfect: {0}", string.Join("", chumonResult.ShomonResults.Select(x => x.IsPerfect ? "■" : "□").ToArray())),
                    Font = EPuzzleFonts.ChumonResultState_Default,
                    Width = w1,
                    Height = h1,
                    StringFormat = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, },
                };
                box.Items.Add(item);
            }*/
            {
                var height = 25f;
                var stars = chumonResult.ShomonResults.Select(x =>
                {
                    var star = new Pentagram(2)
                    {
                        Color = EPuzzleColors.PerfectStarOnChumonResultState,
                        Width = height,
                        Height = height,
                        Tag = x.IsPerfect,
                        PaddingLeft = 3f,
                        PaddingBottom = 3f,
                    };
                    return star;
                }).ToArray();
            /*				for (int i = 0; i < stars.Length; i++)
                {
                    stars[i].Left = stars[0].OuterWidth * i;
                    stars[i].Top = DrawingObjectRoot.Height - stars[0].OuterHeight;
                }
                */
                for (int i = 0; i < stars.Length; i++)
                {
                    stars[i].Left = stars[0].OuterWidth * i;
                    stars[i].Top = 0f;
                }

                if (stars.Any())
                {
                    var starbox = new DrawingObjectContainer()
                    {
                        Position = DrawingObjectPosition.Absolute,
                        Left = 0f,
                        Top = DrawingObjectRoot.Height - stars.First().OuterHeight,
                        Width = stars.Last().OuterRight - stars.First().OuterLeft,
                        Height = stars.First().OuterHeight,
            //						BackColor = EPuzzleColors.Color107,
                    };
                    starbox.Items.AddRange(stars);
                    Items.Add(starbox);
                }
            //				Items.AddRange(stars);
            }

            /*			{
                var bestMondaiResult = window.EPuzzleData.CurrentUserInfo.MondaiResults.GetBest(mondai.Parent.Id);
                if (null != bestMondaiResult)
                {
                    var item = new EigoTestLabelItem()
                    {
                        Color = EPuzzleColors.Color108,
                        Text = string.Format("最速記録: {0}", EigoTestMondai.符号無時間文字列(bestMondaiResult.所要時間)),
                        Font = EPuzzleFonts.ChumonResultState_Default,
                        Width = w1,
                        Height = h1,
                        StringFormat = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, },
                    };
                    box.Items.Add(item);
                }
            }
            {
                var bestMondaiResult = window.EPuzzleData.CurrentUserInfo.MondaiResults.GetBest(mondai.Parent.Id);
                if (null != bestMondaiResult)
                {
                    var item = new EigoTestLabelItem()
                    {
                        Color = EPuzzleColors.Color108,
                        Text = string.Format("最速との差: {0}", EigoTestMondai.符号付時間文字列(mondaiResult.所要時間 - bestMondaiResult.所要時間)),
                        Font = EPuzzleFonts.ChumonResultState_Default,
                        Width = w1,
                        Height = h1,
                        StringFormat = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center, },
                    };
                    box.Items.Add(item);
                }
            }*/

            /*			var retryButton = new EigoTestButtonItem()
            {
                Position = DrawingObjectPosition.Absolute,
                Color = EPuzzleColors.Color108,
                Text = "再挑戦",
                Name = "retryButton",
                Font = EPuzzleFonts.ChumonResultState_Default,
                Width = 80,
                Height = h1,
            };
            Items.Add(retryButton);*/

            /*
            // 右がbox
            box.Left = DrawingObjectRoot.Width - ( box.OuterWidth + kirokuBox.OuterWidth );
            box.Top = DrawingObjectRoot.Height - box.OuterHeight;

            kirokuBox.Height = box.OuterHeight;
            kirokuBox.Left = DrawingObjectRoot.Width - kirokuBox.OuterWidth;
            kirokuBox.Top = box.Top;
            */

            box.Left = DrawingObjectRoot.Width - box.OuterWidth;
            box.Top = DrawingObjectRoot.Height - box.OuterHeight;

            kirokuBox.Height = box.OuterHeight;
            kirokuBox.Left = box.OuterLeft - kirokuBox.OuterWidth;
            kirokuBox.Top = box.Top;

            Action0 += (sender, e) =>
            {
                MouseUpInternal(new MouseEventInfo(new PointF(0f, 0f), MouseButtons.Left));
            };
        }
        public EigoTestController(string settings_directory)
        {
            //			_form.Text = "英文復習ゲーム";
            _form.Text = Application.ProductName; // "英文復習ゲーム";

            /*			MondaiItem.KaitouRect = new Rectangle(100, 150, 600, 300);
            MondaiItem.KaitouRectPadding = 10;
            MondaiItem.SentakuRect = new Rectangle(100, 300, 600, 260);
            MondaiItem.SentakuRectPadding = 10;
            MondaiItem.WordsCardKankaku = 8;
            WordsCard.Padding = 7;
            WordsCard.Font = new Font(FontFamily.GenericSansSerif, 16);
            WordsCard.HotKeyFont = new Font(FontFamily.GenericSerif, 8);
            */
            //			ShomonState.ShowStars = true;

            var dataDirectory = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "appdata");
            var ePuzzleData = LoadEPuzzleData(dataDirectory);
            var window = _window = new EPuzzleWindow(ePuzzleData);

            EPuzzlePronuncer.Instance.Enable = true;
            EPuzzlePronuncer.Instance.DirectoryName = ePuzzleData.発音ファイルのディレクトリ名;

            ePuzzleData.CurrentUserInfo.SoundPlayer.IsEnabled = true;

            //			EPuzzleSoundPlayer.IsEnabled = true;

            window.ClientRectangle = _form.ClientRectangle;

            {
                _window.State = WindowState.Fi(new StartGameState(_window, ePuzzleData.家庭教師モードの対象になる問題ファイルのIDの配列), EPuzzleConstants.画面切替時間);			}

            /*			{
                _window.State = WindowState.Fi(new ChumonResultState(_window), EPuzzleConstants.画面切替時間);
            }*/

            /*
            var fff = @"E:\dev\ep-wd\appdata\EPuzzleUserInfos.dat";
            if (File.Exists(fff))
            {
                var container = EPuzzleUserInfoContainer.Load(fff);
                container.SaveAllFilesTo(Path.GetDirectoryName(fff));
            }
            */

            var last_time = DateTime.MinValue;
            _form.Paint += (sender, e) =>
            {
                e.Graphics.FillRectangle(Brushes.White, _form.ClientRectangle);

                // テキストはアンチエイリアスしつつ、線などはアンチエイリアスでぼやけないように普通の描画をする
            //				e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

                var startTime = DateTime.Now;
                window.Draw(e.Graphics);
                var dt = DateTime.Now - startTime;

                var versionFont = EPuzzleFonts.GetMsGothic(12);

            #if TEST
                var text = string.Format("{0}fps {1}, {2}ms, Ver.{3}", _fps.ToString("f1"), _counter.ToString(), (int)dt.TotalMilliseconds, Application.ProductVersion);
            #else
                var text = string.Format("Ver.{0}", Application.ProductVersion);
            #endif
                e.Graphics.DrawString(text, versionFont, Brushes.Black, new PointF(0, 0));

                _fps = 1000d / (DateTime.Now - last_time).TotalMilliseconds;
                _counter++;
                last_time = DateTime.Now;
            };
            _form.MouseUp += (sender, e) =>
            {
                Trace.WriteLine("MouseUp");
                window.MouseUp(new MouseEventInfo_MouseEventArgs(e));
            };

            var lastMouseLocation = new Point();
            _form.MouseMove += (sender, e) =>
            {
                if (e.Location == lastMouseLocation)
                {
                    Trace.WriteLine("Although a MouseMove event has been sent, its Location property is not changed.");
                    return;
                }
                lastMouseLocation = e.Location;
                window.MouseMove(new MouseEventInfo_MouseEventArgs(e));
            };
            _form.MouseWheel += (sender, e) =>
            {
                window.MouseWheel(new MouseEventInfo_MouseEventArgs(e));
            };
            _form.KeyDown += (sender, e) =>
            {
                window.KeyDown(new KeyEventInfo(e));
            };
            _form.KeyPress += (sender, e) =>
            {
                window.KeyPress(e);
            };
            _form.Resize += (sender, e) =>
            {
                var form = (Form)sender;
                window.State.DrawingObjectRoot.Width = form.ClientSize.Width;
                window.State.DrawingObjectRoot.Height = form.ClientSize.Height;
            };

            window.Invalidate += (sender, e) =>
            {
                if (_form.InvokeRequired)
                {
                    _form.BeginInvoke((Action)(() => { _form.Invalidate(); }));
                }
                else
                {
                    _form.Invalidate();
                }
            };
            window.Quit += (sender, e) =>
            {
                _form.Close();
            };

            window.PropertyChanged += (sender, e) =>
            {
                switch (e.PropertyName)
                {
                    case "MouseCursor" :
                    {
                        switch (window.MouseCursor)
                        {
                            case MouseCursor.Default :
                            {
                                _form.Cursor = System.Windows.Forms.Cursors.Default;
                                System.Windows.Forms.Cursor.Show();
                                break;
                            }
                            case MouseCursor.Hand :
                            {
                                _form.Cursor = System.Windows.Forms.Cursors.Hand;
                                System.Windows.Forms.Cursor.Show();
                                break;
                            }
                            case MouseCursor.Hidden :
                            {
                                System.Windows.Forms.Cursor.Hide();
                                break;
                            }
                            default :
                            {
                                throw new InvalidOperationException();
                            }
                        }
                        break;
                    }
                }
            };

            _form.Load += (sender, e) =>
            {
                _timer.Start();
            };

            _timer.Interval = 50;
            _timer.Tick += (sender, e) =>
            {
                window.Tick();
            };
        }
        public TutorState(EPuzzleWindow window, EPuzzleTutor tutor)
            : base(window)
        {
            Trace.WriteLine(_sortType);

            _tutor = tutor;
            _kirokuBox = new KirokuBox2()
            {
                Position = DrawingObjectPosition.Absolute,
                Left = 10,
                Top = 60,
                Width = 280,
                Height = 200,
                UserInfo = Window.EPuzzleData.CurrentUserInfo,
            };
            Action0 += (sender, e) =>
            {
                var chumonButton = CurrentItem as ChumonButton;
                if (null != chumonButton)
                {
                    Chumonを開始する(chumonButton.Chumon, this);
                    return;
                }
                var button = CurrentItem as EigoTestButtonItem;
                if (null != button)
                {
                    switch (button.Name)
                    {
                        case "upButton" :
                            _helpWithScroll.ScrollUp();
                            return;

                        case "downButton" :
                            _helpWithScroll.ScrollDown();
                            return;

            /*						case "orderByGradeStringsButton" :
                            OrderByGradeStrings = !OrderByGradeStrings;
                            Refresh();
                            return;*/

                        case "mottoyaruButton" :
                            もっとやる係数++;
                            Refresh();
                            return;

                        case "backToStartGameStateButton" :
                            MoveToStartGameState();
                            return;

                        case "byGracePriodButton" :
                        {
                            _sortType = TutorStateSortType.GracePriod;
                            Refresh();
                            return;
                        }
                        case "byDateYouDidThemButton" :
                        {
                            _sortType = TutorStateSortType.DateYouDidThem;
                            Refresh();
                            return;
                        }
                        case "byGradeButton" :
                        {
                            _sortType = TutorStateSortType.Grade;
                            Refresh();
                            return;
                        }

                        default:
                            return;
                    }
                }
            };
            ActionUp += (sender, e) =>
            {
                _helpWithScroll.ScrollUp();
            };
            ActionDown += (sender, e) =>
            {
                _helpWithScroll.ScrollDown();
            };
            PropertyChanged += (sender, e) =>
            {
                if ("CurrentItem" != e.PropertyName) return;
                var chumonButton = CurrentItem as ChumonButton;
                _kirokuBox.Chumon = null == chumonButton ? null : chumonButton.Chumon;
            };

            EventHandler updateScreen = (sender, e) =>
            {
                Refresh();
            };
            _dateYouDidThemScrollHelper.UpdateScreen += updateScreen;
            _gracePriodScrollHelper.UpdateScreen += updateScreen;
            _gradeScrollHelper.UpdateScreen += updateScreen;

            Refresh();
        }
 public TutorState(EPuzzleWindow window, IEnumerable<string> mondaiDocumentIds, TimeSpan duration)
     : this(window, new EPuzzleTutor(window.EPuzzleData, mondaiDocumentIds, duration))
 {
 }
 public void Initialize()
 {
     var data = EPuzzleData.Create(_tempDirectory.Name);
     Window = new EPuzzleWindow(data);
     EPuzzleTime.NowObject = new TestNowObject();
     //			EPuzzleTime.Now = new DateTime(2120, 1, 1, 0, 0, 0, DateTimeKind.Local);
     EPuzzleTime.Now = new DateTime(2011, 1, 1, 0, 0, 0); // UTC
 }
        public HelpItemState(EPuzzleWindow window, HelpItemBase[] helpItems, int helpItemIndex, WindowState parentState)
            : base(window)
        {
            _helpItems = helpItems;
            _helpItemIndex = helpItemIndex;
            _parentState = parentState;

            var helpItemButtons = helpItems.Select(helpItem =>
            {
                var helpItemButton = new EigoTestButtonItem("", 20f, 18f)
                {
                    Position = DrawingObjectPosition.Absolute,
                    MarginRight = 10f,
                    MarginBottom = 10f,
                    Tag = helpItem,
                };
                return helpItemButton;
            });
            var helpItemButtonContainer = new DrawingObjectContainer()
            {
                Position = DrawingObjectPosition.Absolute,
                MarginLeft = 50f,
                Height = 40f,
            };
            helpItemButtonContainer.Items.AddRange(helpItemButtons);
            helpItemButtonContainer.Items[helpItemIndex].IsClickable = false;
            Items.Add(helpItemButtonContainer);

            for (int i = 1; i < helpItemButtonContainer.Items.Count(); i++)
            {
                var s = helpItemButtonContainer.Items[i - 1];
                var t = helpItemButtonContainer.Items[i];
                t.Left = s.Left + s.OuterWidth;
            }
            helpItemButtonContainer.下揃え();

            var modoruButton = new EigoTestButtonItem("続ける", 80f, 50f)
            {
                Position = DrawingObjectPosition.Absolute,
                Name = "tsudukeru",
                MarginRight = 50f, MarginBottom = 10f,
            };
            Items.Add(modoruButton);
            modoruButton.右揃え();
            modoruButton.下揃え();

            if (0 < helpItemIndex)
            {
                var previousButton = new PreviousButton()
                {
                    Position = DrawingObjectPosition.Absolute,
                    MarginLeft = 10f,
                    Tag = helpItemIndex - 1,
                };
                Items.Add(previousButton);
                previousButton.垂直方向に中央揃え();
            }
            if (helpItemIndex < helpItemButtonContainer.Items.Count() - 1)
            {
                var nextButton = new NextButton()
                {
                    Position = DrawingObjectPosition.Absolute,
                    MarginRight = 10f,
                    Tag = helpItemIndex + 1,
                };
                Items.Add(nextButton);
                nextButton.垂直方向に中央揃え();
                nextButton.右揃え();
            }
            if (!string.IsNullOrWhiteSpace(_helpItems[helpItemIndex].ImageFile))
            {
                var imageFile = Path.Combine(window.EPuzzleData.HelpDirectory, _helpItems[helpItemIndex].ImageFile);
                var imageItem = new ImageItem(imageFile)
                {
                    Position = DrawingObjectPosition.Absolute,
                    MarginTop = 20f,
                };
                Items.Add(imageItem);
                imageItem.水平方向に中央揃え();
            }

            Action0 += (sender, e) =>
            {
                if (CurrentItem is NextButton)
                {
                    MoveTo((int)CurrentItem.Tag);
                }
                else if (CurrentItem is PreviousButton)
                {
                    MoveTo((int)CurrentItem.Tag);
                }
                else if (CurrentItem.Tag is HelpItem)
                {
                    var index = Array.IndexOf(helpItems, CurrentItem.Tag);
                    MoveTo(index);
                }
                else if ("tsudukeru" == CurrentItem.Name)
                {
                    Window.State = parentState;
                }
            };
            Action3 += (sender, e) =>
            {
                Window.State = parentState;
            };
        }
 public TestState(EPuzzleWindow window)
     : base(window)
 {
 }