예제 #1
0
파일: TheApp.cs 프로젝트: ruhiel/MyShogi
        /// <summary>
        /// ここが本アプリのエントリーポイント
        /// </summary>
        public void Run()
        {
            // -- 各インスタンスの生成と、それぞれのbind作業

            // メインの対局ウィンドゥ

            var mainDialog = new MainDialog();

            mainDialogViewModel = new MainDialogViewModel();
            mainDialog.Bind(mainDialogViewModel);

            // 対局controllerを1つ生成して、メインの対局ウィンドゥのViewModelに加える
            var game = new GameController();

            mainDialogViewModel.Add(game);

            // Notifyクラスのテスト(あとで消す)
            //NotifyTest.Test();

            Application.Run(mainDialog);
        }
예제 #2
0
        /// <summary>
        /// ここが本アプリのエントリーポイント
        /// </summary>
        public void Run()
        {
            // -- 開発時のテストコード

            // 駒素材画像の変換
            //ImageConverter.ConvertPieceImage();
            //ImageConverter.ConvertBoardNumberImage();

            // -- global configの読み込み

            config = GlobalConfig.CreateInstance();

            // -- 各インスタンスの生成と、それぞれのbind作業

            // -- 画像の読み込み

            {
                imageManager = new ImageManager();
                imageManager.Update(); // ここでconfigに従い、画像が読み込まれる。

                // GlobalConfigのプロパティ変更に対して、このimageManagerが呼び出されるようにbindしておく。

                config.AddPropertyChangedHandler("BoardImageVersion", imageManager.UpdateBoardImage);
                config.AddPropertyChangedHandler("TatamiImageVersion", imageManager.UpdateBoardImage);
                config.AddPropertyChangedHandler("KomadaiImageVersion", imageManager.UpdateBoardImage);
                config.AddPropertyChangedHandler("InTheBoardEdit", imageManager.UpdateBoardImage);

                config.AddPropertyChangedHandler("PieceImageVersion", imageManager.UpdatePieceImage);
                config.AddPropertyChangedHandler("PieceAttackImageVersion", imageManager.UpdatePieceAttackImage);

                config.AddPropertyChangedHandler("LastMoveFromColorType", imageManager.UpdatePieceMoveImage);
                config.AddPropertyChangedHandler("LastMoveToColorType", imageManager.UpdatePieceMoveImage);
                config.AddPropertyChangedHandler("PickedMoveFromColorType", imageManager.UpdatePieceMoveImage);
                config.AddPropertyChangedHandler("PickedMoveToColorType", imageManager.UpdatePieceMoveImage);

                config.AddPropertyChangedHandler("BoardNumberImageVersion", imageManager.UpdateBoardNumberImage);
            }

            // -- メインの対局ウィンドゥ

            var mainDialog = new MainDialog();

            mainForm = mainDialog;

            mainDialogViewModel  = new MainDialogViewModel();
            mainDialog.ViewModel = mainDialogViewModel;

            // -- 対局controllerを1つ生成して、メインの対局ウィンドゥのViewModelに加える

            var gameServer = new LocalGameServer();

            mainDialogViewModel.gameServer = gameServer;

            // LocalGameServerの対局情報と棋譜ウィンドウが更新されたときにメインウインドウの盤面・棋譜ウィンドウに
            // 更新がかかるようにしておく。

            gameServer.AddPropertyChangedHandler("KifuList", mainDialog.gameScreen.kifuControl.OnListChanged, mainDialog);
            gameServer.AddPropertyChangedHandler("Position", mainDialog.gameScreen.PositionChanged);
            gameServer.AddPropertyChangedHandler("TurnChanged", mainDialog.gameScreen.TurnChanged, mainDialog);
            gameServer.AddPropertyChangedHandler("InTheGame", mainDialog.gameScreen.InTheGameChanged, mainDialog);
            gameServer.AddPropertyChangedHandler("InTheGame", mainDialog.UpdateMenuItems, mainDialog);
            gameServer.AddPropertyChangedHandler("EngineInitializing", mainDialog.gameScreen.EngineInitializingChanged, mainDialog);
            gameServer.AddPropertyChangedHandler("RestTimeChanged", mainDialog.gameScreen.RestTimeChanged);
            gameServer.AddPropertyChangedHandler("BoardReverse", mainDialog.UpdateMenuItems, mainDialog);
            gameServer.AddPropertyChangedHandler("GameServerStarted", mainDialog.UpdateMenuItems, mainDialog);
            gameServer.AddPropertyChangedHandler("SetKifuListIndex", mainDialog.gameScreen.SetKifuListIndex, mainDialog);

            // 盤・駒が変更されたときにMainDialogのメニューの内容を修正しないといけないので更新がかかるようにしておく。

            config.AddPropertyChangedHandler("BoardImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("TatamiImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("PieceImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("PromotePieceColorType", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("PieceAttackImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("BoardNumberImageVersion", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("LastMoveFromColorType", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("LastMoveToColorType", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("PickedMoveFromColorType", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("PickedMoveToColorType", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("TurnDisplay", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("PieceSoundInTheGame", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("KifuReadOut", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("ReadOutSenteGoteEverytime", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("MemoryLoggingEnable", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("FileLoggingEnable", mainDialog.UpdateMenuItems, mainDialog);
            config.AddPropertyChangedHandler("InTheBoardEdit", mainDialog.UpdateMenuItems, mainDialog);

            // 盤面編集時などに棋譜ウィンドウを消す

            config.AddPropertyChangedHandler("InTheBoardEdit", mainDialog.gameScreen.UpdateKifuControlVisibility, mainDialog);

            // -- ロギング用のハンドラをセット

            var MemoryLoggingEnableHandler = new PropertyChangedEventHandler((args) =>
            {
                if (config.MemoryLoggingEnable)
                {
                    Log.log1 = new MemoryLog();
                }
                else
                {
                    if (Log.log1 != null)
                    {
                        Log.log1.Dispose();
                    }
                    Log.log1 = null;
                }
            });
            var FileLoggingEnable = new PropertyChangedEventHandler((args) =>
            {
                if (config.FileLoggingEnable)
                {
                    var now  = DateTime.Now;
                    Log.log2 = new FileLog($"log{now.ToString("yyyyMMddHHmm")}.txt");
                }
                else
                {
                    if (Log.log2 != null)
                    {
                        Log.log2.Dispose();
                    }
                    Log.log2 = null;
                }
            });

            config.AddPropertyChangedHandler("MemoryLoggingEnable", MemoryLoggingEnableHandler);
            config.AddPropertyChangedHandler("FileLoggingEnable", FileLoggingEnable);

            // 上のハンドラを呼び出して、必要ならばロギングを開始しておいてやる。
            MemoryLoggingEnableHandler(null);
            FileLoggingEnable(null);

            // 初期化が終わったのでgameServerの起動を行う。
            gameServer.Start();

            // サウンド
            soundManager = new SoundManager();
            soundManager.Start();

            // 終了するときに設定ファイルに書き出すコード
            Application.ApplicationExit += new EventHandler((sender, e) =>
            {
                config.Save();
                soundManager.Dispose();
            });

            Application.Run(mainDialog);
        }
예제 #3
0
 /// <summary>
 /// ViewModelを設定する。
 /// このクラスのインスタンスとは1:1で対応する。
 /// </summary>
 /// <param name="vm"></param>
 public void Bind(MainDialogViewModel vm)
 {
     ViewModel = vm;
 }
예제 #4
0
        /// <summary>
        /// ここが本アプリのエントリーポイント
        /// </summary>
        public void Run()
        {
            // -- 開発時のテストコード

            // 駒素材画像の変換
            //ImageConverter.ConvertPieceImage();
            //ImageConverter.ConvertBoardNumberImage();

            // -- global configの読み込み

            config = GlobalConfig.CreateInstance();

            // -- 各インスタンスの生成と、それぞれのbind作業

            // -- 画像の読み込み

            {
                imageManager = new ImageManager();
                imageManager.Update(); // ここでconfigに従い、画像が読み込まれる。

                // GlobalConfigのプロパティ変更に対して、このimageManagerが呼び出されるようにbindしておく。

                config.AddPropertyChangedHandler("BoardImageVersion", imageManager.UpdateBoardImage);
                config.AddPropertyChangedHandler("TatamiImageVersion", imageManager.UpdateBoardImage);
                config.AddPropertyChangedHandler("KomadaiImageVersion", imageManager.UpdateBoardImage);

                config.AddPropertyChangedHandler("PieceImageVersion", imageManager.UpdatePieceImage);
                config.AddPropertyChangedHandler("PieceAttackImageVersion", imageManager.UpdatePieceAttackImage);

                config.AddPropertyChangedHandler("LastMoveFromColorType", imageManager.UpdatePieceMoveImage);
                config.AddPropertyChangedHandler("LastMoveToColorType", imageManager.UpdatePieceMoveImage);
                config.AddPropertyChangedHandler("PickedMoveFromColorType", imageManager.UpdatePieceMoveImage);
                config.AddPropertyChangedHandler("PickedMoveToColorType", imageManager.UpdatePieceMoveImage);

                config.AddPropertyChangedHandler("BoardNumberImageVersion", imageManager.UpdateBoardNumberImage);
            }

            // -- メインの対局ウィンドゥ

            var mainDialog = new MainDialog();

            mainDialogViewModel  = new MainDialogViewModel();
            mainDialog.ViewModel = mainDialogViewModel;

            // -- 対局controllerを1つ生成して、メインの対局ウィンドゥのViewModelに加える

            var gameServer = new LocalGameServer();

            mainDialogViewModel.gameServer = gameServer;

            // LocalGameServerの対局情報と棋譜ウィンドウが更新されたときにメインウインドウの盤面・棋譜ウィンドウに
            // 更新がかかるようにしておく。

            gameServer.AddPropertyChangedHandler("KifuList", mainDialog.gameScreen.kifuControl.OnListChanged);
            gameServer.AddPropertyChangedHandler("Position", mainDialog.gameScreen.PositionChanged);
            gameServer.AddPropertyChangedHandler("TurnChanged", mainDialog.gameScreen.TurnChanged);
            gameServer.AddPropertyChangedHandler("InTheGame", mainDialog.gameScreen.TurnChanged);
            gameServer.AddPropertyChangedHandler("EngineInitializing", mainDialog.gameScreen.EngineInitializingChanged);
            gameServer.AddPropertyChangedHandler("RestTimeChanged", mainDialog.gameScreen.RestTimeChanged);

            // 盤・駒が変更されたときにMainDialogのメニューの内容を修正しないといけないので更新がかかるようにしておく。

            config.AddPropertyChangedHandler("BoardReverse", mainDialog.UpdateMenuItems);
            config.AddPropertyChangedHandler("BoardImageVersion", mainDialog.UpdateMenuItems);
            config.AddPropertyChangedHandler("TatamiImageVersion", mainDialog.UpdateMenuItems);
            config.AddPropertyChangedHandler("PieceImageVersion", mainDialog.UpdateMenuItems);
            config.AddPropertyChangedHandler("PromotePieceColorType", mainDialog.UpdateMenuItems);
            config.AddPropertyChangedHandler("PieceAttackImageVersion", mainDialog.UpdateMenuItems);
            config.AddPropertyChangedHandler("BoardNumberImageVersion", mainDialog.UpdateMenuItems);
            config.AddPropertyChangedHandler("LastMoveFromColorType", mainDialog.UpdateMenuItems);
            config.AddPropertyChangedHandler("LastMoveToColorType", mainDialog.UpdateMenuItems);
            config.AddPropertyChangedHandler("PickedMoveFromColorType", mainDialog.UpdateMenuItems);
            config.AddPropertyChangedHandler("PickedMoveToColorType", mainDialog.UpdateMenuItems);
            config.AddPropertyChangedHandler("TurnDisplay", mainDialog.UpdateMenuItems);

            // MainDialogViewModelが変更されたときにMainDialogに変更がかからないといけないのでそのハンドラの設定。


            // Notifyクラスのテスト(あとで消す)
            //NotifyTest.Test();

            // 終了するときに設定ファイルに書き出すコード
            Application.ApplicationExit += new EventHandler((sender, e) =>
            {
                config.Save();
            });

            Application.Run(mainDialog);
        }