private async void Initcpu(int cpu, int playercolor) { Ai = new MakeOthelloAi(cpu); for (var i = 0; i < DiscDataList.Length; i++) { var discdata = new DiscViewModel(i, Height * 0.08); discdata.DiscTapedCommand = new SimpleCommand((async o => { if (!Othello.Put(ConvertPoint(discdata.Number))) { return; } var points = Update(); await AiPutAsync(points); })); DiscDataList[i] = discdata; } if (playercolor == 1) { var points = Update(); await AiPutAsync(points); } else { Update(); } }
private void Initplayer() { for (var i = 0; i < DiscDataList.Length; i++) { var discdata = new DiscViewModel(i, Height * 0.08); discdata.DiscTapedCommand = new SimpleCommand((o => { if (!Othello.Put(ConvertPoint(discdata.Number))) { return; } Update(); })); DiscDataList[i] = discdata; } Update(); }
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); } }