Advertisement
BorisKotlyar

Untitled

Jun 24th, 2024
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using ModelService;
  5. using StateMachineService;
  6. using UnityEngine;
  7.  
  8. namespace Game
  9. {
  10.     public class MainScreenGameState : State
  11.     {
  12.         private readonly IModelStorage _modelStorage;
  13.  
  14.         public MainScreenGameState(IModelStorage modelStorage)
  15.         {
  16.             _modelStorage = modelStorage;
  17.         }
  18.  
  19.         public override void Enter()
  20.         {
  21.             var models = _modelStorage.GetStorage<DeckModel>().GetAll();
  22.             Shuffle(models, GetUniqueSeed());
  23.  
  24.             var copyList = models.ToList();
  25.            
  26.             var card = copyList[0];
  27.             copyList.RemoveAt(0);
  28.  
  29.             foreach (var model in models)
  30.             {
  31.                 Debug.Log($"id: {model.Id} power: {model.Power} suit: {model.Suit}");
  32.             }
  33.         }
  34.  
  35.         public override void Exit()
  36.         {
  37.         }
  38.  
  39.         private int GetUniqueSeed()
  40.         {
  41.             return Guid.NewGuid().GetHashCode();
  42.         }
  43.        
  44.         private void Shuffle<T>(IList<T> list, int seed)
  45.         {
  46.             var rand = new System.Random(seed);
  47.             var n = list.Count;
  48.             while (n > 1)
  49.             {
  50.                 n--;
  51.                 var k = rand.Next(n + 1);
  52.                 (list[k], list[n]) = (list[n], list[k]);
  53.             }
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement