Example #1
0
        private void PlayNextCard(int player)
        {
            if (selectedCard != null)
            {
                int index = TripleTriadCardLib.SelectedGridPosition();
                if (index >= 0 && TripleTriadGame.PlayedCards[index] == null)
                {
                    selectedGrid.Position = TripleTriadCardLib.GameBoardPos[index];
                    if (!_SceneEntities.Contains(selectedGrid))
                    {
                        _SceneEntities.Add(selectedGrid);
                    }
                    if (Global.MouseManager.IsLeftMouseButtonClicked())
                    {
                        PlaceSelectedCard(index, player);
                        _SceneEntities.Remove(selectedGrid);
                        //ChangePlayersTurn();
                    }
                }
                else
                {
                    _SceneEntities.Remove(selectedGrid);
                }

                if (Global.MouseManager.IsRightMouseButtonClicked())
                {
                    selectedCard = null;
                    _SceneEntities.Remove(selectedGrid);
                    Global.SFXManager.Cancel.Play();
                }
            }
        }
Example #2
0
        public static void GenerateTestHands1()
        {
            _PlayerTurn   = 2;
            _Player1Cards = new TripleTriadCard[5];
            _Player2Cards = new TripleTriadCard[5];

            int[] p1Cards = { 87, 3, 109, 0, 0 };
            int[] p2Cards = { 82, 40, 34, 0, 0 };

            for (int i = 0; i < 5; ++i)
            {
                TripleTriadCard card1 = TripleTriadCardLib.CardInfo[p1Cards [i]].GetInstance();
                TripleTriadCard card2 = TripleTriadCardLib.CardInfo[p2Cards[i]].GetInstance();
                card1.Position          = TripleTriadCardLib.Player1HandPos[i];
                card2.Position          = TripleTriadCardLib.Player2HandPos[i];
                card1.Depth             = i * 0.1f + 0.1f;
                card2.Depth             = i * 0.1f + 0.1f;
                card1.PlayerNumber      = 1;
                card2.PlayerNumber      = 2;
                _Player1Cards[i]        = card1;
                _Player2Cards[i]        = card2;
                _Player1Cards[i].IsOpen = (_PlayerTurn == 1 || GameRule.Open);
                _Player2Cards[i].IsOpen = (_PlayerTurn == 2 || GameRule.Open);
            }
        }
Example #3
0
        public static void SuddenDeathHandRedistribution()
        {
            List <TripleTriadCard> newP1Cards = new List <TripleTriadCard>();
            List <TripleTriadCard> newP2Cards = new List <TripleTriadCard>();

            for (int i = 0; i < 5; ++i)
            {
                TripleTriadCard card = _Player1Cards[i];
                if (card.PlayerNumber == 1)
                {
                    if (newP1Cards.Count > 5)
                    {
                        newP1Cards.Add(card);
                    }
                    else
                    {
                        newP2Cards.Add(card);
                    }
                }
                else if (card.PlayerNumber == 2)
                {
                    if (newP2Cards.Count > 5)
                    {
                        newP2Cards.Add(card);
                    }
                    else
                    {
                        newP1Cards.Add(card);
                    }
                }
                card = _Player2Cards[i];
                if (card.PlayerNumber == 1)
                {
                    if (newP1Cards.Count > 5)
                    {
                        newP1Cards.Add(card);
                    }
                    else
                    {
                        newP2Cards.Add(card);
                    }
                }
                else if (card.PlayerNumber == 2)
                {
                    if (newP2Cards.Count > 5)
                    {
                        newP2Cards.Add(card);
                    }
                    else
                    {
                        newP1Cards.Add(card);
                    }
                }
            }

            _Player1Cards = newP1Cards.ToArray();
            _Player2Cards = newP2Cards.ToArray();
        }
Example #4
0
 private static void ReadCardList(string filename)
 {
     _CardInfo = new Dictionary <int, TripleTriadCard>();
     System.IO.StreamReader input = new System.IO.StreamReader(filename);
     for (int i = 0; !input.EndOfStream; ++i)
     {
         TripleTriadCard card = new TripleTriadCard();
         card.LoadContent("Cards/", input.ReadLine());
         _CardInfo.Add(i, card);
     }
     input.Close();
 }
Example #5
0
        // Provides a copy of a card.
        // Since the attributes of a card is unchanged throughout the game,
        // only shallow copying is used. Positions and other data associating
        // with the sprite can be changed freely.
        public TripleTriadCard GetInstance()
        {
            TripleTriadCard card = new TripleTriadCard();

            card._Texture      = _Texture;
            card._Rectangle    = _Rectangle;
            card._Name         = _Name;
            card._CardValue    = _CardValue;
            card._Element      = _Element;
            card._Type         = _Type;
            card._Level        = _Level;
            card._PlayerNumber = _PlayerNumber;
            return(card);
        }
Example #6
0
        private void UpdateCurrentMouseTargetOnBoard(GameTime gameTime, int player)
        {
            TripleTriadCard tmp = null;

            for (int i = 0; i < TripleTriadGame.PlayedCards.Length; ++i)
            {
                if (TripleTriadGame.PlayedCards[i] != null && (TripleTriadGame.PlayedCards[i].IsMouseOver() || TripleTriadGame.PlayedCards[i].IsMouseDown()))
                {
                    tmp = TripleTriadGame.PlayedCards[i];
                    break;
                }
            }
            _PrevMouseTarget = _CurrMouseTarget;
            _CurrMouseTarget = tmp;
        }
Example #7
0
        private void UpdatePlayersCardPositions(GameTime gameTime, TripleTriadCard[] cards, int player)
        {
            TripleTriadCard tmp   = null;
            int             index = -1;

            ResetHandPositions(player);
            for (int i = 0; i < cards.Length; ++i)
            {
                if (selectedCard == null && !TripleTriadGame.PlayedCards.Contains(cards[i]) && (cards[i].IsMouseOver() || cards[i].IsMouseDown()))
                {
                    if (tmp == null || cards[i].Depth > tmp.Depth)
                    {
                        tmp   = cards[i];
                        index = i;
                    }
                }
            }

            if (tmp != null && index != -1)
            {
                if (tmp.IsSelected())
                {
                    selectedCard = tmp;
                    Global.SFXManager.Card.Play();
                }

                if (player == 1)
                {
                    tmp.Position = TripleTriadCardLib.Player1HandPos[index] + new Vector2(-16, 0);
                }
                else if (player == 2)
                {
                    tmp.Position = TripleTriadCardLib.Player2HandPos[index] + new Vector2(16, 0);
                }
            }

            if (tmp != null)
            {
                _PrevMouseTarget = _CurrMouseTarget;
                _CurrMouseTarget = tmp;
            }
            else
            {
                UpdateCurrentMouseTargetOnBoard(gameTime, player);
            }
        }
Example #8
0
        /// <summary>
        /// Place the selected card on the board
        /// </summary>
        /// <param name="boardIndex">The index on the board</param>
        public void PlaceSelectedCard(int boardIndex, int player)
        {
            TripleTriadGame.PlayedCards[boardIndex] = selectedCard;
            if (TripleTriadGame.Elements[boardIndex] != TripleTriadCardLib.Element.None)
            {
                if (TripleTriadGame.Elements[boardIndex] == selectedCard.Element)
                {
                    Sprite plus = new Sprite();
                    plus.LoadContent("Plus_1");
                    plus.Position = TripleTriadCardLib.GameBoardPos[boardIndex];
                    plus.Depth    = 0.99f;
                    _SceneEntities.Add(plus);
                }
                else
                {
                    Sprite minus = new Sprite();
                    minus.LoadContent("Minus_1");
                    minus.Position = TripleTriadCardLib.GameBoardPos[boardIndex];
                    minus.Depth    = 0.99f;
                    _SceneEntities.Add(minus);
                }
            }

            logWriter.WriteToLog("PLAYER " + player + " places " + selectedCard.Name + " at cell number " + boardIndex);

            TripleTriadGame.PlayedCards[boardIndex].Position = TripleTriadCardLib.GameBoardPos[boardIndex];
            TripleTriadGame.PlayedCards[boardIndex].IsOpen   = true;
            selectedCard = null;

            if (_CurrentGameActivity == MainSwitches.None && GameRule.Same)
            {
                PerformSameRuleCheck(boardIndex, player);
            }
            if (_CurrentGameActivity == MainSwitches.None && GameRule.Plus)
            {
                PerformPlusRuleCheck(boardIndex, player);
            }

            if (_CurrentGameActivity == MainSwitches.None)
            {
                PerformNormalCheck(boardIndex, player);
                _CurrentGameActivity = MainSwitches.Normal;
            }
        }
Example #9
0
        public static void GenerateRandomHands()
        {
            _Player1Cards = new TripleTriadCard[5];
            _Player2Cards = new TripleTriadCard[5];

            for (int i = 0; i < 5; ++i)
            {
                TripleTriadCard card1 = TripleTriadCardLib.CardInfo[rand.Next(110)].GetInstance();
                TripleTriadCard card2 = TripleTriadCardLib.CardInfo[rand.Next(110)].GetInstance();
                card1.Position          = TripleTriadCardLib.Player1HandPos[i];
                card2.Position          = TripleTriadCardLib.Player2HandPos[i];
                card1.Depth             = i * 0.1f + 0.1f;
                card2.Depth             = i * 0.1f + 0.1f;
                card1.PlayerNumber      = 1;
                card2.PlayerNumber      = 2;
                _Player1Cards[i]        = card1;
                _Player2Cards[i]        = card2;
                _Player1Cards[i].IsOpen = (_PlayerTurn == 1 || GameRule.Open);
                _Player2Cards[i].IsOpen = (_PlayerTurn == 2 || GameRule.Open);
            }
        }
Example #10
0
        private List <int> PerformNormalCheck(int boardIndex, int player)
        {
            List <int> possibleComboIndices = new List <int>();

            int[] adjacentIndices = GetAdjacentIndices(boardIndex);
            //int count = 0;
            TripleTriadCard currentCard = TripleTriadGame.PlayedCards[boardIndex];

            if (_CurrentGameActivity == MainSwitches.None)
            {
                _CardsTakenIndices = new List <int>();
            }

            int valueModifier1 = 0;

            if (TripleTriadGame.Elements[boardIndex] != TripleTriadCardLib.Element.None)
            {
                if (TripleTriadGame.Elements[boardIndex] == currentCard.Element)
                {
                    valueModifier1 += 1;
                }
                else
                {
                    valueModifier1 -= 1;
                }
            }

            for (int i = 0; i < 4; ++i)
            {
                int             valueModifier2 = 0;
                TripleTriadCard adjacentCard   = adjacentIndices[i] >= 0 ? TripleTriadGame.PlayedCards[adjacentIndices[i]] : null;
                if (adjacentIndices[i] >= 0 && TripleTriadGame.Elements[adjacentIndices[i]] != TripleTriadCardLib.Element.None && adjacentCard != null)
                {
                    if (TripleTriadGame.Elements[adjacentIndices[i]] == adjacentCard.Element)
                    {
                        valueModifier2 += 1;
                    }
                    else
                    {
                        valueModifier2 -= 1;
                    }
                }

                if (adjacentCard != null && currentCard.PlayerNumber != adjacentCard.PlayerNumber &&
                    currentCard.CardValue[i] + valueModifier1 > adjacentCard.CardValue[3 - i] + valueModifier2)
                {
                    if (_CurrentGameActivity == MainSwitches.None)
                    {
                        if (!_CardsTakenIndices.Contains(adjacentIndices[i]))
                        {
                            _CardsTakenIndices.Add(adjacentIndices[i]);
                        }
                    }
                    //adjacentCard.PlayerNumber = player;
                    possibleComboIndices.Add(adjacentIndices[i]);
                    //++count;
                    //Global.SFXManager.CardWon.Play();
                }
            }

            //if (player == 1)
            //    TripleTriadGame.P1Score += count;
            //else
            //    TripleTriadGame.P1Score -= count;

            return(possibleComboIndices);
        }
Example #11
0
        private void PerformPlusRuleCheck(int boardIndex, int player)
        {
            int[] adjacentIndices = GetAdjacentIndices(boardIndex);
            //int count = 0;
            TripleTriadCard currentCard = TripleTriadGame.PlayedCards[boardIndex];

            //List<int> comboCheckIndices = new List<int>();

            _CardsTakenIndices = new List <int>();

            for (int i = 0; i < 4; ++i)
            {
                for (int j = i + 1; j < 4; ++j)
                {
                    TripleTriadCard adjacentCard1 = adjacentIndices[i] >= 0 ? TripleTriadGame.PlayedCards[adjacentIndices[i]] : null;
                    TripleTriadCard adjacentCard2 = adjacentIndices[j] >= 0 ? TripleTriadGame.PlayedCards[adjacentIndices[j]] : null;
                    if (adjacentCard1 != null && adjacentCard2 != null &&
                        (currentCard.PlayerNumber != adjacentCard1.PlayerNumber || currentCard.PlayerNumber != adjacentCard2.PlayerNumber) &&
                        currentCard.CardValue[i] + adjacentCard1.CardValue[3 - i] == currentCard.CardValue[j] + adjacentCard2.CardValue[3 - j])
                    {
                        logWriter.WriteToLog("[PLUS] " + currentCard.Name + " adjacent to " + adjacentCard1.Name + " and " + adjacentCard2.Name);
                        StartAnimation("plusFlyIn");
                        Global.SFXManager.FlyIn.Play();

                        _CurrentGameActivity = MainSwitches.Plus;

                        if (adjacentCard1.PlayerNumber != player)
                        {
                            logWriter.WriteToLog("[PLUS] " + adjacentCard1.Name + " taken by PLAYER " + player);
                            if (!_CardsTakenIndices.Contains(adjacentIndices[i]))
                            {
                                _CardsTakenIndices.Add(adjacentIndices[i]);
                            }
                            //adjacentCard1.PlayerNumber = player;
                            //comboCheckIndices.Add(adjacentIndices[i]);
                            //++count;
                        }
                        if (adjacentCard2.PlayerNumber != player)
                        {
                            logWriter.WriteToLog("[PLUS] " + adjacentCard2.Name + " taken by PLAYER " + player);
                            if (!_CardsTakenIndices.Contains(adjacentIndices[j]))
                            {
                                _CardsTakenIndices.Add(adjacentIndices[j]);
                            }
                            //adjacentCard2.PlayerNumber = player;
                            //comboCheckIndices.Add(adjacentIndices[j]);
                            //++count;
                        }
                    }
                }
            }

            //if (player == 1)
            //    TripleTriadGame.P1Score += count;
            //else
            //    TripleTriadGame.P1Score -= count;


            // Perform Combo check
            //while (comboCheckIndices.Count > 0)
            //{
            //    List<int> tmp = new List<int>();
            //    for (int i = 0; i < comboCheckIndices.Count; ++i)
            //    {
            //        tmp.AddRange(PerformNormalCheck(comboCheckIndices[i], player));
            //    }
            //    comboCheckIndices = tmp;
            //}
        }
        private void PlayNextCard(int player)
        {
            if (selectedCard != null)
            {
                int index = TripleTriadCardLib.SelectedGridPosition();
                if (index >= 0 && TripleTriadGame.PlayedCards[index] == null)
                {
                    selectedGrid.Position = TripleTriadCardLib.GameBoardPos[index];
                    if (!_SceneEntities.Contains(selectedGrid))
                        _SceneEntities.Add(selectedGrid);
                    if (Global.MouseManager.IsLeftMouseButtonClicked())
                    {
                        PlaceSelectedCard(index, player);
                        _SceneEntities.Remove(selectedGrid);
                        //ChangePlayersTurn();
                    }
                }
                else
                    _SceneEntities.Remove(selectedGrid);

                if (Global.MouseManager.IsRightMouseButtonClicked())
                {
                    selectedCard = null;
                    _SceneEntities.Remove(selectedGrid);
                    Global.SFXManager.Cancel.Play();
                }
            }
        }
        /// <summary>
        /// Place the selected card on the board
        /// </summary>
        /// <param name="boardIndex">The index on the board</param>
        public void PlaceSelectedCard(int boardIndex, int player)
        {
            TripleTriadGame.PlayedCards[boardIndex] = selectedCard;
            if (TripleTriadGame.Elements[boardIndex] != TripleTriadCardLib.Element.None)
            {
                if (TripleTriadGame.Elements[boardIndex] == selectedCard.Element)
                {
                    Sprite plus = new Sprite();
                    plus.LoadContent("Plus_1");
                    plus.Position = TripleTriadCardLib.GameBoardPos[boardIndex];
                    plus.Depth = 0.99f;
                    _SceneEntities.Add(plus);
                }
                else
                {
                    Sprite minus = new Sprite();
                    minus.LoadContent("Minus_1");
                    minus.Position = TripleTriadCardLib.GameBoardPos[boardIndex];
                    minus.Depth = 0.99f;
                    _SceneEntities.Add(minus);
                }
            }

            logWriter.WriteToLog("PLAYER " + player + " places " + selectedCard.Name + " at cell number " + boardIndex);

            TripleTriadGame.PlayedCards[boardIndex].Position = TripleTriadCardLib.GameBoardPos[boardIndex];
            TripleTriadGame.PlayedCards[boardIndex].IsOpen = true;
            selectedCard = null;

            if (_CurrentGameActivity == MainSwitches.None && GameRule.Same)
            {
                PerformSameRuleCheck(boardIndex, player);
            }
            if (_CurrentGameActivity == MainSwitches.None && GameRule.Plus)
            {
                PerformPlusRuleCheck(boardIndex, player);
            }

            if (_CurrentGameActivity == MainSwitches.None)
            {
                PerformNormalCheck(boardIndex, player);
                _CurrentGameActivity = MainSwitches.Normal;
            }
        }
        private void SimulateTraversingCards(GameTime gameTime, TripleTriadCard[] cards, int player)
        {
            //if (selectedCard == null)
            //{
            //    Thread cal = new Thread(new ThreadStart(CalculateMove));
            //    cal.Start();
            //}

            //simulateCount += gameTime.ElapsedGameTime.Milliseconds;
            //if (simulateCount >= simulateInterval && selectedCard == null)
            //{
            //    simulateCount = 0;
            //    ResetHandPositions(player);
            //    Random rand = new Random();
            //    int index = rand.Next(cards.Length);
            //    while (TripleTriadGame.PlayedCards.Contains(TripleTriadGame.Player2Cards[index]))
            //        index = rand.Next(cards.Length);
            //    if (player == 1)
            //        cards[index].Position = TripleTriadCardLib.Player1HandPos[index] + new Vector2(-16, 0);
            //    else if (player == 2)
            //        cards[index].Position = TripleTriadCardLib.Player2HandPos[index] + new Vector2(16, 0);
            //    Global.SFXManager.Card.Play();
            //}

            //if (selectedCard != null)
            //{
            //    ResetHandPositions(player);
            //    if (player == 1)
            //        selectedCard.Position = TripleTriadCardLib.Player1HandPos[selectedCardIndex] + new Vector2(-16, 0);
            //    else if (player == 2)
            //        selectedCard.Position = TripleTriadCardLib.Player2HandPos[selectedCardIndex] + new Vector2(16, 0);

            //    if (simulateCount >= simulateInterval)
            //    {
            //        PlaceSelectedCard(selectedGridIndex, player);
            //        TripleTriadGame.PlayerTurn = 3 - TripleTriadGame.PlayerTurn;
            //    }
            //}
        }
        private void UpdatePlayersCardPositions(GameTime gameTime, TripleTriadCard[] cards, int player)
        {
            TripleTriadCard tmp = null;
            int index = -1;
            ResetHandPositions(player);
            for (int i = 0; i < cards.Length; ++i)
            {
                if (selectedCard == null && !TripleTriadGame.PlayedCards.Contains(cards[i]) && (cards[i].IsMouseOver() || cards[i].IsMouseDown()))
                {
                    if (tmp == null || cards[i].Depth > tmp.Depth)
                    {
                        tmp = cards[i];
                        index = i;
                    }
                }
            }

            if (tmp != null && index != -1)
            {
                if (tmp.IsSelected())
                {
                    selectedCard = tmp;
                    Global.SFXManager.Card.Play();
                }

                if (player == 1)
                    tmp.Position = TripleTriadCardLib.Player1HandPos[index] + new Vector2(-16, 0);
                else if (player == 2)
                    tmp.Position = TripleTriadCardLib.Player2HandPos[index] + new Vector2(16, 0);
            }

            if (tmp != null)
            {
                _PrevMouseTarget = _CurrMouseTarget;
                _CurrMouseTarget = tmp;
            }
            else
                UpdateCurrentMouseTargetOnBoard(gameTime, player);
        }
Example #16
0
 // Provides a copy of a card.
 // Since the attributes of a card is unchanged throughout the game, 
 // only shallow copying is used. Positions and other data associating
 // with the sprite can be changed freely.
 public TripleTriadCard GetInstance()
 {
     TripleTriadCard card = new TripleTriadCard();
     card._Texture = _Texture;
     card._Rectangle = _Rectangle;
     card._Name = _Name;
     card._CardValue = _CardValue;
     card._Element = _Element;
     card._Type = _Type;
     card._Level = _Level;
     card._PlayerNumber = _PlayerNumber;
     return card;
 }
 private static void ReadCardList(string filename)
 {
     _CardInfo = new Dictionary<int, TripleTriadCard>();
     System.IO.StreamReader input = new System.IO.StreamReader(filename);
     for (int i = 0; !input.EndOfStream; ++i)
     {
         TripleTriadCard card = new TripleTriadCard();
         card.LoadContent("Cards/", input.ReadLine());
         _CardInfo.Add(i, card);
     }
     input.Close();
 }