コード例 #1
0
 void Awake()
 {
     buildingFirstIndex = new Index();
     buildingLastIndex  = new Index();
     selectedTiles      = new SelectedTiles();
     constructionMode   = false;
 }
コード例 #2
0
        public static void SelectTile(int xPos, int yPos, TileTab tab, int clicks)
        {
            var ti            = TileHandler.GetTileImage(tab);
            var tileSize      = ti.TileSize;
            int originalIndex = TileHandler.GetTileIndex(xPos, yPos, tab);
            int index         = ti.ColumnsPerRow * yPos + xPos;

            if (xPos >= ti.Image.Width / tileSize || yPos >= ti.Image.Height / tileSize)
            {
                return;
            }

            if (clicks == 1)
            {
                if (SelectedTiles.Contains(index))
                {
                    SelectedTiles.Remove(index);
                }
                else
                {
                    SelectedTiles.Add(index);
                }
            }
            else
            {
                switch (tab)
                {
                case TileTab.Source: { TileHandler.SelectedTile = originalIndex; break; }

                case TileTab.Randomized: { TileHandler.SelectedTile = RandomizedMap[xPos, yPos]; break; }

                case TileTab.RuleTest: { TileHandler.SelectedTile = RuleTestMap[xPos, yPos]; break; }
                }
            }
        }
コード例 #3
0
 public static void SelectAll(TileTab tab)
 {
     DeselectAll(tab);
     for (int i = 0; i <= GetTileImage(tab).NumberOfTiles - 1; i++)
     {
         SelectedTiles.Add(i);
     }
 }
コード例 #4
0
 /// <summary>
 /// Clear current selectin
 /// </summary>
 void ClearSelection()
 {
     foreach (GameObject obj in SelectedTiles)
     {
         RemoveSelection(obj.transform);
     }
     SelectedTiles.Clear();
 }
コード例 #5
0
        public void OnTileClicked(object sender, MahjongTile ClickedTile)
        {
            SelectedTiles.Add(ClickedTile);

            if (SelectedTiles.Count == 2)
            {
                if (SelectedTiles[0] == SelectedTiles[1])
                {
                    SelectedTiles.RemoveAt(1);
                    return;
                }

                int x1 = SelectedTiles[0].TileVector.X;
                int y1 = SelectedTiles[0].TileVector.Y;
                int z1 = SelectedTiles[0].TileVector.Z;
                int x2 = SelectedTiles[1].TileVector.X;
                int y2 = SelectedTiles[1].TileVector.Y;
                int z2 = SelectedTiles[1].TileVector.Z;

                bool FirstTileAccessible  = TileStore[x1 - 1, y1, z1] == null || TileStore[x1 + 1, y1, z1] == null;
                bool SecondTileAccessible = TileStore[x2 - 1, y2, z2] == null || TileStore[x2 + 1, y2, z2] == null;
                bool SameTile             = SelectedTiles[0].GetTileIndex() == SelectedTiles[1].GetTileIndex();

                if (FirstTileAccessible && SecondTileAccessible && SameTile)
                {
                    Console.WriteLine("Tile able to destroy");
                }
                else
                {
                    SelectedTiles[0].IsHovered = false;
                    SelectedTiles[0].IsClicked = false;
                    SelectedTiles[0].TileCanvas.Invalidate();
                    SelectedTiles[1].IsHovered = false;
                    SelectedTiles[1].IsClicked = false;
                    SelectedTiles[1].TileCanvas.Invalidate();
                    SelectedTiles.Clear();
                    return;
                }

                WindowHandle.Controls.Remove(SelectedTiles[0].TileCanvas);
                WindowHandle.Controls.Remove(SelectedTiles[1].TileCanvas);

                TileStore[x1, y1, z1] = null;
                TileStore[x2, y2, z2] = null;

                SelectedTiles.Clear();

                if (!CheckForCompletition())
                {
                    WindowHandle.PopulateBoard(WindowHandle);
                }
            }
        }
コード例 #6
0
ファイル: GameManager.cs プロジェクト: MKrolikoski/AIGame
 public void SelectEnemyTile(Tile tile)
 {
     if (tile.unitOnTile.unitOwner != SelectedUnit.unitOwner)
     {
         SelectedTiles.ForEach(e => e.OnDeselect());
         if (tilesWithEnemies.Count > 0)
         {
             tilesWithEnemies = new List <Tile>();
         }
         tilesWithEnemies.Add(tile);
         CurrentGameState       = GameState.SELECTING_ENEMY_UNIT;
         selectedEnemyTileIndex = 0;
         SelectedTile           = tilesWithEnemies[selectedEnemyTileIndex];
         SelectedUnit.FaceDirection(SelectedTile.unitOnTile.transform.position);
     }
 }
コード例 #7
0
    /// <summary>
    /// Adds selection icon to tile and stores reference to it
    /// </summary>
    /// <param name="selection"></param>
    void AddSelection(Transform selection)
    {
        //Dequeue inactive object from queue
        GameObject newSelectionIcon = InactiveSelectionObjects.Dequeue();

        //Set object to active in scene
        newSelectionIcon.SetActive(true);
        //Sets new object to correct position
        newSelectionIcon.transform.position = selection.position;
        //Add new object to dictionary
        SelectedObjects.Add(selection, newSelectionIcon);
        //Add to active selection list
        ActiveSelectionIconObjects.Add(newSelectionIcon);
        //Add tile to current tiles selected
        SelectedTiles.Add(selection.gameObject);
    }
コード例 #8
0
 void Update()
 {
     //Checks if left mouse button was pressed
     if (Input.GetMouseButtonDown(0))
     {
         //Checks if mouse is currently over ui element
         if (!EventSystem.current.IsPointerOverGameObject())
         {
             //Raycast to check for collider under mouse
             RaycastHit2D hit  = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.down, 0.1f);
             int          hitx = (int)hit.transform.position.x;
             int          hity = (int)hit.transform.position.y;
             if (hit.collider != null)
             {
                 if (TileGenerator.GetTileAt(hitx, hity).ActiveTower != null)
                 {
                     //Checks if object is already selected
                     if (!SelectedObjects.ContainsKey(hit.collider.transform))
                     {
                         //Checks if holding shift to select multiple
                         if (!Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift))
                         {
                             if (SelectedTiles.Count > 0)
                             {
                                 //Clears previous selection if shift was not held down
                                 ClearSelection();
                             }
                         }
                         //Add new selection
                         AddSelection(hit.collider.transform);
                     }
                     //Object was already selected
                     else
                     {
                         //Removes selection
                         RemoveSelection(hit.collider.transform);
                         SelectedTiles.Remove(hit.collider.gameObject);
                     }
                 }
             }
         }
     }
 }
コード例 #9
0
 public static List <Tile> GetSelectedTiles()
 {
     return(SourceImages[SelectedSource].GetTiles().Where(t => SelectedTiles.Contains(t.Index)).ToList());
 }
コード例 #10
0
 public static void DeselectAll(TileTab tab)
 {
     SelectedTiles.Clear();
 }
コード例 #11
0
 void Awake()
 {
     selectedTiles = new SelectedTiles();
 }
コード例 #12
0
ファイル: Map.cs プロジェクト: hajimehoshi/shrimp
 public Command CreateSettingTilesCommand(int layerNumber, int x, int y, SelectedTiles selectedTiles,
     int dx, int dy)
 {
     Rectangle region = new Rectangle
     {
         X = x,
         Y = y,
         Width = selectedTiles.Width,
         Height = selectedTiles.Height,
     };
     int width = region.Width;
     int height = region.Height;
     if (dx < 0)
     {
         dx = -(-dx % width) + width;
     }
     if (dy < 0)
     {
         dy = -(-dy % height) + height;
     }
     Tile[] oldTiles = new Tile[region.Width * region.Height];
     int index = 0;
     for (int j = 0; j < height; j++)
     {
         for (int i = 0; i < width; i++)
         {
             if (0 <= i + x && i + x < this.Width &&
                 0 <= j + y && j + y < this.Height)
             {
                 oldTiles[index] = this.Layers[layerNumber][(y + j) * this.Width + (x + i)];
             }
             index++;
         }
     }
     Command command = new Command();
     command.Doing += delegate
     {
         bool isChanged = false;
         List<Tile> layer = this.Layers[layerNumber];
         Tile[] newTiles = selectedTiles.Tiles.ToArray();
         for (int j = 0; j < height; j++)
         {
             for (int i = 0; i < width; i++)
             {
                 if (0 <= i + x && i + x < this.Width &&
                     0 <= j + y && j + y < this.Height)
                 {
                     Tile tile = newTiles[((j + dy) % height) * width + ((i + dx) % width)];
                     int location = (j + y) * this.Width + (i + x);
                     if (layer[location] != tile)
                     {
                         layer[location] = tile;
                         isChanged = true;
                     }
                 }
             }
         }
         if (isChanged)
         {
             this.OnUpdated(new UpdatedEventArgs(this.GetProperty(_ => _.Tiles), region));
         }
     };
     command.Undoing += delegate
     {
         bool isChanged = false;
         List<Tile> layer = this.Layers[layerNumber];
         for (int j = 0; j < height; j++)
         {
             for (int i = 0; i < width; i++)
             {
                 if (0 <= i + x && i + x < this.Width &&
                     0 <= j + y && j + y < this.Height)
                 {
                     Tile tile = oldTiles[j * width + i];
                     int location = (j + y) * this.Width + (i + x);
                     if (layer[location] != tile)
                     {
                         layer[location] = tile;
                         isChanged = true;
                     }
                 }
             }
         }
         if (isChanged)
         {
             this.OnUpdated(new UpdatedEventArgs(this.GetProperty(_ => _.Tiles), region));
         }
     };
     return command;
 }