Exemple #1
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;
            }
        }
Exemple #2
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;
            //}
        }
Exemple #3
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            counter++;
            if (_Animations["indicatorScale"].AnimationState == AnimationState.End)
            {
                if (_CurrentGameActivity == MainSwitches.EndGame)
                {
                    UpdateEndGame(gameTime);
                }
                else if ((_CurrentGameActivity == MainSwitches.Same && _Animations["sameFlyOut"].AnimationState == AnimationState.End) ||
                         (_CurrentGameActivity == MainSwitches.Plus && _Animations["plusFlyOut"].AnimationState == AnimationState.End) ||
                         (_CurrentGameActivity == MainSwitches.SameWall && _Animations["samewallFlyOut"].AnimationState == AnimationState.End) ||
                         (_CurrentGameActivity == MainSwitches.PlusWall && _Animations["pluswallFlyOut"].AnimationState == AnimationState.End))
                {
                    TakeCards();
                    _CurrentGameActivity = MainSwitches.ComboCheck;
                }
                else if (_CurrentGameActivity == MainSwitches.ComboCheck)
                {
                    if (_CardsTakenIndices.Count == 0)
                    {
                        if (TripleTriadGame.NumberOfCardPlayed == 9)
                        {
                            _CurrentGameActivity = MainSwitches.EndGame;
                        }
                        else
                        {
                            _CurrentGameActivity = MainSwitches.None;
                        }
                        ChangePlayersTurn();
                    }
                    else
                    {
                        logWriter.WriteToLog("---Begin checking for combo's" + counter);
                        List <int> tmp = new List <int>();
                        for (int i = 0; i < _CardsTakenIndices.Count; ++i)
                        {
                            tmp.AddRange(PerformNormalCheck(_CardsTakenIndices[i], TripleTriadGame.PlayerTurn));
                            logWriter.WriteToLog("For " + TripleTriadGame.PlayedCards[_CardsTakenIndices[i]].Name + ": " + tmp.Count + " possible combo's");
                        }
                        _CardsTakenIndices = tmp;
                        if (_CardsTakenIndices.Count > 0)
                        {
                            StartAnimation("comboFlyIn");
                            Global.SFXManager.FlyIn.Play();
                            _CurrentGameActivity = MainSwitches.Combo;
                        }
                    }
                }
                else if (_CurrentGameActivity == MainSwitches.Combo && _Animations["comboFlyOut"].AnimationState == AnimationState.End)
                {
                    TakeCards();
                    logWriter.WriteToLog(_CardsTakenIndices.Count + " combo card(s) taken" + counter);
                    _CurrentGameActivity = MainSwitches.ComboCheck;
                }
                else if (_CurrentGameActivity == MainSwitches.None)
                {
                    if (TripleTriadGame.PlayerTurn == 1)
                    {
                        UpdatePlayersCardPositions(gameTime, TripleTriadGame.Player1Cards, 1);
                        PlayNextCard(1);
                    }
                    else if (TripleTriadGame.PlayerTurn == 2)
                    {
                        //SimulateTraversingCards(gameTime, TripleTriadGame.Player2Cards, 2);
                        UpdatePlayersCardPositions(gameTime, TripleTriadGame.Player2Cards, 2);
                        PlayNextCard(2);
                    }

                    if (_CurrentGameActivity == MainSwitches.Normal)
                    {
                        if (TripleTriadGame.NumberOfCardPlayed == 9)
                        {
                            _CurrentGameActivity = MainSwitches.EndGame;
                        }
                        else
                        {
                            _CurrentGameActivity = MainSwitches.None;
                        }
                        TakeCards();
                        ChangePlayersTurn();
                    }
                }

                UpdateHelpWindow(gameTime);
            }
        }
        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;
            //}
        }
        /// <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;
            }
        }
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            counter++;
            if (_Animations["indicatorScale"].AnimationState == AnimationState.End)
            {
                if (_CurrentGameActivity == MainSwitches.EndGame)
                    UpdateEndGame(gameTime);
                else if ((_CurrentGameActivity == MainSwitches.Same && _Animations["sameFlyOut"].AnimationState == AnimationState.End) ||
                    (_CurrentGameActivity == MainSwitches.Plus && _Animations["plusFlyOut"].AnimationState == AnimationState.End) ||
                    (_CurrentGameActivity == MainSwitches.SameWall && _Animations["samewallFlyOut"].AnimationState == AnimationState.End) ||
                    (_CurrentGameActivity == MainSwitches.PlusWall && _Animations["pluswallFlyOut"].AnimationState == AnimationState.End))
                {
                    TakeCards();
                    _CurrentGameActivity = MainSwitches.ComboCheck;
                }
                else if (_CurrentGameActivity == MainSwitches.ComboCheck)
                {
                    if (_CardsTakenIndices.Count == 0)
                    {
                        if (TripleTriadGame.NumberOfCardPlayed == 9)
                            _CurrentGameActivity = MainSwitches.EndGame;
                        else
                            _CurrentGameActivity = MainSwitches.None;
                        ChangePlayersTurn();
                    }
                    else
                    {
                        logWriter.WriteToLog("---Begin checking for combo's" + counter);
                        List<int> tmp = new List<int>();
                        for (int i = 0; i < _CardsTakenIndices.Count; ++i)
                        {
                            tmp.AddRange(PerformNormalCheck(_CardsTakenIndices[i], TripleTriadGame.PlayerTurn));
                            logWriter.WriteToLog("For " + TripleTriadGame.PlayedCards[_CardsTakenIndices[i]].Name + ": " + tmp.Count + " possible combo's");
                        }
                        _CardsTakenIndices = tmp;
                        if (_CardsTakenIndices.Count > 0)
                        {
                            StartAnimation("comboFlyIn");
                            Global.SFXManager.FlyIn.Play();
                            _CurrentGameActivity = MainSwitches.Combo;
                        }
                    }
                }
                else if (_CurrentGameActivity == MainSwitches.Combo && _Animations["comboFlyOut"].AnimationState == AnimationState.End)
                {
                    TakeCards();
                    logWriter.WriteToLog(_CardsTakenIndices.Count + " combo card(s) taken" + counter);
                    _CurrentGameActivity = MainSwitches.ComboCheck;
                }
                else if (_CurrentGameActivity == MainSwitches.None)
                {
                    if (TripleTriadGame.PlayerTurn == 1)
                    {
                        UpdatePlayersCardPositions(gameTime, TripleTriadGame.Player1Cards, 1);
                        PlayNextCard(1);
                    }
                    else if (TripleTriadGame.PlayerTurn == 2)
                    {
                        //SimulateTraversingCards(gameTime, TripleTriadGame.Player2Cards, 2);
                        UpdatePlayersCardPositions(gameTime, TripleTriadGame.Player2Cards, 2);
                        PlayNextCard(2);
                    }

                    if (_CurrentGameActivity == MainSwitches.Normal)
                    {
                        if (TripleTriadGame.NumberOfCardPlayed == 9)
                            _CurrentGameActivity = MainSwitches.EndGame;
                        else
                            _CurrentGameActivity = MainSwitches.None;
                        TakeCards();
                        ChangePlayersTurn();
                    }
                }

                UpdateHelpWindow(gameTime);
            }
        }