// determines if moves are still possible, returns boolean public bool ExistMoves() { if (speedState == gameState.Winner) { return(true); } if (speedState == gameState.PlayAgain) { return(true); } if (!ableToReBegin || !ableToReBegin2) { return(true); } bool oppMoves = false; for (int i = 0; i < opponentCards.Length; i++) { if (opponentCards[i].Count() != 0) { int cv = opponentCards[i].Peek().cardValue; int value1 = lGameStack.Peek().cardValue; int value2 = rGameStack.Peek().cardValue; if ((cv == 0 && value1 == 12) || (cv == 12 && value1 == 0) || (cv == value1 + 1 || cv == value1 - 1)) { oppMoves = true; } if ((cv == 0 && value2 == 12) || (cv == 12 && value2 == 0) || (cv == value2 + 1 || cv == value2 - 1)) { oppMoves = true; } } } bool yourMoves = false; for (int i = 0; i < yourCards.Length; i++) { if (yourCards[i].Count() != 0) { int cv = yourCards[i].Peek().cardValue; int value1 = lGameStack.Peek().cardValue; int value2 = rGameStack.Peek().cardValue; if ((cv == 0 && value1 == 12) || (cv == 12 && value1 == 0) || (cv == value1 + 1 || cv == value1 - 1)) { yourMoves = true; } if ((cv == 0 && value2 == 12) || (cv == 12 && value2 == 0) || (cv == value2 + 1 || cv == value2 - 1)) { yourMoves = true; } } } return(yourMoves || oppMoves); }
// plays cards from selected piles to destination piles public void PlayCard(Player player, int selectedPile, Pile destinationPile) { if (speedState != gameState.GamePlay) { return; } Pile fromPile; if (player.isPlayer1) { fromPile = yourCards[player.selector]; } else { fromPile = opponentCards[player.selector]; } if (fromPile.Count() == 0) { return; } if (fromPile.drawnTo) { return; } speedState = gameState.PlayingCard; Card c = fromPile.Peek(); int cv = c.cardValue; int value = destinationPile.Peek().cardValue; if ((cv == 0 && value == 12) || (cv == 12 && value == 0) || (cv == value + 1 || cv == value - 1)) { //if(myType == gameType.Timed) delayTimer.ResetTimer(0); Card m = fromPile.Take(); m.toPile(destinationPile); if (soundOn) { playcard.Play(); } if (vibrateOn) { GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f); } m.Rotate(Actions.ExpoMove, (float)(random.NextDouble() - .5) / 2, .3f); m.WhenDoneMoving(delegate() { m.Move(Actions.LinearMove, m.attributes.position + new Vector2(random.Next(-5, 5), random.Next(-5, 5)), 3f); player.score++; if (powerUpOn) { if (destinationPile.hasPowerUp) { Player victim; if (player.isPlayer1) { victim = opp; } else { victim = you; } destinationPile.PlayPowerUp(victim); } } speedState = gameState.GamePlay; if (player.isPlayer1) { if (yourStack.Count() != 0) { if (fromPile.Count() == 0) { DrawCard(yourStack, fromPile, 0f); } } } else { if (opponentStack.Count() != 0) { if (fromPile.Count() == 0) { DrawCard(opponentStack, fromPile, 0f); } } } Shake(); SelectPowerUp(destinationPile); ParticleEngine smoke = new ParticleEngine(textures, destinationPile.position, new Vector2(300, 300), m.attributes.depth, .3f, Color.WhiteSmoke); base.Add(smoke); }); } else { speedState = gameState.GamePlay; c.attributes.color = Color.Red; Timer timer = new Timer(1); base.Add(timer); timer.SetTimer(0, 1, delegate() { c.attributes.color = Color.White; player.RemovePenalty(); }); player.Penalize(); } }
// determines if a move is available based on card values & dealt hand public bool ExistAMove(Pile[] Hand, Pile rgamestack, Pile lgamestack) { bool moves = false; for (int i = 0; i < Hand.Length; i++) { if (Hand[i].Count() != 0) { int cv = Hand[i].Peek().cardValue; int value1 = lgamestack.Peek().cardValue; int value2 = rgamestack.Peek().cardValue; if ((cv == 0 && value1 == 12) || (cv == 12 && value1 == 0) || (cv == value1 + 1 || cv == value1 - 1)) { if (moves) { int olddistance = Math.Abs(pileNumber - selector); if (olddistance > 2) { olddistance = Math.Abs(olddistance - 5); } int newdistance = Math.Abs(i - selector); if (newdistance > 2) { newdistance = Math.Abs(newdistance - 5); } if (newdistance < olddistance) { isLeftPile = true; pileNumber = i; } } else { moves = true; isLeftPile = true; pileNumber = i; } } if ((cv == 0 && value2 == 12) || (cv == 12 && value2 == 0) || (cv == value2 + 1 || cv == value2 - 1)) { if (moves) { int olddistance = Math.Abs(pileNumber - selector); if (olddistance > 2) { olddistance = Math.Abs(olddistance - 5); } int newdistance = Math.Abs(i - selector); if (newdistance > 2) { newdistance = Math.Abs(newdistance - 5); } if (newdistance < olddistance) { isLeftPile = false; pileNumber = i; } } else { moves = true; isLeftPile = false; pileNumber = i; } } } } return(moves); }
public bool ExistAMove2(Pile[] Hand, Pile rgamestack, Pile lgamestack) { bool moves = false; int maxPile = -2; int maxFurtherMoves = -1; Card[] Hands = new Card[Hand.Length]; for (int i = 0; i < Hand.Length; i++) { if (Hand[i].Count() != 0) { Hands[i] = Hand[i].Peek(); } } Card right = rgamestack.Peek(); Card left = lgamestack.Peek(); for (int i = 0; i < Hands.Length; i++) { if (Hands[i] != null) { int cv = Hands[i].cardValue; int value1 = left.cardValue; int value2 = right.cardValue; if ((cv == 0 && value1 == 12) || (cv == 12 && value1 == 0) || (cv == value1 + 1 || cv == value1 - 1)) { Card[] newHand = new Card[Hands.Length]; for (int j = 0; j < Hands.Length; j++) { if (j != i) { newHand[j] = Hands[j]; } } int tempFurtherMoves = FurtherMoves(newHand, Hands[i], right); if (moves) { if (tempFurtherMoves > maxFurtherMoves) { maxFurtherMoves = tempFurtherMoves; maxPile = i; isLeftPile = true; } if (tempFurtherMoves == maxFurtherMoves) { int olddistance = Math.Abs(maxPile - selector); if (olddistance > 2) { olddistance = Math.Abs(olddistance - 5); } int newdistance = Math.Abs(i - selector); if (newdistance > 2) { newdistance = Math.Abs(newdistance - 5); } if (newdistance < olddistance) { isLeftPile = true; maxPile = i; } } } else { moves = true; isLeftPile = true; maxPile = i; maxFurtherMoves = tempFurtherMoves; } pileNumber = maxPile; } if ((cv == 0 && value2 == 12) || (cv == 12 && value2 == 0) || (cv == value2 + 1 || cv == value2 - 1)) { Card[] newHand = new Card[Hands.Length]; for (int j = 0; j < Hands.Length; j++) { if (j != i) { newHand[j] = Hands[j]; } } int tempFurtherMoves = FurtherMoves(newHand, left, Hands[i]); if (moves) { if (tempFurtherMoves > maxFurtherMoves) { maxFurtherMoves = tempFurtherMoves; maxPile = i; isLeftPile = false; } if (tempFurtherMoves == maxFurtherMoves) { int olddistance = Math.Abs(maxPile - selector); if (olddistance > 2) { olddistance = Math.Abs(olddistance - 5); } int newdistance = Math.Abs(i - selector); if (newdistance > 2) { newdistance = Math.Abs(newdistance - 5); } if (newdistance < olddistance) { isLeftPile = false; maxPile = i; } } } else { moves = true; isLeftPile = false; maxPile = i; maxFurtherMoves = tempFurtherMoves; } pileNumber = maxPile; } } } return(moves); }
// plays cards from selected piles to destination piles public void PlayCard(Player player, int selectedPile, Pile destinationPile) { if (speedState != gameState.GamePlay) return; Pile fromPile; if (player.isPlayer1) fromPile = yourCards[player.selector]; else fromPile = opponentCards[player.selector]; if (fromPile.Count() == 0) { return; } if (fromPile.drawnTo) return; speedState = gameState.PlayingCard; Card c = fromPile.Peek(); int cv = c.cardValue; int value = destinationPile.Peek().cardValue; if ((cv == 0 && value == 12) || (cv == 12 && value == 0) || (cv == value + 1 || cv == value - 1)) { //if(myType == gameType.Timed) delayTimer.ResetTimer(0); Card m = fromPile.Take(); m.toPile(destinationPile); if (soundOn) { playcard.Play(); } if (vibrateOn) { GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f); } m.Rotate(Actions.ExpoMove, (float)(random.NextDouble() - .5) / 2, .3f); m.WhenDoneMoving(delegate() { m.Move(Actions.LinearMove, m.attributes.position + new Vector2(random.Next(-5,5), random.Next(-5, 5)), 3f); player.score++; if (powerUpOn) { if (destinationPile.hasPowerUp) { Player victim; if (player.isPlayer1) victim = opp; else victim = you; destinationPile.PlayPowerUp(victim); } } speedState = gameState.GamePlay; if (player.isPlayer1) { if (yourStack.Count() != 0) { if (fromPile.Count() == 0) { DrawCard(yourStack, fromPile, 0f); } } } else { if (opponentStack.Count() != 0) { if (fromPile.Count() == 0) { DrawCard(opponentStack, fromPile, 0f); } } } Shake(); SelectPowerUp(destinationPile); ParticleEngine smoke = new ParticleEngine(textures, destinationPile.position,new Vector2(300,300), m.attributes.depth, .3f, Color.WhiteSmoke); base.Add(smoke); }); } else { speedState = gameState.GamePlay; c.attributes.color = Color.Red; Timer timer = new Timer(1); base.Add(timer); timer.SetTimer(0, 1, delegate() { c.attributes.color = Color.White; player.RemovePenalty(); }); player.Penalize(); } }