Пример #1
0
        private List <Point> Update()
        {
            for (var i = 0; i < 64; i++)
            {
                var point = ConvertPoint(i);
                switch (Othello.Board[point.x, point.y])
                {
                case -1:
                    DiscDataList[i].DiscCondition = DiscCondition.Black;
                    break;

                case 1:
                    DiscDataList[i].DiscCondition = DiscCondition.White;
                    break;

                case 0:
                    DiscDataList[i].DiscCondition = DiscCondition.Void;
                    break;
                }
            }
            var points = Othello.GetPossiblePoints(Othello.Turn);

            switch (Othello.Turn)
            {
            case -1:
                foreach (var point in points)
                {
                    DiscDataList[ConvertInt(point)].DiscCondition = DiscCondition.AbleBlack;
                }
                break;

            case 1:
                foreach (var point in points)
                {
                    DiscDataList[ConvertInt(point)].DiscCondition = DiscCondition.AbleWhite;
                }
                break;
            }
            BlackNumberText = Othello.GetDiscNumber(-1).ToString();
            WhiteNumberText = Othello.GetDiscNumber(1).ToString();
            return(points);
        }
Пример #2
0
        public BoardViewModel(int player = -1, int cpu = 0)
        {
            WaitingMaskVisibility = Visibility.Collapsed;
            MessageBoxData        = MessageBoxViewModel.Empty;
            PassControlData       = new PassControlViewModel();
            DiscDataList          = new DiscViewModel[64];


            double min = Math.Min(Frame.ActualHeight, Frame.ActualWidth);

            if (min < 600)
            {
                Height = min * 5 / 6;
                Width  = min * 5 / 6;
            }
            else
            {
                Height = 500;
                Width  = 500;
            }
            cpuLevel    = cpu;
            playercolor = player;
            Othello     = new Othello();
            Othello.Start();
            QuitCommand = new SimpleCommand(o =>
            {
                MessageBoxData = new ConfirmMessageBoxViewModel();
            });


            BlackNumberText = Othello.GetDiscNumber(-1).ToString();
            WhiteNumberText = Othello.GetDiscNumber(1).ToString();
            if (cpu == 0)
            {
                BlackPlayerText = "1P: ";
                WhitePlayerText = "2P: ";
                BackCommand     = new SimpleCommand(o =>
                {
                    Othello.Back();
                    Update();
                });
                Othello.EndEvent += (othello, resulut) =>
                {
                    if (resulut == 0)
                    {
                        MessageBoxData = new EndMessageBoxViewModel(player, cpu, "Draw !");
                    }
                    else if (playercolor == resulut)
                    {
                        MessageBoxData = new EndMessageBoxViewModel(player, cpu, "2P Success");
                    }
                    else
                    {
                        MessageBoxData = new EndMessageBoxViewModel(player, cpu, "2P Success");
                    }
                };
                PassControlData.OkCommand = new SimpleCommand(o =>
                {
                    PassControlData.Visibility = Visibility.Collapsed;
                    Othello.Pass();
                    Update();
                });
                Othello.PassEvent += (othello, pass) =>
                {
                    PassControlData.Visibility = Visibility.Visible;
                };
                Initplayer();
            }
            else
            {
                if (player == 1)
                {
                    BlackPlayerText = "CPU Lv." + cpu + ":";
                    WhitePlayerText = "You:";
                }
                else
                {
                    WhitePlayerText = "CPU Lv." + cpu + ":";
                    BlackPlayerText = "You:";
                }

                BackCommand = new SimpleCommand(o =>
                {
                    PassControlData.Visibility = Visibility.Collapsed;
                    Othello.Back();
                    Othello.Back();
                    Update();
                });
                Othello.EndEvent += (othello, resulut) =>
                {
                    if (resulut == 0)
                    {
                        MessageBoxData = new EndMessageBoxViewModel(player, cpu, "Draw !");
                    }
                    else if (playercolor == resulut)
                    {
                        MessageBoxData = new LoseMessageBoxViewModel(player, cpu);
                    }
                    else
                    {
                        MessageBoxData = new WinMessageBoxViewModel(player, cpu);
                    }
                };
                PassControlData.OkCommand = new SimpleCommand(async o =>
                {
                    PassControlData.Visibility = Visibility.Collapsed;
                    Othello.Pass();
                    var points = Update();
                    await AiPutAsync(points);
                });
                Othello.PassEvent += (othello, pass) =>
                {
                    if (pass == player)
                    {
                        PassControlData.Visibility = Visibility.Visible;
                    }
                };
                Initcpu(cpu, playercolor);
            }
        }