public override void Initialize() { BoardRectangle = boardRectangle = boardRect; boardTexture = curGame.LoadContent <Texture2D>(@"Images\Board"); debugFont = curGame.LoadContent <SpriteFont>(@"Fonts\TitleFont"); int pieceSize = boardRect.Width / ReversiGame.BoardSize; for (int i = 0; i < ReversiGame.BoardSize; i++) { for (int j = 0; j < ReversiGame.BoardSize; j++) { pieces[i, j] = CreateChild <Piece, Rectangle>( new Rectangle( boardRect.X + pieceSize * i, boardRect.Y + pieceSize * j, pieceSize, pieceSize)); } } IsInitializing = true; // 如果有上一局棋, 则清除上一局棋盘 if (reversiGame != null) { pieces[reversiGame.LastPosition.X, reversiGame.LastPosition.Y].IsLastPiece = false; } // 创建一个新游戏 reversiGame = ReversiGame.CreateANewGame(); // 创建玩家 for (int i = 0; i < 2; i++) { if (PlayerSettings.Player[i].Type == PlayerTypes.Human) { player[i] = CreateChild <Human, Rectangle, Piece[, ], ReversiPiece>(boardRectangle, pieces, i == 0 ? ReversiPiece.Black : ReversiPiece.White); } else if (PlayerSettings.Player[i].Type == PlayerTypes.AI) { player[i] = CreateChild <AI, Rectangle, Piece[, ], ReversiPiece>(boardRectangle, pieces, i == 0 ? ReversiPiece.Black : ReversiPiece.White); ((AI)(player[i])).SetAIType(PlayerSettings.Player[i].AIIndex); } } // 请求刷新棋盘 DebugText = ""; boardState = BoardState.FreshGame; IsInitializing = false; base.Initialize(); }
/// <summary> /// 执行棋局初始化操作 (包括新建棋局实例, 新建人工智能实例. 必要时执行自动下棋操作.) /// </summary> public void InitializeGame(ReversiPiece userPiece, int AIIndex, WhenGameOver gameOver) { InitialControls(); whenGameOver = gameOver; reversiGame = ReversiGame.CreateANewGame(); HumanPieceType = userPiece; UpdateWindow(); reversiAI = ReversiAIType.GetAI(AIIndex); changeWaitingState(WaitingState.NotWaiting); if (HumanPieceType == ReversiPiece.White) { reversiAI.AIInitialize(ReversiPiece.Black); MovePiece(); DoEvents(); } else { reversiAI.AIInitialize(ReversiPiece.White); } ShowNextEnabledPieces(); isInitialized = true; IsUserTurn = true; }