Exemple #1
0
    private void SetUpTable(int noOfColumns, DeckShuffler shuffler)
    {
        if (noOfColumns > 9)
        {
            throw new Exception("Too Many Columns. Please choose a number <= 9");
        }

        //Init Tableu
        Tableu = new CardColumn[noOfColumns];
        for (int i = 0; i < noOfColumns; i++)
        {
            CardColumn newCardColumn = new CardColumn();

            List <Card> faceDownCards = shuffler.DrawCards(i);
            newCardColumn.faceDownCards = new Stack <Card>(faceDownCards);


            List <Card> faceUpCard = shuffler.DrawCards(1);
            newCardColumn.faceUpCards = faceUpCard;

            Tableu[i] = newCardColumn;
        }
        //Init Stock
        StockPile = new Stack <Card>(shuffler.DrawCards(shuffler.GetRemainigCardsCount()));
    }
    public void TriggerRoom(Transform player)
    {
        var enemy = Instantiate(enemyDeck.GetNextCard(), new Vector2(player.position.x - offset, player.position.y + offset), Quaternion.identity);

        if (enemy.TryGetComponent <Combatant>(out var combatant))
        {
            OnEnemySpawned?.Invoke(combatant);
        }

        // Move the player to the oposite corner of the room
        LeanTween.move(player.gameObject, new Vector2(player.position.x + offset, player.position.y - offset), timeToComplete)
        .setEaseOutSine()
        .setOnComplete(() =>
        {
            OnPlayerMoved?.Invoke();
        });

        // Shuffle and Reset the deck;
        playingCardsDeck.ResetIndex();
        DeckShuffler.Shuffle(playingCardsDeck.Cards);

        vcam.LookAt           = m_transform;
        vcam.Follow           = m_transform;
        spriteRenderer.sprite = null;
    }
Exemple #3
0
    private void RandomizeRooms()
    {
        // Shuffle all the rooms
        DeckShuffler.Shuffle(allRoomsExceptStartAndExit);

        // Divide the rooms into two stacks
        GameObject[] firstHalfOfRooms  = new GameObject[allRoomsExceptStartAndExit.Length / 2];
        GameObject[] secondHalfOfRooms = new GameObject[allRoomsExceptStartAndExit.Length / 2 + 1];

        for (int i = 0; i < firstHalfOfRooms.Length; i++)
        {
            firstHalfOfRooms[i]  = allRoomsExceptStartAndExit[i];
            secondHalfOfRooms[i] = allRoomsExceptStartAndExit[firstHalfOfRooms.Length + i];
        }

        // Add the Exit Room to the second stack
        secondHalfOfRooms[secondHalfOfRooms.Length - 1] = exitRoom;
        // Then shuffle the second stack
        DeckShuffler.Shuffle(secondHalfOfRooms);

        // Combine both stacks into a Room Deck
        GameObject[] allRooms = new GameObject[allRoomsExceptStartAndExit.Length + 1];

        firstHalfOfRooms.CopyTo(allRooms, 0);
        secondHalfOfRooms.CopyTo(allRooms, firstHalfOfRooms.Length);

        roomsDeck.SetCards(allRooms);
    }
Exemple #4
0
    public void InitGame()
    {
        DeckShuffler shuffler = new DeckShuffler();

        shuffler.ShuffleDeck();

        InitGame(shuffler);
    }
    public void ShuffleDeck()
    {
        DeckShuffler shuffler = new DeckShuffler();

        shuffler.Shuffle(ref _deck);

        OrganizeQueue();
    }
Exemple #6
0
        public void Null()
        {
            var randomizer   = new Mock <IRandomizer>();
            var deckShuffler = new DeckShuffler(randomizer.Object);
            var results      = deckShuffler.Shuffle(null);

            Assert.IsNotNull(results);
            Assert.AreEqual(0, results.Count);
        }
Exemple #7
0
    private void Awake()
    {
        RandomizeRooms();
        DeckShuffler.Shuffle(enemyDeck.Cards);
        enemyDeck.ResetIndex();

        player       = GameObject.FindGameObjectWithTag("Player").GetComponent <Combatant>();
        playerHealth = player.GetComponent <HealthBehaviour>();
    }
Exemple #8
0
    private void LoadSerializedGame()
    {
        using (FileStream fs = File.Open(dirPathToSerialize + "data" + serializedGameToLoad_index + ".dat", FileMode.Open))
        {
            BinaryFormatter b = new BinaryFormatter();
            this.shufflerClone = b.Deserialize(fs) as DeckShuffler;
        }

        this.RestartGame();
    }
Exemple #9
0
        public void ShufflingDeck()
        {
            var deckShuffler = new DeckShuffler(_deck.GetDeck());

            Assert.IsNotNull(deckShuffler.GetShuffledDeck());
            foreach (var variable in deckShuffler.GetShuffledDeck())
            {
                Console.WriteLine(variable);
            }
            Console.WriteLine(deckShuffler.GetShuffledDeck().Count);
        }
Exemple #10
0
    public void InitGame(DeckShuffler seed)
    {
        gameState         = new GameState();
        this.movesHistory = new Stack <Move>();

        shufflerClone = seed.Clone() as DeckShuffler;

        SetUpTable(columns_count, seed);
        foreach (ISolitaireEventsHandlers subscribedHandler in subscribedInstances)
        {
            subscribedHandler.NotifyBeginGame(Tableu, StockPile);
        }
    }
Exemple #11
0
        public void Shuffled()
        {
            var randomizer = new Mock <IRandomizer>();

            randomizer.Setup(x => x.Next(0, 2)).Returns(1);
            randomizer.Setup(x => x.Next(0, 1)).Returns(0);
            var deckShuffler = new DeckShuffler(randomizer.Object);
            var a            = new Card(null, null);
            var b            = new Card(null, null);
            var results      = deckShuffler.Shuffle(new[] { a, b });

            Assert.AreEqual(b, results[0]);
            Assert.AreEqual(a, results[1]);
        }
Exemple #12
0
        public override void Puzzle1()
        {
            while (player1Deck.Count > 0 && player2Deck.Count > 0)
            {
                if (player1Deck.First() > player2Deck.First())
                {
                    DeckShuffler.RoundOfCombat(player1Deck, player2Deck);
                }
                else
                {
                    DeckShuffler.RoundOfCombat(player2Deck, player1Deck);
                }
            }
            long ans = player1Deck.Count() == 0 ? DeckShuffler.CountResult(player2Deck) : DeckShuffler.CountResult(player1Deck);

            Console.WriteLine($"The winning player's score = {ans}");
        }
Exemple #13
0
    // Start is called before the first frame update
    void Start()
    {
        CardLoader.loadCards();

        List <Card> shuffledCards = new List <Card>(CardLoader.deckBang);

        DeckShuffler.Shuffle(shuffledCards);

        float z = 0.0f;

        foreach (Card card in shuffledCards)
        {
            GameObject obj = Instantiate(cardPrefab);
            obj.transform.parent   = transform;
            obj.transform.position = new Vector3(0.0f, 0.0f, z);
            CardSprite cardSprite = obj.GetComponent <CardSprite>();
            cardSprite.card = card;
            z += 0.5f;
        }
    }
Exemple #14
0
        public override void Puzzle2()
        {
            int gameNumber  = 1;
            int roundNumber = 1;

            while (player1Deck.Count > 0 && player2Deck.Count > 0)
            {
                //Console.WriteLine($" ===== Round {roundNumber} (Game {gameNumber}) ===== ");
                //Console.Write("P1: ");
                //player1Deck.ForEach(x => Console.Write(x + " "));
                //Console.WriteLine();
                //Console.Write("P2: ");
                //player2Deck.ForEach(x => Console.Write(x + " "));
                //Console.WriteLine();
                DeckShuffler.RoundOfRecursiveCombat(player1Deck, player2Deck, gameNumber);
                roundNumber++;
            }
            long ans = player1Deck.Count() == 0 ? DeckShuffler.CountResult(player2Deck) : DeckShuffler.CountResult(player1Deck);

            Console.WriteLine($"The winning player's score = {ans}");
        }
Exemple #15
0
        public void HandOutCards()
        {
            var deckShuffler = new DeckShuffler(_deck.GetDeck());

            Assert.IsNotNull(_deck.GetDeck());
            foreach (var variable in deckShuffler.GetShuffledDeck())
            {
                Console.WriteLine("shuffled" + variable);
            }
            Console.WriteLine(deckShuffler.GetShuffledDeck().Count);
            var deckDealer = new DeckDealer(_playerMaker.GetTeam(), deckShuffler.GetShuffledDeck(), 5);

            Assert.IsNotNull(deckDealer.GetPlayersCards());
            for (var i = 0; i < 5; i++)
            {
                Assert.AreEqual(5, deckDealer.GetPlayersCards()[i].Count);
                Console.WriteLine("gracz {0} ma tyle kart " + deckDealer.GetPlayersCards()[i].Count, i);
                for (var j = 0; j < 5; j++)
                {
                    Console.WriteLine("Karty gracza {0} to " + deckDealer.GetPlayersCards()[i].ElementAt(j), i);
                }
            }
        }
Exemple #16
0
 public void TestOfNullExceptionInDeckDealer2_MustPass()
 {
     var deckShuffler        = new DeckShuffler(_deck.GetDeck());
     var deckDealerNullTest2 = new DeckDealer(_playerMaker.GetTeam(), null, 5);
 }
Exemple #17
0
 public void TestOfNullExceptionInDeckShuffler_MustPass()
 {
     var deckShuffler = new DeckShuffler(null);
 }
Exemple #18
0
 private void StartNewRound()
 {
     DeckShuffler.Shuffle(playingCardDeck.Cards);
     playingCardDeck.ResetIndex();
     OnNewRoundStart?.Invoke();
 }
Exemple #19
0
 public void TestOfNullExceptionInDeckDealer_MustPass()
 {
     var deckShuffler        = new DeckShuffler(_deck.GetDeck());
     var deckDealerNullTest1 = new DeckDealer(null, deckShuffler.GetShuffledDeck(), 5);
 }
Exemple #20
0
 public void TestOfHandOutExceptionInDeckDealer2_MustPass()
 {
     var deckShuffler   = new DeckShuffler(_deck.GetDeck());
     var deckDealerTest = new DeckDealer(_playerMaker.GetTeam(), deckShuffler.GetShuffledDeck(), 0);
 }