public List <NormalCell> GetNormalCells(string mapName, Size cellSize) { List <NormalCell> normalCellList = new List <NormalCell>(); Connect(); try { string query = "SELECT * FROM Cell WHERE MapName = @MapName AND NormalCell = 1"; using (command = new SqlCommand(query, SQLcon)) { command.Parameters.Add(new SqlParameter("@MapName", mapName)); reader = command.ExecuteReader(); while (reader.Read()) { NormalCell wc = new NormalCell(ConvertDataToPoint(reader["Coordinaten"].ToString()), cellSize); normalCellList.Add(wc); } } } catch (Exception e) { throw new Exceptions.QueryFailedException(e.Message); } Close(); return(normalCellList); }
public IEnumerator PowerUp_Review() { #region Prepare IObjectStorage objectStorage = new ObjectStorage(); ISpawnManager spawnManager = new SpawnManager(objectStorage); #endregion yield return(new WaitForSeconds(0.5f)); #region Prepare Cell and Output to Screen Vector3 position = new Vector3(0, 0, 0); ICell cell = new NormalCell(0, 0); foreach (PowerUpTypesEnum powerUp in System.Enum.GetValues(typeof(PowerUpTypesEnum))) { cell.CurrentGameObject = spawnManager.SpawnPowerPrefab(powerUp, position); yield return(new WaitForSeconds(0.5f)); GameObject.Destroy(cell.CurrentGameObject); } #endregion }
public ICell SpawnNormalCell(Vector3 position) { GameObject newGameObject = _objectStorage.GetRandomGameElement(); ICell newNormalCell = new NormalCell((int)position.x, (int)position.y); _objectSetter.SetGameObject(newGameObject, position); _objectSetter.SetNormalCell(newNormalCell as INormalCell, newGameObject); return(newNormalCell); }
public ICell SpawnNormalCell(GameElementTypesEnum gameElement, Vector3 position) { GameObject newGameObject = SpawnPrefab(gameElement, position); ICell newNormalCell = new NormalCell((int)position.x, (int)position.y); newNormalCell.CurrentGameObject = newGameObject; return(newNormalCell); }
public ICell SpawnRandomNormalCell(Vector3 position) { GameObject newGameObject = SpawnRandomPrefab(position); ICell newNormalCell = new NormalCell((int)position.x, (int)position.y); newNormalCell.CurrentGameObject = newGameObject; return(newNormalCell); }
public void Execute() { for (int i = 0; i < vertices.Length; ++i) { int3 hash = Hash(vertices[i], cellSize); NormalCell item; if (normalCells.TryGetValue(hash, out item)) { item.AddNormal(normals[i]); } else { item = new NormalCell(normals[i]); } normalCells.Remove(hash); normalCells.TryAdd(hash, item); } }
//查找身后三格内的最大点数格(至少大于+2),如果没有,则查找是否有非道具格 //都找不到,则返回Failure public override TaskStatus OnUpdate() { Dictionary <int, GameObject> cellDic = manager.cellDic; List <NormalCell> normalCells = new List <NormalCell>(); int noPointCellIndex = 0; int startIndex = Utility.GetVaildIndex(player.curCellIndex - 1, cellDic.Count); for (int i = 0; i < 3; i++) { NormalCell normalCell = cellDic[startIndex].GetComponent <NormalCell>(); if (normalCell != null && normalCell.extraPoint > 2) { normalCells.Add(normalCell); } else if (normalCell == null) { noPointCellIndex = startIndex; } startIndex = Utility.GetVaildIndex(startIndex - 1, cellDic.Count); } if (normalCells.Count > 0) { normalCells = normalCells.OrderByDescending(n => n.extraPoint).ToList(); onCell.SetData(normalCells[0].index, 1, 1, 0); useProp.placeIndex = normalCells[0].index; } else if (noPointCellIndex != 0) { onCell.SetData(noPointCellIndex, 1, 1, 0); useProp.placeIndex = noPointCellIndex; } else { return(TaskStatus.Failure); } return(TaskStatus.Success); }
public override TaskStatus OnUpdate() { player = gmTask.player; Dictionary <int, GameObject> cellDic = manager.cellDic; int startIndex = Utility.GetVaildIndex(player.curCellIndex + stride, cellDic.Count); //查找范围内中第一个非负数格 for (int i = 0; i < area; i++) { NormalCell normalCell = cellDic[startIndex].GetComponent <NormalCell>(); if (normalCell == null || normalCell.extraPoint > 0) { p2.placeIndex = startIndex; onCell.SetData(startIndex, 1, -1, 0); return(TaskStatus.Success); } startIndex = Utility.GetVaildIndex(startIndex + stride, cellDic.Count); } //无法放置,使检测脚本从自身开始,保证返回failure onCell.area = 1; return(TaskStatus.Failure); }
//获取颜色格内容方法,在移动结束后调用 public void GetCellContent() { extraPoint = 0; //做射线检测(忽略Player层),获取当前格子引用 RaycastHit2D hit = DoLinecast(11, transform.up, true); if (hit.transform != null) { //获取当前格子ID和tag GameObject currentCell = hit.transform.gameObject; string cellTag = currentCell.tag; Cell cell = Utility.GetCellScriptByTag(currentCell); curCellIndex = cell.index; //计算到终点距离 CalculateDistacnFromFinal(); //停留点不是终点格,取消backToFinal if (!Utility.IsTypeOf <FinalCell>(cell)) { backToFinal = false; } //否则,与终点距离+52 else { distanceFromFinal += 52; } //停留在普通格,获取点数 if (Utility.IsTypeOf <NormalCell>(cell)) { NormalCell normalCell = currentCell.GetComponent <NormalCell>(); if (normalCell != null) { UpdateExtraPoint(normalCell.extraPoint); } StartCoroutine(GetCellEffect(InitNormalCells.pointSpriteDic[normalCell.extraPoint])); } //停留在道具格,获取道具 else if (Utility.IsTypeOf <Cell>(cell)) { extraPointText.ClearExtraPointText(); UpdatePropAmount(cellTag, 1); StartCoroutine(GetCellEffect(InitPropsCells.propSpriteDic[cell.tag])); } //停留在三角格 else if (Utility.IsTypeOf <TriCell>(cell)) { //如果当前方向不是三角格旋转方向,取消needRotate //用于处理倒退恰好停在三角格情况 TriCell triCell = currentCell.GetComponent <TriCell>(); if (moveDir != triCell.clockwideDir && moveDir != triCell.antiClockwideDir) { needRotate = false; } //执行三角格上对应的脚本 DoTriCellFunc(currentCell); } } }
public void RegistrateNormalCell(NormalCell cell) { cell.Notifier = _gameplayNotifier; _updateManager.AddUpdatable(cell); }
public IEnumerator PowerUp_UseTwoPowerUp_Review(PowerUpTypesEnum powerUpTypeEnumA, PowerUpTypesEnum powerUpTypeEnumB) { #region Create Managers IMasterManager masterManager; ICellRegistrator cellRegistrator; IBoard board = ObjectsCreator.CreateBoard(9, 9, out masterManager, out cellRegistrator); IUpdateManager updateManager = masterManager.UpdateManager; IGameplayLogicManager gameplayLogicManager = ObjectsCreator.CreateGameplayLogicManager(); INotifier gameplayNotifier = masterManager.GameplayNotifier; ISpawnManager spawnManager = masterManager.SpawnManager; IInputManager inputManager = new InputManager(gameplayNotifier); ICheckManager checkManager = new CheckManager(); #endregion #region Create And SetUp Cells with PowerUp IList <ICell> cellsWithPowerUp = new List <ICell>(); IList <Vector3> positions = new List <Vector3>(); switch (powerUpTypeEnumA) { case PowerUpTypesEnum.Bomb: positions.Add(new Vector2(4, 4)); positions.Add(new Vector2(2, 4)); break; case PowerUpTypesEnum.Vertical: positions.Add(new Vector2(3, 3)); positions.Add(new Vector2(3, 6)); break; case PowerUpTypesEnum.Horizontal: positions.Add(new Vector2(3, 3)); positions.Add(new Vector2(6, 3)); break; } for (int i = 0; i < 2; i++) { ICell cell = new NormalCell((int)positions[i].x, (int)positions[i].y); Vector3 cellPosition = new Vector2((int)positions[i].x, (int)positions[i].y); cell.CurrentGameObject = spawnManager.SpawnPowerPrefab(i == 0 ? powerUpTypeEnumA : powerUpTypeEnumB, positions[i]); cellRegistrator.RegistrateNormalCell(cell as NormalCell); board.Cells[cell.TargetX, cell.TargetY] = cell; cellsWithPowerUp.Add(cell); } #endregion yield return(new WaitForSeconds(0.1f)); #region SetUp Board and Managers board.Initial(); checkManager.Board = board; gameplayLogicManager.Board = board; gameplayLogicManager.CheckManager = checkManager; gameplayLogicManager.SpawnManager = spawnManager; gameplayLogicManager.Notifier = new Notifier(); inputManager.AddSubscriber(gameplayLogicManager); updateManager.AddUpdatable(inputManager as IUpdatable); updateManager.IsUpdate = true; #endregion yield return(new WaitForSeconds(0.3f)); #region Try Use PowerUp int swipeCount = 2; gameplayLogicManager.TryCheckSwipedCells(cellsWithPowerUp[0], swipeCount); #endregion #region Remove From Scene yield return(new WaitForSeconds(2f)); updateManager.IsUpdate = false; foreach (var cell in board.Cells) { GameObject.Destroy(cell.CurrentGameObject); } #endregion }
public IEnumerator PowerUp_UseOnePowerUp_Review(PowerUpTypesEnum powerUpTypeEnum) { #region Create Managers IMasterManager masterManager; ICellRegistrator cellRegistrator; IBoard board = ObjectsCreator.CreateBoard(9, 9, out masterManager, out cellRegistrator); IUpdateManager updateManager = masterManager.UpdateManager; IGameplayLogicManager gameplayLogicManager = ObjectsCreator.CreateGameplayLogicManager(); INotifier gameplayNotifier = masterManager.GameplayNotifier; ISpawnManager spawnManager = masterManager.SpawnManager; IInputManager inputManager = new InputManager(gameplayNotifier); ICheckManager checkManager = new CheckManager(); #endregion #region Create And SetUp Cell with PowerUp ICell cellWithPowerUp = new NormalCell(4, 4); Vector3 cellPosition = new Vector2(4, 4); cellWithPowerUp.CurrentGameObject = spawnManager.SpawnPowerPrefab(powerUpTypeEnum, cellPosition); cellRegistrator.RegistrateNormalCell(cellWithPowerUp as NormalCell); board.Cells[cellWithPowerUp.TargetX, cellWithPowerUp.TargetY] = cellWithPowerUp; #endregion yield return(new WaitForSeconds(0.1f)); #region SetUp Board and Managers board.Initial(); checkManager.Board = board; gameplayLogicManager.Board = board; gameplayLogicManager.CheckManager = checkManager; gameplayLogicManager.SpawnManager = spawnManager; gameplayLogicManager.Notifier = new Notifier(); inputManager.AddSubscriber(gameplayLogicManager); updateManager.AddUpdatable(inputManager as IUpdatable); updateManager.IsUpdate = true; #endregion yield return(new WaitForSeconds(0.3f)); #region Try Use PowerUp int swipeCount = 2; gameplayLogicManager.TryCheckSwipedCells(cellWithPowerUp, swipeCount); #endregion #region Remove From Scene yield return(new WaitForSeconds(2f)); updateManager.IsUpdate = false; foreach (var cell in board.Cells) { GameObject.Destroy(cell.CurrentGameObject); } #endregion }
public IEnumerator Cells_TryCheck(int equalsCellsCount, bool isVertical) { #region Create Managers And Board IMasterManager masterManager; ICellRegistrator cellRegistrator; IBoard board = ObjectsCreator.CreateBoard(equalsCellsCount + 3, equalsCellsCount + 3, out masterManager, out cellRegistrator); IUpdateManager updateManager = masterManager.UpdateManager; IGameplayLogicManager gameplayLogicManager = ObjectsCreator.CreateGameplayLogicManager(); INotifier gameplayNotifier = masterManager.GameplayNotifier; ISpawnManager spawnManager = masterManager.SpawnManager; IInputManager inputManager = new InputManager(gameplayNotifier); ICheckManager checkManager = new CheckManager(); #endregion #region Create Cells int startX = 2; int startY = 2; ICell swipedCell = null; for (int i = 0; i < equalsCellsCount; i++) { int x = startX; int y = startY; if (isVertical) { if (i == Mathf.Floor(equalsCellsCount / 2)) { x = startX + 1; } else { x = startX; } y = startY + i; } else { if (i == Mathf.Floor(equalsCellsCount / 2)) { y = startY + 1; } else { y = startY; } x = startX + i; } ICell cell = new NormalCell(x, y); cell.CurrentGameObject = spawnManager.SpawnPrefab(GameElementTypesEnum.RedCircle, new Vector3(x, y, 0)); cellRegistrator.RegistrateNormalCell(cell as NormalCell); board.Cells[cell.TargetX, cell.TargetY] = cell; if (i == Mathf.Floor(equalsCellsCount / 2)) { swipedCell = board.Cells[cell.TargetX, cell.TargetY]; } } #endregion yield return(new WaitForSeconds(1f)); #region SetUp Board And Managers board.Initial(); checkManager.Board = board; gameplayLogicManager.Board = board; gameplayLogicManager.CheckManager = checkManager; gameplayLogicManager.SpawnManager = spawnManager; gameplayLogicManager.Notifier = masterManager.UINotifier; inputManager.AddSubscriber(gameplayLogicManager); updateManager.AddUpdatable(inputManager as IUpdatable); updateManager.IsUpdate = true; #endregion yield return(new WaitForSeconds(1f)); #region Create And SetUp MacroCommand to use swap cells ICommand[] commands; if (isVertical) { commands = new ICommand[] { new SwipeLeftCommand(swipedCell), new SwipeRightCommand(board.Cells[swipedCell.TargetX - 1, swipedCell.TargetY]), }; } else { commands = new ICommand[] { new SwipeDownCommand(swipedCell), new SwipeUpCommand(board.Cells[swipedCell.TargetX, swipedCell.TargetY - 1]), }; } ICommand macroCommand = new MacroCommand(commands); gameplayLogicManager.MacroCommand = macroCommand; #endregion #region Try Swap Cells and get Check gameplayLogicManager.MacroCommand.Execute(); yield return(new WaitForSeconds(1f)); gameplayLogicManager.TryCheckSwipedCells(swipedCell); #endregion #region Remove From Scene yield return(new WaitForSeconds(0.2f)); updateManager.IsUpdate = false; foreach (var boadrdCell in board.Cells) { updateManager.RemoveUpdatable(boadrdCell as IUpdatable); } foreach (var cell in board.Cells) { GameObject.Destroy(cell.CurrentGameObject); } #endregion }
public void NormalCell_Create_NotNull() { ICell normalCell = new NormalCell(0, 0); Assert.IsNotNull(normalCell); }