/// <summary> /// новый ход /// </summary> /// <param name="myTurn"><c>true</c> - мой ход</param> /// <param name="capturedCell">захваченная ячейка соперником, надо отобразить на своем поле</param> /// <param name="graphic">Символ соперника</param> void NewTurn(bool myTurn, int capturedCell, CellSymbol graphic) { _myTurn = myTurn; if (_myTurn) { _ui.ShowMsg("Ваш ход"); } else { _ui.ShowMsg("Ход соперника"); } if (capturedCell != -1) { Cell cell = ( from c in _allCells where c.index == capturedCell select c ).Single <Cell> (); cell.ShowXO(graphic); ///если ход сделал клиент, тогда на стороне сервера проверяем условия выиграша if (_playerType == PlayerType.SERVER) { ChekForWinner(); } } }
/// <summary> /// сброс в начальное состояние /// </summary> public void Reset() { _isUsed = false; _sr.sprite = null; _symbol = CellSymbol.NONE; Highlight(false); }
/// <summary> /// отображает указанный символ /// </summary> /// <param name="symbol">символ</param> public void ShowXO(CellSymbol symbol) { _sr.sprite = ( from g in allSymbols where g.symbol == symbol select g.sprite ).Single <Sprite> (); _isUsed = true; _symbol = symbol; }
public void setCell() { if (GameManager.Instance.GameController.CurrentTurn == PlayerSymbol.X) { x.SetActive(true); cellAssignedSymbol = CellSymbol.X; } else { o.SetActive(true); cellAssignedSymbol = CellSymbol.O; } button.interactable = false; GameManager.Instance.GameController.UpdateTurn(this); }
public void ResetCell() { cellAssignedSymbol = CellSymbol.EMPTY; x.SetActive(false); o.SetActive(false); }
private IEnumerator ProccedMove() { isThinking = true; Debug.Log("Starting thing"); yield return(new WaitForSeconds(1)); int x = (int)transform.position.x; int y = (int)transform.position.y; if (world.levelMap.GetTile(new Vector3Int(x, y, (int)world.levelMap.transform.position.z)) == null || world.entitiesMap.GetTile(new Vector3Int(x, y, (int)world.entitiesMap.transform.position.z)) == world.wampus) { Debug.LogError("Failure"); IsGameEnd = true; IsLoose = true; } Debug.Log("Percepted: " + String.Join(", ", percepted)); CellSymbol wind = new CellSymbol(x, y, Symbol.Wind); if (percepted.Contains(Symbol.Wind)) { brain.Tell(wind); } else { brain.Tell(new Not(wind)); } CellSymbol stench = new CellSymbol(x, y, Symbol.Stench); if (percepted.Contains(Symbol.Stench)) { brain.Tell(stench); } else { brain.Tell(new Not(stench)); } CellSymbol glitter = new CellSymbol(x, y, Symbol.Glitter); if (percepted.Contains(Symbol.Glitter)) { brain.Tell(glitter); Debug.Log("WIN!"); IsGameEnd = true; IsWin = true; } // add visited cells AddReachable(x, y); Cell currCell = new Cell(x, y); visited.Add(currCell); // if nothing in this cell, then neighbours is safe if (percepted.Count == 0) { foreach (Cell cell in getValuableNeighbours(x, y)) { if (!visited.Contains(cell)) { safeCells.Add(cell); } } } else // add all neighbours, which not in visited or safe { foreach (Cell cell in getValuableNeighbours(x, y)) { if (!visited.Contains(cell) && !safeCells.Contains(cell)) { dangerousCells.Add(cell); } } } percepted.Clear(); int z = (int)transform.position.z; if (!IsGameEnd) { // Find next cell in safe cells else think about dangerous if (safeCells.Count > 0) { Cell nextCell = null; foreach (Cell safeCell in safeCells) { nextCell = safeCell; break; } path = pathTo(nextCell, currCell); if (path == null) { Debug.LogError("Empty path for safe cell. From: " + currCell + "; to: " + nextCell); path = new Queue <Cell>(); } path.Dequeue(); safeCells.Remove(nextCell); isThinking = false; } else { Task task = new Task(() => { Cell nextCell = tryToFindNextCellInDangerous(); if (nextCell != null) { positionToMove = new Vector3Int(nextCell.x, nextCell.y, z); Debug.Log("Next move! " + positionToMove); ++StepCount; isThinking = false; } else { Debug.Log("End of game"); IsGameEnd = true; } }); task.Start(); } } }