Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using ModelService;
- using StateMachineService;
- using UnityEngine;
- namespace Game
- {
- public class MainScreenGameState : State
- {
- private readonly IModelStorage _modelStorage;
- public MainScreenGameState(IModelStorage modelStorage)
- {
- _modelStorage = modelStorage;
- }
- public override void Enter()
- {
- var models = _modelStorage.GetStorage<DeckModel>().GetAll();
- Shuffle(models, GetUniqueSeed());
- var copyList = models.ToList();
- var card = copyList[0];
- copyList.RemoveAt(0);
- foreach (var model in models)
- {
- Debug.Log($"id: {model.Id} power: {model.Power} suit: {model.Suit}");
- }
- }
- public override void Exit()
- {
- }
- private int GetUniqueSeed()
- {
- return Guid.NewGuid().GetHashCode();
- }
- private void Shuffle<T>(IList<T> list, int seed)
- {
- var rand = new System.Random(seed);
- var n = list.Count;
- while (n > 1)
- {
- n--;
- var k = rand.Next(n + 1);
- (list[k], list[n]) = (list[n], list[k]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement