Esempio n. 1
0
    public void refreshGridpositions()
    {
        Item [,] itemMap = GameManager.instance.itemMap;
        this.gridPositions.Clear();

        // exclude exit, exclude player position
        int exitx = itemMap.GetLength(0) - 1;
        int exity = itemMap.GetLength(1) - 1;
        int px    = (int)(GameManager.instance.player.transform.position.x / BoardManager.wMultiplier);
        int py    = (int)(GameManager.instance.player.transform.position.y / BoardManager.hMultiplier);

        for (int i = 0; i < itemMap.GetLength(0); i++)
        {
            for (int j = 0; j < itemMap.GetLength(1); j++)
            {
                if (!(i == exitx && j == exity) && !(i == px && j == py))
                {
                    if (itemMap[i, j] == null)
                    {
                        gridPositions.Add(new Vector3(i * wMultiplier, j * hMultiplier, 0f));
                    }
                }
            }
        }
    }
Esempio n. 2
0
        private static Node[,] BuildNodes(Item[,] matrix)
        {
            int height = matrix.GetLength(0);
            int width  = matrix.GetLength(1);

            Node[,] nodes = new Node[height, width];

            for (int rowIndex = 0; rowIndex < height; rowIndex++)
            {
                for (int colIndex = 0; colIndex < width; colIndex++)
                {
                    if (matrix[rowIndex, colIndex].Type.CompareTo(ItemType.Nothing) == 0 ||
                        matrix[rowIndex, colIndex].Type.CompareTo(ItemType.AISpawnPoint) == 0 ||
                        matrix[rowIndex, colIndex].Type.CompareTo(ItemType.PlayerSpawnPoint) == 0 ||
                        matrix[rowIndex, colIndex].Type.CompareTo(ItemType.Forrest) == 0)
                    {
                        nodes[rowIndex, colIndex] = new Node(rowIndex, colIndex, true);
                    }
                    else
                    {
                        nodes[rowIndex, colIndex] = new Node(rowIndex, colIndex, false);
                    }
                }
            }

            return(nodes);
        }
Esempio n. 3
0
 public void Clear()
 {
     for (int i = 0; i < Items.GetLength(0); i++)
     {
         for (int j = 0; j < Items.GetLength(1); j++)
         {
             Items[i, j] = new Item(RawItem.None, 0);
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Премества всички "чужди хора"
        /// </summary>
        /// <param name="field">поле</param>
        /// <param name="diamondsLeft">брой останали диаманти</param>
        static void MoveSomeGuys(Item[,] field, ref int diamondsLeft)
        {
            // взимаме размерите на полето
            int m = field.GetLength(0);
            int n = field.GetLength(1);

            // създаваме генератор на произволни числа
            var random = new Random();

            // обхождаме всички позиции в полето
            for (int y = 0; y < n; y++)
            {
                for (int x = 0; x < m; x++)
                {
                    // ако на съответната позиция има "чужд човек"
                    if (field[x, y] == Item.SomeGuy)
                    {
                        // избираме му произволна посока
                        Direction direction;

                        int num = random.Next(4);
                        if (num == 0)
                        {
                            direction = Direction.Up;
                        }
                        else if (num == 1)
                        {
                            direction = Direction.Right;
                        }
                        else if (num == 2)
                        {
                            direction = Direction.Down;
                        }
                        else
                        {
                            direction = Direction.Left;
                        }

                        // опитваме се да преместим човека
                        int  newX, newY;
                        bool hadDiamond;
                        MoveGuy(field, x, y, direction, out newX, out newY, out hadDiamond);
                        // ако е взел диамант, намаляваме бройката на диамантите
                        if (hadDiamond)
                        {
                            diamondsLeft--;
                        }
                    }
                }
            }
        }
Esempio n. 5
0
 public void LoadItems(Item[,] items)
 {
     if (items.GetLength(0) > Items.GetLength(0) || items.GetLength(1) > Items.GetLength(1))
     {
         throw new ArgumentException("Invalid inventory dimensions");
     }
     for (int i = 0; i < Items.GetLength(0); i++)
     {
         for (int j = 0; j < Items.GetLength(1); j++)
         {
             Items[i, j] = i >= items.GetLength(0) || j >= items.GetLength(1) ? new Item(RawItem.None, 0) : items[i, j];
         }
     }
 }
Esempio n. 6
0
        void Start()
        {
            inventoryDimensions = new Vector2Int(4, 12);

            inventory = new Item[inventoryDimensions.x, inventoryDimensions.y];

            for (int r = 0; r < inventory.GetLength(0); r++)
            {
                for (int c = 0; c < inventory.GetLength(1); c++)
                {
                    inventory[r, c] = null;
                }
            }

            AddToInventory(RunManager.Instance.CurrentDungeon.encounters[0].drops[1]);
        }
Esempio n. 7
0
        private string[,] GetNamesOfItems(Item[,] matrix)
        {
            int rows = matrix.GetLength(0);
            int cols = matrix.GetLength(1);

            string[,] stringMatrix = new string[rows, cols];

            for (int row = 0; row < rows; row++)
            {
                for (int col = 0; col < cols; col++)
                {
                    stringMatrix[row, col] = matrix[row, col].Name;
                }
            }

            return(stringMatrix);
        }
Esempio n. 8
0
        /// <summary>
        /// Взима произволна празна позиция от полето
        /// </summary>
        /// <param name="field">поле</param>
        /// <param name="x">позиция по хоризонтала</param>
        /// <param name="y">позиция по вертикала</param>
        static void GetEmptyPosition(Item[,] field, out int x, out int y)
        {
            // взимаме размерите на полето
            int m = field.GetLength(0);
            int n = field.GetLength(1);

            // създаваме генератор на произволни числа
            var random = new Random();

            do
            {
                // генерираме произволни стойности за x и y
                x = random.Next(m);
                y = random.Next(n);
            }
            // продължаваме, докато не попаднем на позиция, на която няма нищо
            while (field[x, y] != Item.Empty);
        }
Esempio n. 9
0
    private bool InsertItem(Item item)
    {
        for (int i = 0; i < stock.GetLength(0); i++)
        {
            for (int j = 0; j < stock.GetLength(1); j++)
            {
                if (stock[i, j] != null)
                {
                    continue;
                }

                stock[i, j] = item;
                PositionItem(item, i, j);
                return(true);
            }
        }

        return(false);
    }
Esempio n. 10
0
 public static bool AddItem(Item item)
 {
     // For each row
     for (int x = 0; x < Bag.GetLength(0); x++)
     {
         // For each column
         for (int y = 0; y < Bag.GetLength(1); y++)
         {
             // If we find an empty space, we add the item and return
             if (Bag[x, y] == null)
             {
                 Debug.Log("Adding " + item.Name + " to inventory. " + x + " " + y);
                 Bag[x, y] = item;
                 return(true);
             }
         }
     }
     // Or we can't
     return(false);
 }
Esempio n. 11
0
        internal decimal CalculateCoefficient(Item[,] matrix)
        {
            decimal totalCoef = 0;

            winningRows.Clear();

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Item    previousItem = null;
                bool    isWinningRow = true;
                decimal rowCoef      = 0;

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    var element = matrix[row, col];
                    if (element.Type == ItemType.Wildcard)
                    {
                        continue;
                    }

                    if (previousItem != null && element != previousItem)
                    {
                        isWinningRow = false;
                        break;
                    }

                    rowCoef     += element.Coefficient;
                    previousItem = element;
                }

                if (isWinningRow)
                {
                    totalCoef += rowCoef;
                    winningRows.Add(row);
                }
            }

            return(totalCoef);
        }
Esempio n. 12
0
 public Item GetItem(int column, int line)
 {
     if (column >= items.GetLength(0) || line >= items.GetLength(1) || column < 0 || line < 0)
     {
         return(null);
     }
     return(items[column, line]);
 }
        /// <summary>
        /// Deals with updating what gets clicked and swapped in the inventory
        /// </summary>
        private void UpdateInventoryLogic()
        {
            if (drawInventory)
            {
                mousePoint = new Point(Mouse.GetState().X, Mouse.GetState().Y);


                for (int x = 0; x < inventory.GetLength(0); x++)
                {
                    for (int y = 0; y < inventory.GetLength(1); y++)
                    {
                        if (inventory[x, y].itemID != -1)
                        {
                            Rectangle rectangle = new Rectangle(xOffset + (x * boxWidth) + (x * spacing),
                                                                yOffset + (y * boxHeight) + (y * spacing), boxWidth, boxHeight);

                            if (rectangle.Contains(mousePoint))
                            {
                                if (currentMouseState.LeftButton == ButtonState.Pressed &&
                                    previousMouseState.LeftButton == ButtonState.Released)
                                {
                                    Console.WriteLine("Clicked " + SpaceMarauders.Entity.Items.ItemDictionary.itemDictinary[inventory[x, y].guiItemID].entityName);
                                    Swap(x, y, 1);
                                }
                            }
                        }
                    }
                }

                if (new Rectangle(
                        xOffset + xOffset + (inventory.GetLength(0) * (boxWidth / 2)) + (inventory.GetLength(0) * spacing) +
                        50,
                        yOffset, boxWidth, boxHeight).Contains(mousePoint))
                {
                    if (currentMouseState.LeftButton == ButtonState.Pressed &&
                        previousMouseState.LeftButton == ButtonState.Released)
                    {
                        SwapPrimary();
                    }
                }
            }
        }
Esempio n. 14
0
        public int EmptySlotCount()
        {
            int empty = 0;

            for (int y = 0; y < Slots.GetLength(0); y++)
            {
                for (int x = 0; x < Slots.GetLength(1); x++)
                {
                    if (Slots[y, x] == null)
                    {
                        ++empty;
                    }
                }
            }

            return(empty);
        }
Esempio n. 15
0
 public void AddAvailableItem(Item item)
 {
     if (item.id.type == filter)
     {
         for (int j = 0; j < inventory.GetLength(1); j++)
         {
             for (int i = 0; i < inventory.GetLength(0); i++)
             {
                 if (inventory[j, i] == null)
                 {
                     inventory[j, i] = item;
                     raws[j].SetItem(i, item, true);
                     raws[j].UpdateVisuals();
                     return;
                 }
             }
         }
     }
 }
Esempio n. 16
0
        /// <summary>
        /// Премества човек
        /// </summary>
        /// <param name="field">поле</param>
        /// <param name="x">хоризонтална позиция на човека</param>
        /// <param name="y">вертикална позиция на човека</param>
        /// <param name="direction">посока на преместване</param>
        /// <param name="newX">нова хоризонтална позиция на човека</param>
        /// <param name="newY">нова вертикална позиция на човека</param>
        /// <param name="hadDiamond">true, ако човекът е прибрал диамант, иначе - false</param>
        /// <returns>true, ако човекът се е преместил, иначе - false</returns>
        static bool MoveGuy(Item[,] field, int x, int y, Direction direction,
                            out int newX, out int newY, out bool hadDiamond)
        {
            // взимаме размерите на полето
            int m = field.GetLength(0);
            int n = field.GetLength(1);

            // човекът още се намира на старата си позиция
            newX = x;
            newY = y;
            // човекът още не е взел диамант
            hadDiamond = false;

            // в зависимост от посоката...
            switch (direction)
            {
            // опитваме да преместим човека нагоре
            case Direction.Up:
                newY--;
                break;

            // опитваме да преместим човека надясно
            case Direction.Right:
                newX++;
                break;

            // опитваме да преместим човека надолу
            case Direction.Down:
                newY++;
                break;

            // опитваме да преместим човека наляво
            case Direction.Left:
                newX--;
                break;

            default:
                return(false);
            }

            // проверяваме дали няма да излезе от полето
            if (newX < 0 || newX >= m)
            {
                return(false);
            }
            if (newY < 0 || newY >= n)
            {
                return(false);
            }

            // в зависимост от това, което има на новата позиция...
            switch (field[newX, newY])
            {
            // нищо
            case Item.Empty:
            // земя
            case Item.Ground:
            // трева
            case Item.Grass:
                // преместваме човека
                field[newX, newY] = field[x, y];
                // зад него остава просто земя
                field[x, y] = Item.Ground;
                // казваме, че сме го преместили
                return(true);

            // диамант
            case Item.Diamond:
                // казваме, че е взел диамант
                hadDiamond = true;
                // преместваме човека
                field[newX, newY] = field[x, y];
                // зад него остава просто земя
                field[x, y] = Item.Ground;
                // казваме, че сме го преместили
                return(true);

            // "наш човек"
            case Item.OurGuy:
            // "чужд човек"
            case Item.SomeGuy:
            // "дърво"
            case Item.Tree:
            // камък
            case Item.Stone:
            // нещо друго
            default:
                // не правим нищо и не местим човека
                return(false);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Изрисува полето в горната лява част на екрана
        /// </summary>
        /// <param name="field">поле</param>
        static void DrawField(Item[,] field)
        {
            // записваме оригиналните цветове на конзолата
            ConsoleColor backColor = Console.BackgroundColor;
            ConsoleColor foreColor = Console.ForegroundColor;

            // сменяме фона на тъмно червен
            Console.BackgroundColor = ConsoleColor.DarkRed;

            // взимаме размерите на полето
            int m = field.GetLength(0);
            int n = field.GetLength(1);

            // обхождаме всеки ред от полето
            for (int y = 0; y < n; y++)
            {
                // за всеки ред от полето поставяме курсора в началото на съответния ред на конзолата
                Console.SetCursorPosition(0, y);

                // обхождаме всяка позиция от избрания ред
                for (int x = 0; x < m; x++)
                {
                    // проверяваме какво има на позицията в полето
                    switch (field[x, y])
                    {
                    // ако няма нищо...
                    case Item.Empty:
                        Console.Write(' ');
                        break;

                    // ако е "нашият човек"...
                    case Item.OurGuy:
                        Console.ForegroundColor = ConsoleColor.Blue;
                        Console.Write('\u263A');
                        break;

                    // ако е "чужд човек"...
                    case Item.SomeGuy:
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write('\u263B');
                        break;

                    // ако е диамант...
                    case Item.Diamond:
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.Write('\u2666');
                        break;

                    // ако е земя...
                    case Item.Ground:
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.Write('\u2592');
                        break;

                    // ако е трева...
                    case Item.Grass:
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write('\u2593');
                        break;

                    // ако е дърво...
                    case Item.Tree:
                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                        Console.Write('\u2663');
                        break;

                    // ако е камък...
                    case Item.Stone:
                        Console.ForegroundColor = ConsoleColor.DarkGray;
                        Console.Write('\u0665');
                        break;

                    // в противен случай...
                    default:
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write('?');
                        break;
                    }
                }
            }

            // възстановяваме основните цветове на конзолата
            Console.ForegroundColor = foreColor;
            Console.BackgroundColor = backColor;
        }