public void OnPointerClick(PointerEventData eventData) { if (IsRunning) { return; } // If we are dragging, OnEndDrag will be called after OnPointerClick, // so IsDragging will be set. if (IsDragging) { return; } BoardPosition pos = FindPosition(eventData); //Debug.LogFormat("OnPointerClick: {0}", pos); if (!MouseDownPos.Equals(pos)) { return; } if (pos.place == BoardPosition.Place.BOARD) { // Click on board. LClick rotate forward, RClick rotate backward. Board.Cell currentCell = TheBoard[pos]; if (eventData.button == PointerEventData.InputButton.Left) { SetBoardAndTile(pos, currentCell.RotateForward()); } else if (eventData.button == PointerEventData.InputButton.Right) { SetBoardAndTile(pos, currentCell.RotateBackward()); } } }
public void OnEndDrag(PointerEventData eventData) { if (IsRunning) { return; } if (!IsDragging) { return; } BoardPosition pos = FindPosition(eventData); //Debug.LogFormat("OnEndDrag: {0}", pos); if (pos.place == BoardPosition.Place.BOARD) { // Drop in board Board.Cell targetCell = TheBoard[pos]; if (targetCell.IsEmpty()) { // Set item at target position SetBoardAndTile(pos, DraggingCell); } else if (DraggingFrom.x != -999) { // Move from board if (!targetCell.IsMovable()) { // Cannot swap with immovable object, spring back to original position SetBoardAndTile(DraggingFrom, DraggingCell); } else { // There are something there and is movable, swap them SetBoardAndTile(DraggingFrom, targetCell); SetBoardAndTile(pos, DraggingCell); } } else { // Move from toolbox but dropped on something. Discard it. TheBoard.ReturnTool(DraggingCell); } } else { // Drop outside board, try to return the item to toolbox if (!TheBoard.ReturnTool(DraggingCell)) { // Item cannot be returned, spring back to original position (if there is) if (DraggingFrom.x != -999) { SetBoardAndTile(DraggingFrom, DraggingCell); } } } DragIcon.gameObject.SetActive(false); IsDragging = false; }
/// <summary> /// Find the corresponding Sprite of a certain item. /// </summary> /// <param name="cell">The item.</param> /// <returns>The Sprite.</returns> public static Sprite CellToSprite(Board.Cell cell) { int index = CellToSpriteIndex(cell); if (index == -1) { return(null); } return(SpriteTools[index]); }
/// <summary> /// Return an item to Toolbox. /// </summary> /// <param name="cell">The returned item.</param> /// <returns>Whether the item is successfully returned.</returns> public bool ReturnTool(Board.Cell cell) { for (int i = 0; i < Tools.Count; i++) { if (Tools[i].type == cell.type) { return(true); } } return(false); }
private void boardCell_VisibilityChanged(object sender, System.EventArgs e) { Board.Cell cell = sender as Board.Cell; if (cell != null) { int line = cell.Line; int col = cell.Col; m_BoardForm.CellsView.GetButtonAt(line, col).SetDisabled(cell.Selected); } }
public override bool GetTileAnimationData(Vector3Int position, ITilemap tilemap, ref TileAnimationData tileAnimationData) { Board.Cell mycell = TheBoard[(Vector2Int)position]; if (mycell.type != Board.CellType.OUTPUT) { return(false); } tileAnimationData.animatedSprites = OutputSprite; tileAnimationData.animationSpeed = 4f; tileAnimationData.animationStartTime = 0f; return(true); }
private void GetResult(Board.Cell coords, Player player) { var panel = GameBoard.Panels.At(coords.Row, coords.Column); CellFactory objCellFactory = new CellFactory(); var result = objCellFactory.CreateCell(panel.CellType); if (result != null) { Bank objBank = new Bank(); player.AddMoneyEarned(result.Amount); objBank.AddMoneyEarned(result.Amount); } }
public void OnBeginDrag(PointerEventData eventData) { if (IsRunning) { return; } if (eventData.button != PointerEventData.InputButton.Left) { return; } BoardPosition pos = MouseDownPos; // Use position when mouse is down, not start dragging //BoardPosition pos = FindPosition(eventData); //Debug.LogFormat("OnBeginDrag: {0}", pos); do { if (pos.place == BoardPosition.Place.TOOLBOX) { int toolID = pos.x; Board.Cell NewCell = TheBoard.TakeTool(toolID); if (!NewCell.IsEmpty()) { DraggingCell = NewCell; DraggingFrom = new Vector2Int(-999, -999); break; } } else if (pos.place == BoardPosition.Place.BOARD) { // Begin drag on a board Board.Cell cell = TheBoard[pos]; if (cell.IsMovable()) { DraggingCell = cell; DraggingFrom = pos; SetBoardAndTile(DraggingFrom, Board.EmptyCell); break; } } eventData.pointerDrag = null; return; } while (false); IsDragging = true; Sprite draggingSprite = BoardTile.CellToSprite(DraggingCell); DragIcon.gameObject.SetActive(true); DragIcon.GetComponent <SpriteRenderer>().sprite = draggingSprite; DragIcon.position = MainCamera.ScreenToWorldPoint((Vector3)eventData.position).SetZ(0); //Debug.LogFormat("OnBeginDrag: Event position = {0}", eventData.position)); }
private ConsoleColor GetCellColor(Board.Cell cell) { if (cell.IsError) { return(ConsoleColor.Red); } if (cell.IsFixed) { return(ConsoleColor.White); } return(ConsoleColor.Gray); }
public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData) { Board.Cell mycell = TheBoard[(Vector2Int)position]; int spriteIndex = CellToSpriteIndex(mycell); if (spriteIndex == -1) { tileData.sprite = null; } else { tileData.sprite = SpriteTools[CellToSpriteIndex(mycell)]; } tileData.color = Color.white; tileData.transform = Matrix4x4.identity; tileData.flags = 0; tileData.gameObject = null; }
public static Color GetColorFromType(Board.Cell cellType) { switch (cellType) { case Board.Cell.PlayerBlue: return(Color.blue); case Board.Cell.PlayerRed: return(Color.red); case Board.Cell.PlayerPurple: return(Color.magenta); case Board.Cell.PlayerYellow: return(Color.yellow); default: throw new Exception("Colors not available "); } }
/// <summary> /// Find the sprite index of a certain item. /// </summary> /// <param name="cell">The item.</param> /// <returns>The sprite index, -1 if not applicable for whatever reason.</returns> public static int CellToSpriteIndex(Board.Cell cell) { switch (cell.type) { case Board.CellType.GENERATOR: return((int)SpriteIndex.GEN_0 + cell.param); case Board.CellType.MIRROR: return((int)SpriteIndex.MIRROR_HORIZONTAL + cell.param); case Board.CellType.PROCESS: return((int)SpriteIndex.PROCESS_SPLIT); case Board.CellType.SLUICE: return((int)SpriteIndex.SLUICE_UP + cell.param); case Board.CellType.TARPIT: return((int)SpriteIndex.TARPIT_PLUS + cell.param); case Board.CellType.MODIFIER_BOOLEAN: return((int)SpriteIndex.MODIFIER_TRUE + cell.param); case Board.CellType.MODIFIER_COMPARE: return((int)SpriteIndex.MODIFIER_ZERO + cell.param); case Board.CellType.MODIFIER_PARITY: return((int)SpriteIndex.MODIFIER_ODD + cell.param); case Board.CellType.INPUT: return((int)SpriteIndex.INPUT_UP + cell.param); case Board.CellType.OUTPUT: return((int)SpriteIndex.OUTPUT1); case Board.CellType.WALL: return((int)SpriteIndex.WALL); default: return(-1); } }
Player GetPlayerAtCell(Board.Cell cell) { switch (cell) { case Board.Cell.PlayerRed: return(players[0]); case Board.Cell.PlayerPurple: return(players[1]); case Board.Cell.PlayerBlue: return(players[2]); case Board.Cell.PlayerYellow: return(players[3]); default: throw new Exception( "A célula do inimigo não tem um inimigo?" ); } }
public Choice(Board.Cell i_Cell) { r_Line = i_Cell.Line; r_Col = i_Cell.Col; }
protected override void WriteCellValue(Board.Cell cell, string value) { using var colorGuard = new ConsoleColorGuard(GetCellColor(cell)); base.WriteCellValue(cell, value); }
internal CellButton(int i_Row, int i_Column) { r_BoardLocation = new Board.Cell(i_Row, i_Column); }
/// <summary> /// Set a board position to a cell, and update the corresponding tile. /// </summary> /// <param name="pos">Position in the board.</param> /// <param name="cell">The content.</param> private void SetBoardAndTile(Vector2Int pos, Board.Cell cell) { TheBoard[pos] = cell; BoardTilemap.RefreshTile((Vector3Int)pos); }