Setup and play area prefab
This commit is contained in:
parent
fe61df43e7
commit
af12b601fc
166 changed files with 14014 additions and 10 deletions
31
WizardDuelsProject/Assets/Scripts/StackExtensions.cs
Normal file
31
WizardDuelsProject/Assets/Scripts/StackExtensions.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
namespace DefaultNamespace
|
||||
{
|
||||
public static class StackExtensions
|
||||
{
|
||||
private static Random random = new Random();
|
||||
|
||||
public static void Shuffle<T>(this Stack<T> stack)
|
||||
{
|
||||
List<T> list = new List<T>(stack);
|
||||
stack.Clear();
|
||||
|
||||
// Fisher-Yates shuffle
|
||||
for (int i = list.Count - 1; i > 0; i--)
|
||||
{
|
||||
int j = random.Next(i + 1);
|
||||
(list[i], list[j]) = (list[j], list[i]); // Swap elements
|
||||
}
|
||||
|
||||
// Push shuffled elements back to stack
|
||||
foreach (T item in list)
|
||||
{
|
||||
stack.Push(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue