private void PrepareForNewGame() { try { Debug.WriteLine($"MainPage Start PrepareForNewGame~~~~~~~~~~~~~~"); Application.Current.Properties["CurrentStep"] = 0; isGameInProgress = false; isGameStart = false; //boardLayout.NewGameInitialize(); int step = CurrentBoard.Step; for (int i = 0; i < step; i++) { int lenght = boardLayout.Children.Count; boardLayout.Children.RemoveAt(lenght - 1); } boardLayout.DownTiles.Clear(); CurrentBoard = new Board(); BoardList.Clear(); timeLabel.Text = new TimeSpan(0).ToString(ConstClass.TimeFormat); msgLb.Text = ""; msgLb.TextColor = Color.Black; } catch (Exception ex) { Debug.WriteLine(StaticClass.LogException("PrepareForNewGame", ex)); } }
public void ChangeTileStatus(TileStatus status) { try { Debug.WriteLine($"Tile: ChangeTileStatus {Tilestatus} to {status}"); Tilestatus = status; var source = emptyImageSource; switch (status) { case TileStatus.Empty: source = emptyImageSource; break; case TileStatus.Black: source = blackImageSource; break; case TileStatus.White: source = whiteImageSource; break; case TileStatus.BlackGB: source = gbXImageSource; break; case TileStatus.WhiteGB: source = gbOImageSource; break; } Device.BeginInvokeOnMainThread(async() => { await ChangeSource(source); }); //Device.BeginInvokeOnMainThread(() => //{ //TileImage.SetValue(Image.SourceProperty, source); //Debug.WriteLine($"Tile: empty {emptyImageSource.Id} black {blackImageSource.Id} white {whiteImageSource.Id}"); //}); Debug.WriteLine($"Tile: ChangeTileStatus [{X},{Y}] ButtonStatus:{status } TileImage {source.Id}"); } catch (Exception ex) { Debug.WriteLine(StaticClass.LogException("ChangeTileStatus", ex)); } }
private Point GetNextStep(Board board) { Point point = new Point(); try { hepler = new GoBangHepler(board); PieceInfo pieceInfo = hepler.AIGetNext(board); string str = $"NextPiece: x:{pieceInfo.X + 1} y:{pieceInfo.Y + 1} "; //msgLb.Text = str; point.X = pieceInfo.X; point.Y = pieceInfo.Y; } catch (Exception ex) { Debug.WriteLine(StaticClass.LogException("GetNextStep", ex)); } return(point); }
void BoardTileChanged(BoardLayout boardLayout, Tile tile) { try { if (boardLayout == null) { return; } var board = CurrentBoard.ChangeBoard(tile.X, tile.Y, CurrentBoard.Step + 1); if (!BoardList.Exists(a => a.Step == board.Step)) { Application.Current.Properties["CurrentStep"] = board.Step; CurrentBoard = board; BoardList.Add(CurrentBoard); ChangeLastImage(tile); //判断是否胜 if (CurrentBoard.Step > 5 && CurrentBoard.IsWin) { boardLayout.IsGameStart = isGameStart = false; msgLb.Text = $"[{CurrentBoard.Colour}] IsWin! Start A New Game."; msgLb.TextColor = Color.Red; return; } Task.Run(() => { Device.BeginInvokeOnMainThread(() => { DoAI(); }); }); } else { Debug.WriteLine($"MainPage: BoardTileChanged Err [{tile.X},{tile.Y}] TileStep:{CurrentBoard.Step}"); } } catch (Exception ex) { Debug.WriteLine(StaticClass.LogException("BoardTileChanged", ex)); } }