void Start() { GameEventManager.Initialize(); mBags = new List <Bag>(2); mBoard = mBoardObject.GetComponent <Board>(); mBoard.Initialize(kBoardSize); // Init shared game data. BoardController boardController = mBoard.Controller; Debug.Log("board controller " + boardController.ToString()); DominoGenerator generator = new DominoGenerator(boardController.StartPosition, mDominoObject); Debug.Log("board controller" + generator.ToString()); GamePlayManager.Initialize(); GamePlayManager.Instance.Init(generator, mBoard.Controller, mDominoObject); // init draw bags { Bag bag = new Bag(kNumSlots, mBoard.Controller.Size, true); for (int i = 0; i < kNumSlots; i++) { Domino d = GamePlayManager.Instance.GetNextDomino(); d.EnableGraphics(mBoard.Controller.Size); bag.AddDomino(d); } mBags.Add(bag); } { Bag bag = new Bag(kNumSlots, mBoard.Controller.Size, false); for (int i = 0; i < kNumSlots; i++) { Domino d = GamePlayManager.Instance.GetNextDomino(); d.EnableGraphics(mBoard.Controller.Size); d.UpdateDominoLocation(mBoard.Controller.Size); bag.AddDomino(d); } mBags.Add(bag); } ActiveDomino = GamePlayManager.Instance.GetNextDomino().GetComponent <Domino>(); if (mActiveDomino != null) { mActiveDomino.MakeActive(); } mDominos.Add(ActiveDomino); ActiveDomino.EnableGraphics(mBoard.Controller.Size); ActiveDomino.SetHighlight(HighLightMode.Active); }
void HandleUp(Vector2 mousePosition) { if (ActiveDomino != null) { if (!LocationIsInBoard(ActiveDomino.Controller.Row, ActiveDomino.Controller.Column, ActiveDomino.Controller.IsHorizontal())) { Bag activeBag = GetActiveBag(); activeBag.AddDomino(ActiveDomino); // No longer active on board, set to null. ActiveDomino = null; // Leave active. } } }
void Update() { GameEventManager.Instance.Activity(); if (GamePlayManager.Instance.Player1Playing && !GamePlayManager.Instance.Player1Computer) { //Debug.Log("play"); HandleMouseInput(); } else if ((!GamePlayManager.Instance.Player1Playing) && !GamePlayManager.Instance.Player2Computer) { //Debug.Log("Player 2 move"); HandleMouseInput(); } // Either the user or the computer has added a new Domino if (GamePlayManager.Instance.PickNewDomino && ((Time.time - mTimeStamp) > kWaitingTime)) { //draw into previous bag // before the change over Bag bag = GetActiveBag(); ActiveDomino = null; if (bag.HasEmptySlot()) { Debug.Log("Add new domino"); Domino domino = GamePlayManager.Instance.GetNextDomino(); domino.EnableGraphics(mBoard.Controller.Size); bag.AddDomino(domino); //check there's a legal move in that bag List <IDomino> cloneDominoes = CloneBag(bag); GamePlayManager.Instance.CheckForGameOver(cloneDominoes); DestroyBag(cloneDominoes); } else { Debug.Log("First move, no draw"); } GamePlayManager.Instance.DoneWithDraw(); ChangePlayer(); // check if the game is over // highlight for visibility //mDomino.SetHighlight(Domino.HighLightMode.Active); GamePlayManager.Instance.GameOnHold = false; if (GamePlayManager.Instance.GameOver) { Debug.Log("Game over"); // move this back to the game screen - graphics belong in the screen // not the game play logic int score1 = mBoard.Controller.CalculatePlayer1Score(); int score2 = mBoard.Controller.CalculatePlayer2Score(); if (score1 > score2) { this.InfoText = "Game Over: " + mPlayer1Name + " wins!"; } else if (score2 > score1) { this.InfoText = "Game Over: " + mPlayer2Name + " wins!"; } else { this.InfoText = "Game Over: Draw"; } } mTimeStamp = Time.time; } //Computer's Turn if (!GamePlayManager.Instance.GameOnHold && !GamePlayManager.Instance.HumanPlayer && !GamePlayManager.Instance.GameOver && ((Time.time - mTimeStamp) > kWaitingTime)) { ComputerMove(); } }
void Start() { GameEventManager.Initialize(); mBags = new List<Bag>(2); mBoard = mBoardObject.GetComponent<Board>(); mBoard.Initialize(kBoardSize); // Init shared game data. BoardController boardController = mBoard.Controller; Debug.Log("board controller " + boardController.ToString()); DominoGenerator generator = new DominoGenerator(boardController.StartPosition, mDominoObject); Debug.Log("board controller" + generator.ToString()); GamePlayManager.Initialize(); GamePlayManager.Instance.Init(generator, mBoard.Controller, mDominoObject); // init draw bags { Bag bag = new Bag(kNumSlots, mBoard.Controller.Size, true); for (int i = 0; i < kNumSlots; i++) { Domino d = GamePlayManager.Instance.GetNextDomino(); d.EnableGraphics(mBoard.Controller.Size); bag.AddDomino(d); } mBags.Add(bag); } { Bag bag = new Bag(kNumSlots, mBoard.Controller.Size, false); for (int i = 0; i < kNumSlots; i++) { Domino d = GamePlayManager.Instance.GetNextDomino(); d.EnableGraphics(mBoard.Controller.Size); d.UpdateDominoLocation(mBoard.Controller.Size); bag.AddDomino(d); } mBags.Add(bag); } ActiveDomino = GamePlayManager.Instance.GetNextDomino().GetComponent<Domino>(); if (mActiveDomino != null) { mActiveDomino.MakeActive(); } mDominos.Add(ActiveDomino); ActiveDomino.EnableGraphics(mBoard.Controller.Size); ActiveDomino.SetHighlight(HighLightMode.Active); }