Exemple #1
0
        /// <summary>
        /// 初期処理を行います。
        /// </summary>
        private static void Start()
        {
            NoneMovePlayer = Player.Index.First;
            LastWinCount   = new[] { 0, 0 };

            // 初期フィールド状態の取得
            NoneDirectionUpdateFrameCount = 0;
            Receiver = ConsoleClientDiProvider.GetContainer().GetInstance <CommandReceiver <NativeCommand, FieldContext> >();
            Sender   = ConsoleClientDiProvider.GetContainer().GetInstance <FieldContextSender <string> >();
            var command = ConsoleClientDiProvider.GetContainer().GetInstance <NativeCommand>();

            command.Command = Command.Start;
            Context         = Receiver.Receive(command);

            // キー変更イベントの購読
            KeyInfos         = new List <ConsoleKeyInfo>();
            IsBlockedKeyInfo = false;

            // キーの入力読み込みタスクを開始
            Task.Run(() =>
            {
                while (true)
                {
                    if (!IsBlockedKeyInfo)
                    {
                        KeyInfos.Add(Console.ReadKey());
                    }
                }
            });
        }
Exemple #2
0
        /// <summary>
        /// フレーム毎に実行される更新処理を行います。
        /// </summary>
        private static void Update()
        {
            if (IsEnd(Context))
            {
                Console.WriteLine(string.Format("{0}Pの勝ちです。", (int)GetWinPlayer(Context) + 1));
                return;
            }

            // 移動方向無コマンドの実行
            Context.OperationDirection = Direction.None;
            var c = ConsoleClientDiProvider.GetContainer().GetInstance <NativeCommand>();

            c.Command = Command.Move;
            c.Context = Context.DeepCopy();
            c.Context.OperationPlayer = NoneMovePlayer;
            NoneMovePlayer            = Player.GetOppositeIndex(NoneMovePlayer);
            FileHelper.WriteLine("----- 移動方向無コマンドの実行 -----");
            FileHelper.WriteLine(Sender.Send(Context));
            Context = Receiver.Receive(c);

            // 入力を受け付けたコマンドの実行
            IsBlockedKeyInfo = true;
            var keys = KeyInfos.Select(k => k).ToList();

            KeyInfos.Clear();
            IsBlockedKeyInfo = false;

            foreach (var key in keys)
            {
                if (!KeyMap.ContainsKey(key.Key))
                {
                    continue;
                }

                Context.OperationPlayer    = KeyMap.GetPlayer(key.Key);
                Context.OperationDirection = KeyMap.GetDirection(key.Key);
                c         = ConsoleClientDiProvider.GetContainer().GetInstance <NativeCommand>();
                c.Command = Command.Move;
                c.Context = Context.DeepCopy();
                FileHelper.WriteLine("----- 入力を受け付けたコマンドの実行 -----");
                FileHelper.WriteLine(Sender.Send(Context));
                Context = Receiver.Receive(c);
            }

            // 画面描画
            FieldContextWriter.Write(Context);
        }
Exemple #3
0
 //for web player, gets called via the SendMessage interface with Unity, requires it being on a GameObject named Canvas
 private void MessageListener(string message)
 {
     m_Receiver.Receive(message);
 }