// turns game on public override void TurnOn() { if (myType == gameType.Timed) { gameTimer = new Timer(1); gameTimer.SetTimer(0, gameLength, delegate() { Winner(DetermineWinner()); ableToReBegin = false; ableToReBegin2 = false; /*time1.Fade(4);*/ time2.Fade(4); speedState = gameState.Winner; }); /*time1 = new Text(gameTimer.getCountDown(0), _font); * time1.height = 100; * time1.attributes.position = new Vector2(yourName.attributes.position.X, oppName.attributes.position.Y); * time1.isSeeable = true; * time1.attributes.color = Color.Black; * time1.attributes.depth = .02f; * time1.scale = new Vector2(.15f, .15f);*/ time2 = new Text(gameTimer.getCountDown(0), _font); time2.height = 100; time2.attributes.position = new Vector2(oppName.attributes.position.X, yourName.attributes.position.Y); time2.isSeeable = true; time2.attributes.color = Color.Black; time2.attributes.depth = .02f; time2.scale = new Vector2(.12f, .12f); } Deal(); base.TurnOn(); }
// public void unPauseFreeze() { freezeTimer.isPaused = false; Timer newTimer = new Timer(2); newTimer.SetTimer(2, (float)timeLeft, delegate() { UnFreeze(); }); }
// shakes screen public void Shake() { Timer timer = new Timer(1); base.Add(timer); isShaking = true; timer.SetTimer(0, .2f, delegate() { isShaking = false; }); }
// starts the game public void BeginGame() { Timer timer = new Timer(1); base.Add(timer); timer.SetTimer(0, .4f, delegate() { speedState = gameState.GamePlay; ableToReBegin = true; }); DrawCard(lSpitStack, lGameStack, 0f); DrawCard(rSpitStack, rGameStack, 0f); you.TurnOn(); opp.TurnOn(); }
// public void Freeze() { if (myState == PlayerState.Frozen || (myState == PlayerState.Penalized && oldState == PlayerState.Frozen)) { freezeTimer.ResetTimer(0); } oldState = PlayerState.Frozen; if (myState != PlayerState.Penalized) { myState = PlayerState.Frozen; } freezeTimer.SetTimer(0, 4, delegate() { UnFreeze(); }); }
// performs button actions .5 seconds after it's clicked, then uses delegates to make events occur public void Click() { if (!isSetting) { clicked = true; attributes.color = Color.Orange; buttonTimer.SetTimer(0, .5f, delegate() { Clicked(); clicked = false; attributes.color = Color.Black; }); } else { toggled++; clicked = true; attributes.color = Color.Orange; moduloToggled = toggled % 2; if (moduloToggled == 0) { buttonTimer.SetTimer(0, .5f, delegate() { Clicked(); clicked = false; attributes.color = Color.Black; }); } else { buttonTimer.SetTimer(0, .5f, delegate() { Clicked(); clicked = false; attributes.color = Color.Orange; }); } } }
// menu constructor public Menu(Drawable background, int numberOfButtons, Text title, String[] buttonNames, Button.ClickHandler[] buttonActions, SpriteFont buttonFont, Drawable checkMark) : base(background) { // gives buttons height & width, adds title, makes buttons & gives position in middle of screen buttonHeight = 75; buttons = new Button[numberOfButtons]; buttonAmount = numberOfButtons; _checkMark = checkMark; base.Add(title); title.attributes.position = new Vector2(512, title.height / 2 + 40); title.attributes.depth = .01f; maxButtonWidth = 0; // makes new buttons, adds heights, adds actions and events for if clicked for (int i = 0; i < numberOfButtons; i++) { buttons[i] = new Button(buttonNames[i], buttonFont, new Vector2(512, title.height + 140 + ((800 - title.height - 80 - buttonHeight) / numberOfButtons) * i), Color.Black, _checkMark); buttons[i].height = buttonHeight; buttons[i].Clicked += buttonActions[i]; buttons[i].Clicked += delegate() { for (int j = 0; j < numberOfButtons; j++) { if (j != i) { buttons[j].Remove(); } } }; if (buttons[i].width > maxButtonWidth) { maxButtonWidth = buttons[i].width; } base.Add(buttons[i]); buttons[i].attributes.depth = .01f; } // sets selected button to the top button selected = 0; // initializes menu to off, then turns it on after .5 seconds myState = menuState.Off; keysOff = false; Timer state = new Timer(1); base.Add(state); state.SetTimer(0, .5f, delegate() { myState = menuState.On; }); }
// draws card to different piles public void DrawCard(Pile drawPile, Pile destinationPile, float delay) { if (destinationPile.drawnTo) { return; } ableToReBegin = false; destinationPile.drawnTo = true; Card temp = null; switch (myType) { case gameType.Levels: case gameType.Normal: temp = drawPile.Take(); break; case gameType.Marathon: case gameType.Timed: temp = getRandomCard(drawPile); base.Add(temp); break; } temp.Flip(true, delay); temp.toPile(destinationPile, delay); if (destinationPile.hasPowerUp) { destinationPile.RemovePowerUp(); } temp.WhenDoneMoving(delegate() { destinationPile.drawnTo = false; Timer drawTimer = new Timer(1); base.Add(drawTimer); drawTimer.SetTimer(0, .5f, delegate() { ableToReBegin = true; }); if ((destinationPile == lGameStack || destinationPile == rGameStack) && !destinationPile.hasPowerUp) { SelectPowerUp(destinationPile); } }); }
// overloaded constructor to add buttonheight public Menu(Drawable background, int numberOfButtons, Text title, String[] buttonNames, Button.ClickHandler[] buttonActions, SpriteFont buttonFont, int buttonHeight, bool PAMenuButtonHeight) : base(background) { this.buttonHeight = buttonHeight; buttons = new Button[numberOfButtons]; base.Add(title); title.attributes.position = new Vector2(512, title.height / 2 + 40); title.attributes.depth = .01f; maxButtonWidth = 0; for (int i = 0; i < numberOfButtons; i++) { buttons[i] = new Button(buttonNames[i], buttonFont, new Vector2(512, 550 + (125 * i)), Color.Black); buttons[i].height = 100; buttons[i].Clicked += buttonActions[i]; buttons[i].Clicked += delegate() { for (int j = 0; j < numberOfButtons; j++) { if (j != i) { buttons[j].Remove(); } } }; if (buttons[i].width > maxButtonWidth) { maxButtonWidth = buttons[i].width; } base.Add(buttons[i]); buttons[i].attributes.depth = .01f; } selected = 0; myState = menuState.Off; keysOff = false; Timer state = new Timer(1); base.Add(state); state.SetTimer(0, .5f, delegate() { myState = menuState.On; }); }
// menu constructor public Menu(Drawable background, int numberOfButtons, Text title, String[] buttonNames, Button.ClickHandler[] buttonActions, SpriteFont buttonFont) : base(background) { // gives buttons height & width, adds title, makes buttons & gives position in middle of screen buttonHeight = 75; buttons = new Button[numberOfButtons]; buttonAmount = numberOfButtons; base.Add(title); title.attributes.position = new Vector2(512, title.height / 2 + 40); title.attributes.depth = .01f; maxButtonWidth = 0; // makes new buttons, adds heights, adds actions and events for if clicked for (int i = 0; i < numberOfButtons; i++) { buttons[i] = new Button(buttonNames[i], buttonFont, new Vector2(512, title.height + 140 + ((800 - title.height - 80 - buttonHeight) / numberOfButtons) * i), Color.Black); buttons[i].height = buttonHeight; buttons[i].Clicked += buttonActions[i]; buttons[i].Clicked += delegate() { for (int j = 0; j < numberOfButtons; j++) { if (j != i) buttons[j].Remove(); } }; if (buttons[i].width > maxButtonWidth) maxButtonWidth = buttons[i].width; base.Add(buttons[i]); buttons[i].attributes.depth = .01f; } // sets selected button to the top button selected = 0; // initializes menu to off, then turns it on after .5 seconds myState = menuState.Off; keysOff = false; Timer state = new Timer(1); base.Add(state); state.SetTimer(0, .5f, delegate() { myState = menuState.On; }); }
// initializes lots of variables public Speed(Card[] deckOfCards, Drawable background, Texture2D selector, SpriteFont font, Player bottom, Player top, List <Texture2D> particles, gameType gameType, SoundEffect shuffling, SoundEffect playingcard, SoundEffectInstance shuffinstance, bool isSoundOn, bool isPowerUpOn, bool isVibrateOn, PowerUp powerup) : base(background) { myType = gameType; cardcounter = new int[52]; random = new Random(); _font = font; shuffle = shuffling; playcard = playingcard; shuffleinstance = shuffinstance; isHalted = false; isShaking = false; textures = particles; soundOn = isSoundOn; powerUpOn = isPowerUpOn; vibrateOn = isVibrateOn; ableToReBegin = true; ableToReBegin2 = true; freeze = powerup; freeze.isSeeable = false; base.Add(freeze); freeze.WhenPlayed(delegate(Player player) { player.Freeze(); Timer timer = new Timer(1); base.Add(timer); timer.SetTimer(0, 4, delegate() { player.UnFreeze(); }); freeze.Fade(4); if (player.isPlayer1) { freeze.Move(Actions.ExpoMove, yourSelector.attributes.position, 1); } else { freeze.Move(Actions.ExpoMove, oppSelector.attributes.position, 1); } }); you = bottom; opp = top; you.SelectedCardLeft += delegate(){ PlayCard(you, you.selector, lGameStack); }; you.SelectedCardRight += delegate() { PlayCard(you, you.selector, rGameStack); }; opp.SelectedCardLeft += delegate() { PlayCard(opp, opp.selector, lGameStack); }; opp.SelectedCardRight += delegate() { PlayCard(opp, opp.selector, rGameStack); }; you.score = 0; opp.score = 0; deck = new Card[deckOfCards.Length]; cards = new Card[deckOfCards.Length]; for (int i = 0; i < deckOfCards.Length; i++) { deck[i] = deckOfCards[i]; cards[i] = deckOfCards[i]; } for (int i = 0; i < cards.Length; i++) { cards[i].attributes.position = new Vector2(-100, 100); cards[i].isFaceUp = false; cards[i].isSeeable = true; cards[i].attributes.color = Color.White; cards[i].attributes.rotation = 0; cards[i].ClearTweeners(); cards[i].attributes.height = 180; cards[i].attributes.width = 130; deck[i].attributes.position = new Vector2(-100, 100); deck[i].isFaceUp = false; deck[i].isSeeable = true; deck[i].attributes.color = Color.White; deck[i].attributes.rotation = 0; deck[i].ClearTweeners(); deck[i].attributes.height = 180; deck[i].attributes.width = 130; } yourStack = new Pile(new Vector2(897, 675)); opponentStack = new Pile(new Vector2(127, 125)); lSpitStack = new Pile(new Vector2(217, 400)); rSpitStack = new Pile(new Vector2(807, 400)); lGameStack = new Pile(new Vector2(413, 400)); rGameStack = new Pile(new Vector2(610, 400)); yourCards = new Pile[5]; opponentCards = new Pile[5]; for (int i = 0; i < yourCards.Length; i++) { opponentCards[i] = new Pile(new Vector2(opponentStack.position.X + (i + 1) * 154, opponentStack.position.Y)); yourCards[i] = new Pile(new Vector2(yourStack.position.X - (i + 1) * 154, yourStack.position.Y)); } yourName = new Text(you.playerName + " - ", _font); yourName.height = 100; yourName.attributes.position = new Vector2((yourCards[3].position.X + yourCards[4].position.X) / 2 - 20, (yourCards[3].position.Y + lGameStack.position.Y) / 2); yourName.isSeeable = true; yourName.attributes.color = Color.LightSkyBlue; yourName.attributes.depth = .02f; yourName.scale = new Vector2(.15f, .15f); oppName = new Text(" - " + opp.playerName, _font); oppName.height = 100; oppName.attributes.position = new Vector2((opponentCards[3].position.X + opponentCards[4].position.X) / 2 + 20, (opponentCards[3].position.Y + lGameStack.position.Y) / 2); oppName.isSeeable = true; oppName.attributes.color = Color.Red; oppName.attributes.depth = .02f; oppName.scale = new Vector2(.15f, .15f); yourScore = new Text(you.score.ToString(), _font); yourScore.height = 100; yourScore.attributes.position = new Vector2(yourName.attributes.position.X + yourName.width / 2 + 10, yourName.attributes.position.Y); yourScore.isSeeable = true; yourScore.attributes.color = Color.LightSkyBlue; yourScore.attributes.depth = .02f; yourScore.scale = new Vector2(.15f, .15f); oppScore = new Text(opp.score.ToString(), _font); oppScore.height = 100; oppScore.attributes.position = new Vector2(oppName.attributes.position.X - oppName.width / 2 - 10, oppName.attributes.position.Y); oppScore.isSeeable = true; oppScore.attributes.color = Color.Red; oppScore.attributes.depth = .02f; oppScore.scale = new Vector2(.15f, .15f); for (int i = 0; i < cards.Length; i++) { base.Add(cards[i]); } oppSelector = new Drawable() { attributes = new Attributes() { texture = selector, position = new Vector2(-100, -100), color = Color.Red, height = 190, width = 140, depth = .11f, rotation = 0 } }; yourSelector = new Drawable() { attributes = new Attributes() { texture = selector, position = new Vector2(-100, -100), color = Color.LightSkyBlue, height = 190, width = 140, depth = .11f, rotation = 0 } }; base.Add(oppSelector); base.Add(yourSelector); if (myType == gameType.Marathon) { winningscore = 30; } //if (myType == gameType.Timed) //{ gameLength = 120; delayTimer = new Timer(1); delayTimer.SetTimer(0, 4, delegate() { if (speedState == gameState.GamePlay && lSpitStack.Count() != 0) { speedState = gameState.ReBeginning; Text delay = new Text("Delay", font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400), depth = .001f, }, height = 400, }; base.Add(delay); delay.Fade(2); delay.WhenDoneFading(delegate() { BeginGame(); }); } }); //} }
// if top player wins, displays certain text & fades some drawables& adds endgame actions public void OppAWinner() { speedState = gameState.Winner; Text winner = new Text("Winner!!!", _font) { attributes = new Attributes() { color = Color.Red, position = new Vector2(512, 180), //rotation = -.2f, depth = .1f }, scale = new Vector2(.8f, .8f) }; Text loser = new Text("Scrub!!!", _font) { attributes = new Attributes() { color = Color.DarkBlue, position = new Vector2(512, 650), //rotation = -.2f, depth = .1f }, scale = new Vector2(.8f, .8f) }; yourSelector.Fade(2); oppSelector.Fade(2); oppSelector.Move(Actions.ExpoMove, new Vector2(512, 400), 2); oppSelector.WhenDoneMoving(delegate() { base.Add(winner); base.Add(loser); }); oppSelector.Scale(Actions.LinearMove, yourSelector.attributes.scale * 2, 2); Timer endGame = new Timer(2); base.Add(endGame); endGame.SetTimer(0, 6, delegate() { yourScore.attributes.color = Color.LightSkyBlue; yourScore.isSeeable = true; yourScore.attributes.position = new Vector2(624, 675); yourScore.height = 150; oppScore.attributes.color = Color.Red; oppScore.isSeeable = true; oppScore.attributes.position = new Vector2(400, 675); oppScore.height = 150; Text dash = new Text(" - ", _font); dash.attributes = new Attributes() { color = Color.Black, position = new Vector2(512, 675) }; dash.isSeeable = true; dash.height = 150; base.Add(dash); if (myType == gameType.Levels) { YouLost(); } else { Reset(); } }); endGame.SetTimer(1, 4, delegate() { winner.Fade(2); loser.Fade(2); }); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // loads up badaboom font, since it is "SpriteFont3" font = Content.Load<SpriteFont>("SpriteFont3"); SpriteFont instructionsfont = this.Content.Load<SpriteFont>("SpriteFont1"); // loads up background as drawable background = new Drawable() { attributes = new Attributes() { texture = this.Content.Load<Texture2D>("PossibleBackground"), color = Color.White, position = new Vector2(512, 400), depth = 1, height = 802, width = 1026, rotation = 0 } }; Drawable PauseBackground = new Drawable() { attributes = new Attributes() { texture = this.Content.Load<Texture2D>("PlainWhite"), color = new Color(0, 100, 100, 23), position = new Vector2(512, 400), depth = .05f, height = 802, width = 1026, rotation = 0 } }; // makes an example in which the background is transparent Drawable playAgainBackground = new Drawable() { attributes = new Attributes() { texture = this.Content.Load<Texture2D>("PossibleBackground"), color = Color.White, position = new Vector2(512, 400), depth = 1, height = 802, width = 1026, rotation = 0 } }; // creates players player1 = new HumanPlayer(Keys.Up, Keys.Down, Keys.Left, Keys.Right, "Ben", true); player2 = new HumanPlayer(Keys.W, Keys.S, Keys.A, Keys.D, "Ben", false); computer = new ComputerPlayer("computer", false); computer2 = new ComputerPlayer("computer2", true); // loads up cards & assigns values #region Create cards[] cards = new Card[52]; cards[0] = new Card(0, this.Content.Load<Texture2D>("AceClubs"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[1] = new Card(1, this.Content.Load<Texture2D>("TwoClubs"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[2] = new Card(2, this.Content.Load<Texture2D>("ThreeClubs"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[3] = new Card(3, this.Content.Load<Texture2D>("FourClubs"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[4] = new Card(4, this.Content.Load<Texture2D>("FiveClubs"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[5] = new Card(5, this.Content.Load<Texture2D>("SixClubs"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[6] = new Card(6, this.Content.Load<Texture2D>("SevenClubs"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[7] = new Card(7, this.Content.Load<Texture2D>("EightClubs"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[8] = new Card(8, this.Content.Load<Texture2D>("NineClubs"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[9] = new Card(9, this.Content.Load<Texture2D>("TenClubs"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[10] = new Card(10, this.Content.Load<Texture2D>("JackClubs"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[11] = new Card(11, this.Content.Load<Texture2D>("QueenClubs"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[12] = new Card(12, this.Content.Load<Texture2D>("KingClubs"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[13] = new Card(13, this.Content.Load<Texture2D>("AceDiamonds"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[14] = new Card(14, this.Content.Load<Texture2D>("TwoDiamonds"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[15] = new Card(15, this.Content.Load<Texture2D>("ThreeDiamonds"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[16] = new Card(16, this.Content.Load<Texture2D>("FourDiamonds"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[17] = new Card(17, this.Content.Load<Texture2D>("FiveDiamonds"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[18] = new Card(18, this.Content.Load<Texture2D>("SixDiamonds"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[19] = new Card(19, this.Content.Load<Texture2D>("SevenDiamonds"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[20] = new Card(20, this.Content.Load<Texture2D>("EightDiamonds"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[21] = new Card(21, this.Content.Load<Texture2D>("NineDiamonds"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[22] = new Card(22, this.Content.Load<Texture2D>("TenDiamonds"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[23] = new Card(23, this.Content.Load<Texture2D>("JackDiamonds"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[24] = new Card(24, this.Content.Load<Texture2D>("QueenDiamonds"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[25] = new Card(25, this.Content.Load<Texture2D>("KingDiamonds"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[26] = new Card(26, this.Content.Load<Texture2D>("AceHearts"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[27] = new Card(27, this.Content.Load<Texture2D>("TwoHearts"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[28] = new Card(28, this.Content.Load<Texture2D>("ThreeHearts"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[29] = new Card(29, this.Content.Load<Texture2D>("FourHearts"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[30] = new Card(30, this.Content.Load<Texture2D>("FiveHearts"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[31] = new Card(31, this.Content.Load<Texture2D>("SixHearts"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[32] = new Card(32, this.Content.Load<Texture2D>("SevenHearts"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[33] = new Card(33, this.Content.Load<Texture2D>("EightHearts"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[34] = new Card(34, this.Content.Load<Texture2D>("NineHearts"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[35] = new Card(35, this.Content.Load<Texture2D>("TenHearts"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[36] = new Card(36, this.Content.Load<Texture2D>("JackHearts"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[37] = new Card(37, this.Content.Load<Texture2D>("QueenHearts"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[38] = new Card(38, this.Content.Load<Texture2D>("KingHearts"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[39] = new Card(39, this.Content.Load<Texture2D>("AceSpades"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[40] = new Card(40, this.Content.Load<Texture2D>("TwoSpades"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[41] = new Card(41, this.Content.Load<Texture2D>("ThreeSpades"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[42] = new Card(42, this.Content.Load<Texture2D>("FourSpades"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[43] = new Card(43, this.Content.Load<Texture2D>("FiveSpades"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[44] = new Card(44, this.Content.Load<Texture2D>("SixSpades"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[45] = new Card(45, this.Content.Load<Texture2D>("SevenSpades"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[46] = new Card(46, this.Content.Load<Texture2D>("EightSpades"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[47] = new Card(47, this.Content.Load<Texture2D>("NineSpades"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[48] = new Card(48, this.Content.Load<Texture2D>("TenSpades"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[49] = new Card(49, this.Content.Load<Texture2D>("JackSpades"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[50] = new Card(50, this.Content.Load<Texture2D>("QueenSpades"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); cards[51] = new Card(51, this.Content.Load<Texture2D>("KingSpades"), this.Content.Load<Texture2D>("cardBack2.0"), new Vector2(-100, 100), true); #endregion Create cards[] // loads up playable music, creates instance also, which may not be necessary.. shuffle = Content.Load<SoundEffect>("Audio\\Waves\\shuffle1"); playcard = Content.Load<SoundEffect>("Audio\\Waves\\slapcard"); shuffleinstance = shuffle.CreateInstance(); aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio; // loads up badtime meme as a joke (for if instructions are clicked during gameplay) BadTime = new Drawable() { attributes = new Attributes() { texture = this.Content.Load<Texture2D>("BadTime"), color = Color.White, position = new Vector2(512, 400), depth = 0, scale = new Vector2(1.5f,1.5f), }, isSeeable = false, }; // loads up image of a checkmark checkMark = new Drawable() { attributes = new Attributes() { texture = this.Content.Load<Texture2D>("checkMark"), color = Color.White, depth = 0, }, isSeeable = false, }; // loads card selector selector = this.Content.Load<Texture2D>("CardSelector"); // loads circles, diamonds, stars for the particle generator textures = new List<Texture2D>(); textures.Add(Content.Load<Texture2D>("circle")); textures.Add(Content.Load<Texture2D>("diamond")); textures.Add(Content.Load<Texture2D>("star")); // creates instance of freeze powerup freeze = new PowerUp(Color.LightBlue, textures,powerUpsOn) { attributes = new Attributes() { texture = this.Content.Load<Texture2D>("Freeze"), position = new Vector2(100, 100), color = Color.White } }; freeze.isSeeable = false; #region PlayAgainMenu // title for play again menu Text playAgain = new Text("Play Again?", font) { attributes = new Attributes() { color = Color.Black, depth = 0f, }, height = 200 }; // button names for play again menu String[] PAButtonNames = new String[2]; PAButtonNames[0] = "Yes"; PAButtonNames[1] = "No"; // starts new game or goes to main menu depending on choice Button.ClickHandler[] playAgainAction = new Button.ClickHandler[2]; // if playagain is chosen from the menu, following options are available playAgainAction[0] = delegate() { player1.Reset(); player2.Reset(); computer.Reset(); if (speed != null) { // switch based on what speed game type is being played switch (speed.myType) { // // game length? case Speed.gameType.Timed: int x = speed.gameLength; speed = new Speed(cards, background, selector, font, speed.you, speed.opp, textures, speed.myType, shuffle, playcard, shuffleinstance, SoundSwitch.getOnOff(), PowerUpSwitch.getOnOff(), vibrateOn, freeze); speed.gameLength = x; break; // case Speed.gameType.Marathon: int y = speed.winningscore; speed = new Speed(cards, background, selector, font, speed.you, speed.opp, textures, speed.myType, shuffle, playcard, shuffleinstance, SoundSwitch.getOnOff(), PowerUpSwitch.getOnOff(), vibrateOn, freeze); speed.winningscore = y; break; // if neither of the other cases apply, do this default action default: speed = new Speed(cards, background, selector, font, speed.you, speed.opp, textures, speed.myType, shuffle, playcard, shuffleinstance, SoundSwitch.getOnOff(), PowerUpSwitch.getOnOff(), vibrateOn, freeze); break; } speed.TurnOn(); PlayAgain.isPaused = true; } if (levels != null) { levels = new Levels(cards, background, selector, font, levels._player1, textures, shuffle, playcard, shuffleinstance, SoundSwitch.getOnOff(), PowerUpSwitch.getOnOff(), vibrateOn, (Levels.Difficulty) DifficultySwitch.getState(), freeze); levels.StartGame(); PlayAgain.isPaused = true; } }; // if exit is chosen, nullifies levels or speed, returns to main menu playAgainAction[1] = delegate() { if (speed != null) speed = null; if (levels != null) levels = null; PlayAgain.isPaused = true; MainMenu.isPaused = false; }; // makes playagain menu PlayAgain = new Menu(playAgainBackground, 2, playAgain, PAButtonNames, playAgainAction, font, 100, true); #endregion #region PauseMenu // creates pause menu title Text pause = new Text("Pause", font) { attributes = new Attributes() { color = Color.Black, //rotation = -.1f, depth = 0f, }, height = 300 }; // makes names for each button on pause menu String[] pauseNames = new String[5]; pauseNames[0] = "Resume"; pauseNames[1] = "Restart"; pauseNames[2] = "Instructions"; pauseNames[3] = "Settings"; pauseNames[4] = "Main Menu"; // sets up an array of events based on which button is clicked Button.ClickHandler[] pauseActions = new Button.ClickHandler[5]; // disables pause menu & resumes speed goes to instructions if that's chosen, and goes to main menu if these aren't the case pauseActions[0] = delegate() { if (speed != null && speed.isPaused == false) { speed.Resume(); Pause.isPaused = true; } if (levels != null && levels.isPaused == false) { levels.Resume(); Pause.isPaused = true; } }; // disables pause menu & displays instructions pauseActions[1] = delegate() { player1.Reset(); player2.Reset(); computer.Reset(); // restarts SPEED game if restart is chosen from pause menu if (speed != null) { speed = new Speed(cards, background, selector, font, speed.you, speed.opp, textures, speed.myType, shuffle, playcard, shuffleinstance, SoundSwitch.getOnOff(), PowerUpSwitch.getOnOff(), vibrateOn, freeze); speed.TurnOn(); } // restarts LEVELS game if restart chosen from pause menu else if (levels != null) { player1.Reset(); levels = new Levels(cards, background,selector,font, player1, textures, shuffle, playcard, shuffleinstance, SoundSwitch.getOnOff(), PowerUpSwitch.getOnOff(), vibrateOn, (Levels.Difficulty)DifficultySwitch.getState(), freeze); levels.StartGame(); } Pause.isPaused = true; }; // disables pause menu & shows (fake) instructions.. just a funny image pauseActions[2] = delegate() { BadTime.isSeeable = true; Pause.keysOff = true; Timer timer = new Timer(1); Pause.Add(timer); timer.SetTimer(0, 4, delegate() { BadTime.isSeeable = false; Pause.keysOff = false; }); }; pauseActions[3] = delegate() { Pause.isPaused = true; settings2.isPaused = false; }; // returns to main menu pauseActions[4] = delegate() { MainMenu.isPaused = false; Pause.isPaused = true; speed = null; levels = null; }; // creates instance of pause menu Pause = new Menu(PauseBackground, 5, pause, pauseNames, pauseActions, font); Pause.Add(BadTime); #endregion #region SettingsMenu // settings title Text settingsText = new Text("Settings", font) { attributes = new Attributes() { color = Color.Black, position = new Vector2(512, 100), depth = 0f, }, scale = new Vector2(.5f, .5f) }; SoundSwitch = new Switch("Sound", 300, font, 0); PowerUpSwitch = new Switch("Power Ups", 400, font, 0); VibrateSwitch = new Switch("(XBOX)Vibrate", 500, font, 0); String[] names = new String[4]; names[0] = "Beginner"; names[1] = "Easy"; names[2] = "Medium"; names[3] = "Hard"; DifficultySwitch = new Switch("Difficulty", names, 600, font, 2); Switch[] settingSwitches = new Switch[4]; settingSwitches[0] = SoundSwitch; settingSwitches[1] = PowerUpSwitch; settingSwitches[2] = VibrateSwitch; settingSwitches[3] = DifficultySwitch; settings = new Settings(settingsText, settingSwitches, background, font); settings.SetButton(delegate() { settings.isPaused = true; MainMenu.isPaused = false; }); #endregion #region SettingsMenu2 // creates settings buttons Switch[] settingSwitches2 = new Switch[3]; settingSwitches2[0] = SoundSwitch; settingSwitches2[1] = DifficultySwitch; settingSwitches2[2] = VibrateSwitch; settings2 = new Settings(settingsText, settingSwitches2, PauseBackground, font); settings2.SetButton(delegate() { settings2.isPaused = true; Pause.isPaused = false; }); #endregion #region InstructionsMenu // makes the text for the instructions menu Text Instructions = new Text("Instructions", font) { attributes = new Attributes() { color = Color.Black, //rotation = -.05f, depth = 0f, }, scale = new Vector2(.4f, .4f) }; // makes names for instructions buttons String[] InstructionsMenuString = new String[5]; InstructionsMenuString[0] = "Controls"; InstructionsMenuString[1] = "Rules"; InstructionsMenuString[2] = "Winning"; InstructionsMenuString[3] = "PowerUps"; InstructionsMenuString[4] = "Back"; Button.ClickHandler[] InstructionsMenuAction = new Button.ClickHandler[5]; // displays controls section of instructions InstructionsMenuAction[0] = delegate() { Controls.isPaused = false; InstructionsMenu.isPaused = true; }; // displays rules section of instructions InstructionsMenuAction[1] = delegate() { InstructionsMenu.isPaused = true; Rules.isPaused = false; }; // displays winning sections of instructions InstructionsMenuAction[2] = delegate() { InstructionsMenu.isPaused = true; Winning.isPaused = false; }; // displays powerups section of instructions InstructionsMenuAction[3] = delegate() { InstructionsMenu.isPaused = true; PowerUps.isPaused = false; }; // goes back to the main menu from instructions menu InstructionsMenuAction[4] = delegate() { InstructionsMenu.isPaused = true; MainMenu.isPaused = false; }; // creates instance of instructions menu InstructionsMenu = new Menu(background, 5, Instructions, InstructionsMenuString, InstructionsMenuAction, font); #endregion #region MainMenu // game title Text title = new Text("Speed!", font) { attributes = new Attributes() { color = Color.Black, //rotation = -.2f, depth = 0f, }, scale = new Vector2(.5f, .5f) }; // creates main menu buttons String[] mainMenuString = new String[5]; mainMenuString[0] = "Single Player"; mainMenuString[1] = "Multiplayer"; mainMenuString[2] = "Instructions"; mainMenuString[3] = "Settings"; mainMenuString[4] = "Exit"; Button.ClickHandler[] mainMenuAction = new Button.ClickHandler[5]; // initializes mode to oneplayer, moves on to the one player game menu mainMenuAction[0] = delegate() { MainMenu.isPaused = true; GameMenu1.isPaused = false; myMode = Mode.onePlayer; }; // initializes mode to twoplayer, moves on to the two player game menu mainMenuAction[1] = delegate() { MainMenu.isPaused = true; GameMenu2.isPaused = false; myMode = Mode.twoPlayer; }; // if "instructions" chosen, displays instructions mainMenuAction[2] = delegate() { InstructionsMenu.isPaused = false; MainMenu.isPaused = true; }; // if "settings" chosen, displays settings mainMenuAction[3] = delegate() { MainMenu.isPaused = true; settings.isPaused = false; }; // exits game mainMenuAction[4] = delegate() { this.Exit(); }; //makes main menu and turns it on MainMenu = new Menu(background, 5, title, mainMenuString, mainMenuAction, font); MainMenu.TurnOn(); #endregion #region GameMenu1 // creates playgame text Text playgame1 = new Text("Select Game", font) { attributes = new Attributes() { color = Color.Black, //rotation = -.05f, depth = 0f, }, scale = new Vector2(.5f, .5f) }; // makes menu buttons for one player String[] gameMenuString1 = new String[5]; gameMenuString1[0] = "Normal"; gameMenuString1[1] = "Marathon"; gameMenuString1[2] = "Timed"; gameMenuString1[3] = "Levels"; gameMenuString1[4] = "Back"; Button.ClickHandler[] gameMenuAction1 = new Button.ClickHandler[5]; // begins normal game vs the computer gameMenuAction1[0] = delegate() { player1.Reset(); player2.Reset(); computer.Reset(); speed = new Speed(cards, background, selector, font, player1, computer, textures, Speed.gameType.Normal, shuffle, playcard, shuffleinstance, SoundSwitch.getOnOff(), PowerUpSwitch.getOnOff(), vibrateOn, freeze); speed.TurnOn(); GameMenu1.isPaused = true; }; // goes to 1 player marathon menu from main menu gameMenuAction1[1] = delegate() { player1.Reset(); player2.Reset(); computer.Reset(); speed = new Speed(cards, background, selector, font, player1, computer, textures, Speed.gameType.Marathon, shuffle, playcard, shuffleinstance, SoundSwitch.getOnOff(), PowerUpSwitch.getOnOff(), vibrateOn, freeze); MarathonMenu.isPaused = false; GameMenu1.isPaused = true; }; // goes to 1 player timed menu from main menu gameMenuAction1[2] = delegate() { player1.Reset(); player2.Reset(); computer.Reset(); speed = new Speed(cards, background, selector, font, player1, computer, textures, Speed.gameType.Timed, shuffle, playcard, shuffleinstance, SoundSwitch.getOnOff(), PowerUpSwitch.getOnOff(), vibrateOn, freeze); TimedMenu.isPaused = false; GameMenu1.isPaused = true; }; // begins levels mode vs computer gameMenuAction1[3] = delegate() { player1.Reset(); computer.Reset(); levels = new Levels(cards, background, selector, font, player1, textures, shuffle, playcard, shuffleinstance, SoundSwitch.getOnOff(), PowerUpSwitch.getOnOff(), vibrateOn, (Levels.Difficulty) DifficultySwitch.getState(), freeze); GameMenu1.isPaused = true; levels.StartGame(); }; // goes back to main menu from player 1 game menu gameMenuAction1[4] = delegate() { GameMenu1.isPaused = true; MainMenu.isPaused = false; }; // makes instance of game menu for single player GameMenu1 = new Menu(background, 5, playgame1, gameMenuString1, gameMenuAction1, font); #endregion #region GameMenu2 // creates playgame text Text playgame2 = new Text("Select Game", font) { attributes = new Attributes() { color = Color.Black, //rotation = -.05f, depth = 0f, }, scale = new Vector2(.5f, .5f) }; // creates button names for 2 player game menu String[] gameMenuString2 = new String[4]; gameMenuString2[0] = "Normal"; gameMenuString2[1] = "Marathon"; gameMenuString2[2] = "Timed"; gameMenuString2[3] = "Back"; Button.ClickHandler[] gameMenuAction2 = new Button.ClickHandler[4]; // begin normal game vs another player gameMenuAction2[0] = delegate() { player1.Reset(); player2.Reset(); computer.Reset(); speed = new Speed(cards, background, selector, font, player1, player2, textures, Speed.gameType.Normal, shuffle, playcard, shuffleinstance, SoundSwitch.getOnOff(), PowerUpSwitch.getOnOff(), vibrateOn, freeze); speed.TurnOn(); GameMenu2.isPaused = true; }; // goes to 2 player marathon menu from 2 player game menu gameMenuAction2[1] = delegate() { player1.Reset(); player2.Reset(); computer.Reset(); speed = new Speed(cards, background, selector, font, player1, player2, textures, Speed.gameType.Marathon, shuffle, playcard, shuffleinstance, SoundSwitch.getOnOff(), PowerUpSwitch.getOnOff(), vibrateOn, freeze); MarathonMenu.isPaused = false; GameMenu2.isPaused = true; }; // goes to 2 player timed menu from 2 player game menu gameMenuAction2[2] = delegate() { player1.Reset(); player2.Reset(); computer.Reset(); speed = new Speed(cards, background, selector, font, player1, player2, textures, Speed.gameType.Timed, shuffle, playcard, shuffleinstance, SoundSwitch.getOnOff(), PowerUpSwitch.getOnOff(), vibrateOn, freeze); TimedMenu.isPaused = false; GameMenu2.isPaused = true; }; // returns to main menu from 2 player game menu gameMenuAction2[3] = delegate() { GameMenu2.isPaused = true; MainMenu.isPaused = false; }; // makes new instance of 2 player game menu GameMenu2 = new Menu(background, 4, playgame2, gameMenuString2, gameMenuAction2, font); #endregion #region Controls // makes all the drawable text to display when control screen is chosen from instructions menu Drawable[][] ControlsText = new Drawable[1][]; #region FirstPage ControlsText[0] = new Drawable[9]; ControlsText[0][0] = new Text("Controls", instructionsfont) { height = 200, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 150), } }; ControlsText[0][1] = new Text("Bottom Player:", instructionsfont) { height = 100, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 225), } }; ControlsText[0][2] = new Text("Scroll through your cards - left and right arrow keys", instructionsfont) { height = 75, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 285), } }; ControlsText[0][3] = new Text("Card to left pile - up arrow key.", instructionsfont) { height = 75, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 335), } }; ControlsText[0][4] = new Text("Card to right pile - down arrow key.", instructionsfont) { height = 75, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 385), } }; ControlsText[0][5] = new Text("Top Player:", instructionsfont) { height = 100, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 485), } }; ControlsText[0][6] = new Text("Scroll through your cards - 'A' and 'D' keys", instructionsfont) { height = 75, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 545), } }; ControlsText[0][7] = new Text("Card to left pile - 'W' key.", instructionsfont) { height = 75, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 595), } }; ControlsText[0][8] = new Text("Card to right pile - 'S' key.", instructionsfont) { height = 75, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 645), } }; #endregion // makes instance of the control screen with its text Controls = new Instructions(background, ControlsText, font); Controls.setButton(delegate() { Controls.isPaused = true; InstructionsMenu.isPaused = false; }); #endregion #region Rules // makes all the drawable text to display when control screen is chosen from instructions menu Drawable[][] RulesText = new Drawable[1][]; #region FirstPage RulesText[0] = new Drawable[8]; RulesText[0][0] = new Text("Rules", instructionsfont) { height = 200, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 150), } }; RulesText[0][1] = new Text("Each player has 5 cards in their hand at a time.", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 250), } }; RulesText[0][2] = new Text("You can play a card if its value is one higher or lower", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 310), } }; RulesText[0][3] = new Text("than a card in one of the middle piles.", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 350), } }; RulesText[0][4] = new Text("Aces are both low and high, so they can be played", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 430), } }; RulesText[0][5] = new Text("on both a King and a Two.", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 470), } }; RulesText[0][6] = new Text("If neither player has any moves, two new middle cards", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 550), } }; RulesText[0][7] = new Text("will be drawn and gameplay will continue as before.", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 590), } }; #endregion // makes instance of rules text Rules = new Instructions(background, RulesText, font); Rules.setButton(delegate() { Rules.isPaused = true; InstructionsMenu.isPaused = false; }); #endregion #region Winning // makes all the drawable text to display when control screen is chosen from instructions menu Drawable[][] WinningText = new Drawable[1][]; #region FirstPage WinningText[0] = new Drawable[8]; WinningText[0][0] = new Text("Winning", instructionsfont) { height = 200, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 150), } }; WinningText[0][1] = new Text("In Normal Mode: The first person to play all", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 250), } }; WinningText[0][2] = new Text("of their cards or the player with the highest score when", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 290), } }; WinningText[0][3] = new Text("no more cards can be drawn wins the game.", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 330), } }; WinningText[0][4] = new Text("In Marathon Mode: The first player to play a chosen", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 410), } }; WinningText[0][5] = new Text("number of cards wins the game.", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 450), } }; WinningText[0][6] = new Text("In Timed Mode: The player who plays the most cards", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 530), } }; WinningText[0][7] = new Text("before time runs out wins the game.", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 570), } }; #endregion // makes instance of winning text Winning = new Instructions(background, WinningText, font); Winning.setButton(delegate() { Winning.isPaused = true; InstructionsMenu.isPaused = false; }); #endregion #region PowerUps // makes all the drawable text to display when control screen is chosen from instructions menu Drawable[][] PowerUpsText = new Drawable[1][]; #region FirstPage PowerUpsText[0] = new Drawable[8]; PowerUpsText[0][0] = new Text("PowerUps", instructionsfont) { height = 200, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 150), } }; PowerUpsText[0][1] = new Text("PowerUps appear on game piles randomly during gameplay.", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 250), } }; PowerUpsText[0][2] = new Text("If a card is played on a powerup, the powerup", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 290), } }; PowerUpsText[0][3] = new Text("will immediately take effect in favor of who played the card.", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 330), } }; PowerUpsText[0][4] = new Text("Freeze - Renders the opponent's selector immovable for around 2 seconds.", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 410), } }; PowerUpsText[0][5] = new Text(" ", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 450), } }; PowerUpsText[0][6] = new Text(" ", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 530), } }; PowerUpsText[0][7] = new Text(" ", instructionsfont) { height = 80, attributes = new Attributes() { color = Color.Black, depth = 0f, position = new Vector2(512, 570), } }; #endregion // makes instance of winning text PowerUps = new Instructions(background, PowerUpsText, font); // goes back to instructions menu if back is pressed from powerups instructions PowerUps.setButton(delegate() { PowerUps.isPaused = true; InstructionsMenu.isPaused = false; }); #endregion #region MarathonMenu Text ChooseLength = new Text("Set Win Score", font) { attributes = new Attributes() { color = Color.Black, //rotation = -.05f, depth = 0f, }, scale = new Vector2(.5f, .5f) }; String[] marathonMenuString = new String[4]; marathonMenuString[0] = "Half Marathon (30)"; marathonMenuString[1] = "Marathon (50)"; marathonMenuString[2] = "Ultra Marathon (100)"; marathonMenuString[3] = "Back"; Button.ClickHandler[] marathonMenuAction = new Button.ClickHandler[4]; marathonMenuAction[0] = delegate() { speed.winningscore = 30; speed.TurnOn(); MarathonMenu.isPaused = true; }; marathonMenuAction[1] = delegate() { speed.winningscore = 50; speed.TurnOn(); MarathonMenu.isPaused = true; }; marathonMenuAction[2] = delegate() { speed.winningscore = 100; speed.TurnOn(); MarathonMenu.isPaused = true; }; marathonMenuAction[3] = delegate() { MarathonMenu.isPaused = true; MainMenu.isPaused = false; }; MarathonMenu = new Menu(background, 4, ChooseLength, marathonMenuString, marathonMenuAction, font); #endregion #region TimedMenu Text ChooseTime = new Text("Set Time", font) { attributes = new Attributes() { color = Color.Black, //rotation = -.05f, depth = 0f, }, scale = new Vector2(.5f, .5f) }; String[] TimedMenuString = new String[5]; TimedMenuString[0] = "30 seconds"; TimedMenuString[1] = "1 minute"; TimedMenuString[2] = "2 minutes"; TimedMenuString[3] = "5 minutes"; TimedMenuString[4] = "Back"; Button.ClickHandler[] TimedMenuAction = new Button.ClickHandler[5]; TimedMenuAction[0] = delegate() { speed.gameLength = 30; speed.TurnOn(); TimedMenu.isPaused = true; }; TimedMenuAction[1] = delegate() { speed.gameLength = 60; speed.TurnOn(); TimedMenu.isPaused = true; }; TimedMenuAction[2] = delegate() { speed.gameLength = 120; speed.TurnOn(); TimedMenu.isPaused = true; }; TimedMenuAction[3] = delegate() { speed.gameLength = 300; speed.TurnOn(); TimedMenu.isPaused = true; }; TimedMenuAction[4] = delegate() { TimedMenu.isPaused = true; MainMenu.isPaused = false; }; TimedMenu = new Menu(background, 5, ChooseTime, TimedMenuString, TimedMenuAction, font); #endregion // makes the freeze icon freeze = new PowerUp(Color.LightBlue, textures, powerUpsOn) { attributes = new Attributes() { texture = this.Content.Load<Texture2D>("Freeze"), position = new Vector2(300, 300), color = Color.White } }; freeze.isSeeable = false; test = new ParticleEngine(textures, new Vector2(512, 400), new Vector2(1000,1000), .99f, Color.Blue); test2 = new ParticleEngine(textures, new Vector2(256, 400), new Vector2(1000, 1000), .99f, Color.Red); test3 = new ParticleEngine(textures, new Vector2(768, 400), new Vector2(1000, 1000), .99f, Color.White); for (int i = 0; i < cards.Length; i++) { cards[i].textures = textures; } }
// public void Begin() { base.RemoveLast(); if (myType == gameType.Timed) { //base.Add(time1); base.Add(time2); } if (myType == gameType.Levels) { levelss = new Text("Level " + level, _font) { height = 100, attributes = new Attributes() { color = Color.Black, position = new Vector2(rSpitStack.position.X + 50, yourName.attributes.position.Y), depth = .01f }, scale = new Vector2(.15f, .15f), }; base.Add(levelss); } base.Add(yourName); base.Add(oppName); base.Add(yourScore); base.Add(oppScore); speedState = gameState.Beginning; for (int i = 0; i < 5; i++) { DrawCard(yourStack, yourCards[i], i * .675f); DrawCard(opponentStack, opponentCards[i], i * .675f); } Timer stopwatch = new Timer(3); base.Add(stopwatch); Text three = new Text("3", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(three); three.Fade(1); stopwatch.SetTimer(0, 1, delegate() { Text two = new Text("2", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(two); two.Fade(1); }); stopwatch.SetTimer(1, 2, delegate() { Text one = new Text("1", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(one); one.Fade(1); }); stopwatch.SetTimer(2, 3, delegate() { Text title = new Text("SPEED!", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(title); title.Fade(.5f); title.WhenDoneFading(new Tweener.EndHandler(BeginGame)); if(myType == gameType.Timed) title.WhenDoneFading(delegate() { base.Add(gameTimer); }); }); }
// computer logic to know when to play cards public void Move(Pile[] Hand, Pile rgamestack, Pile lgamestack) { if (myState == CompState.moving) { return; } if (ExistAMove2(Hand, rgamestack, lgamestack)) { myState = CompState.moving; // moves left if that is fastest way to closest playable card if (pileNumber != selector) { int x = pileNumber - selector; if (x >= 3 || (x < 0 && x >= -2)) { moveDelay = new Timer(1); moveDelay.SetTimer(0, timeDelay + ((float)random.NextDouble() - .5f) * timeDelay, delegate() { if (!isPlayer1) { MoveSelectorLeft(); } else { MoveSelectorRight(); } myState = CompState.normal; }); } // moves right if otherwise else if (x <= -3 || (x > 0 && x < 3)) { moveDelay = new Timer(1); moveDelay.SetTimer(0, timeDelay + ((float)random.NextDouble() - .5f) * timeDelay, delegate() { if (!isPlayer1) { MoveSelectorRight(); } else { MoveSelectorLeft(); } myState = CompState.normal; }); } } // stays on same pile & plays it if closest card is there else if (pileNumber == selector) { moveDelay = new Timer(1); moveDelay.SetTimer(0, timeDelay + ((float)random.NextDouble() - .5f) * timeDelay, delegate() { SelectCard(isLeftPile); myState = CompState.normal; }); } } else if (Hand[selector].Count() == 0) { myState = CompState.moving; moveDelay = new Timer(1); moveDelay.SetTimer(0, timeDelay + ((float)random.NextDouble() - .5f) * timeDelay, delegate() { if (!isPlayer1) { MoveSelectorRight(); } else { MoveSelectorLeft(); } myState = CompState.normal; }); } }
// draws card to different piles public void DrawCard(Pile drawPile, Pile destinationPile, float delay) { if (destinationPile.drawnTo) return; ableToReBegin = false; destinationPile.drawnTo = true; Card temp = null; switch (myType) { case gameType.Levels: case gameType.Normal: temp = drawPile.Take(); break; case gameType.Marathon: case gameType.Timed: temp = getRandomCard(drawPile); base.Add(temp); break; } temp.Flip(true, delay); temp.toPile(destinationPile, delay); if (destinationPile.hasPowerUp) destinationPile.RemovePowerUp(); temp.WhenDoneMoving(delegate() { destinationPile.drawnTo = false; Timer drawTimer = new Timer(1); base.Add(drawTimer); drawTimer.SetTimer(0, .5f, delegate() { ableToReBegin = true; }); if ((destinationPile == lGameStack || destinationPile == rGameStack) && !destinationPile.hasPowerUp) SelectPowerUp(destinationPile); }); }
// overloaded constructor to add buttonheight public Menu(Drawable background, int numberOfButtons, Text title, String[] buttonNames, Button.ClickHandler[] buttonActions, SpriteFont buttonFont, int buttonHeight, bool PAMenuButtonHeight) : base(background) { this.buttonHeight = buttonHeight; buttons = new Button[numberOfButtons]; base.Add(title); title.attributes.position = new Vector2(512, title.height / 2 + 40); title.attributes.depth = .01f; maxButtonWidth = 0; for (int i = 0; i < numberOfButtons; i++) { buttons[i] = new Button(buttonNames[i], buttonFont, new Vector2(512, 550 + (125 * i)), Color.Black); buttons[i].height = 100; buttons[i].Clicked += buttonActions[i]; buttons[i].Clicked += delegate() { for (int j = 0; j < numberOfButtons; j++) { if (j != i) buttons[j].Remove(); } }; if (buttons[i].width > maxButtonWidth) maxButtonWidth = buttons[i].width; base.Add(buttons[i]); buttons[i].attributes.depth = .01f; } selected = 0; myState = menuState.Off; keysOff = false; Timer state = new Timer(1); base.Add(state); state.SetTimer(0, .5f, delegate() { myState = menuState.On; }); }
// initializes lots of variables public Speed(Card[] deckOfCards, Drawable background, Texture2D selector, SpriteFont font, Player bottom, Player top, List<Texture2D> particles, gameType gameType, SoundEffect shuffling, SoundEffect playingcard, SoundEffectInstance shuffinstance, bool isSoundOn, bool isPowerUpOn, bool isVibrateOn, PowerUp powerup) : base(background) { myType = gameType; cardcounter = new int[52]; random = new Random(); _font = font; shuffle = shuffling; playcard = playingcard; shuffleinstance = shuffinstance; isHalted = false; isShaking = false; textures = particles; soundOn = isSoundOn; powerUpOn = isPowerUpOn; vibrateOn = isVibrateOn; ableToReBegin = true; ableToReBegin2 = true; freeze = powerup; freeze.isSeeable = false; base.Add(freeze); freeze.WhenPlayed(delegate(Player player) { player.Freeze(); Timer timer = new Timer(1); base.Add(timer); timer.SetTimer(0, 4, delegate() { player.UnFreeze(); }); freeze.Fade(4); if (player.isPlayer1) freeze.Move(Actions.ExpoMove, yourSelector.attributes.position, 1); else freeze.Move(Actions.ExpoMove, oppSelector.attributes.position, 1); }); you = bottom; opp = top; you.SelectedCardLeft += delegate(){ PlayCard(you, you.selector, lGameStack);}; you.SelectedCardRight += delegate() { PlayCard(you, you.selector, rGameStack); }; opp.SelectedCardLeft += delegate() { PlayCard(opp, opp.selector, lGameStack); }; opp.SelectedCardRight += delegate() { PlayCard(opp, opp.selector, rGameStack); }; you.score = 0; opp.score = 0; deck = new Card[deckOfCards.Length]; cards = new Card[deckOfCards.Length]; for (int i = 0; i < deckOfCards.Length; i++) { deck[i] = deckOfCards[i]; cards[i] = deckOfCards[i]; } for (int i = 0; i < cards.Length; i++) { cards[i].attributes.position = new Vector2(-100, 100); cards[i].isFaceUp = false; cards[i].isSeeable = true; cards[i].attributes.color = Color.White; cards[i].attributes.rotation = 0; cards[i].ClearTweeners(); cards[i].attributes.height = 180; cards[i].attributes.width = 130; deck[i].attributes.position = new Vector2(-100, 100); deck[i].isFaceUp = false; deck[i].isSeeable = true; deck[i].attributes.color = Color.White; deck[i].attributes.rotation = 0; deck[i].ClearTweeners(); deck[i].attributes.height = 180; deck[i].attributes.width = 130; } yourStack = new Pile(new Vector2(897, 675)); opponentStack = new Pile(new Vector2(127, 125)); lSpitStack = new Pile(new Vector2(217, 400)); rSpitStack = new Pile(new Vector2(807, 400)); lGameStack = new Pile(new Vector2(413, 400)); rGameStack = new Pile(new Vector2(610, 400)); yourCards = new Pile[5]; opponentCards = new Pile[5]; for (int i = 0; i < yourCards.Length; i++) { opponentCards[i] = new Pile(new Vector2(opponentStack.position.X + (i + 1) * 154, opponentStack.position.Y)); yourCards[i] = new Pile(new Vector2(yourStack.position.X - (i + 1) * 154, yourStack.position.Y)); } yourName = new Text(you.playerName + " - ", _font); yourName.height = 100; yourName.attributes.position = new Vector2((yourCards[3].position.X + yourCards[4].position.X)/2 - 20, (yourCards[3].position.Y + lGameStack.position.Y) / 2); yourName.isSeeable = true; yourName.attributes.color = Color.LightSkyBlue; yourName.attributes.depth = .02f; yourName.scale = new Vector2(.15f, .15f); oppName = new Text(" - " + opp.playerName, _font); oppName.height = 100; oppName.attributes.position = new Vector2((opponentCards[3].position.X + opponentCards[4].position.X)/2 + 20, (opponentCards[3].position.Y + lGameStack.position.Y) / 2); oppName.isSeeable = true; oppName.attributes.color = Color.Red; oppName.attributes.depth = .02f; oppName.scale = new Vector2(.15f, .15f); yourScore = new Text(you.score.ToString(), _font); yourScore.height = 100; yourScore.attributes.position = new Vector2(yourName.attributes.position.X + yourName.width/2 + 10, yourName.attributes.position.Y); yourScore.isSeeable = true; yourScore.attributes.color = Color.LightSkyBlue; yourScore.attributes.depth = .02f; yourScore.scale = new Vector2(.15f, .15f); oppScore = new Text(opp.score.ToString(), _font); oppScore.height = 100; oppScore.attributes.position = new Vector2(oppName.attributes.position.X - oppName.width/2 - 10, oppName.attributes.position.Y); oppScore.isSeeable = true; oppScore.attributes.color = Color.Red; oppScore.attributes.depth = .02f; oppScore.scale = new Vector2(.15f, .15f); for (int i = 0; i < cards.Length; i++) { base.Add(cards[i]); } oppSelector = new Drawable() { attributes = new Attributes() { texture = selector, position = new Vector2(-100, -100), color = Color.Red, height = 190, width = 140, depth = .11f, rotation = 0 } }; yourSelector = new Drawable() { attributes = new Attributes() { texture = selector, position = new Vector2(-100, -100), color = Color.LightSkyBlue, height = 190, width = 140, depth = .11f, rotation = 0 } }; base.Add(oppSelector); base.Add(yourSelector); if (myType == gameType.Marathon) { winningscore = 30; } //if (myType == gameType.Timed) //{ gameLength = 120; delayTimer = new Timer(1); delayTimer.SetTimer(0, 4, delegate() { if (speedState == gameState.GamePlay && lSpitStack.Count() != 0) { speedState = gameState.ReBeginning; Text delay = new Text("Delay", font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400), depth = .001f, }, height = 400, }; base.Add(delay); delay.Fade(2); delay.WhenDoneFading(delegate() { BeginGame(); }); } }); //} }
// start game method public void StartGame() { // resets players, initializes to level 1, sets levelstate to playing _player1.Reset(); computer.Reset(); if (myState == LevelState.Starting) _level = 1; myState = LevelState.Playing; // switches computers timedelay based on difficulty of game switch (myDiff) { case Difficulty.Baby: ComputerPlayer.timeDelay = 2 - (.1f * _level); if (ComputerPlayer.timeDelay <= 0) Winner(); break; case Difficulty.Easy: ComputerPlayer.timeDelay = 1.2f - (.06f * _level); if (ComputerPlayer.timeDelay <= 0) Winner(); break; case Difficulty.Medium: ComputerPlayer.timeDelay = .6f - (.03f * _level); if (ComputerPlayer.timeDelay <= 0) Winner(); break; case Difficulty.Hard: ComputerPlayer.timeDelay = .44f - (.022f * _level); if (ComputerPlayer.timeDelay <= 0) Winner(); break; } // makes new instance of speed between computer and player speed = new Speed(deck, _background, _selector, _font, _player1, computer, _particles, Speed.gameType.Levels, shuffling, playingCard, shuffleInstance, isSoundOn, isPowerUpOn, isVibrateOn, freeze); // sets level to level, turns speed on, makes player's state the playing state speed.level = _level; speed.TurnOn(); myState = LevelState.Playing; // if player wins game, halts speed, increases level, and starts new game speed.YouWon += delegate() { speed.isHalted = true; timer = new Timer(1); timer.SetTimer(0, 2, delegate() { _level++; StartGame(); }); }; // if player loses game, calls loser method, which prompts player to start new game or exit speed.YouLost += delegate() { speed.isHalted = true; timer = new Timer(1); timer.SetTimer(0, 2, delegate() { Loser(); }); }; // if player ties computer, restarts game on the same level speed.YouTie += delegate() { speed.isHalted = true; timer = new Timer(1); timer.SetTimer(0, 2, delegate() { StartGame(); }); }; }
// 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(); } }
// if game ends in a tie, displays certain text & fades some drawables& adds endgame actions public void Tie() { speedState = gameState.Winner; Text tieTop = new Text("It's a tie!", _font) { attributes = new Attributes() { position = new Vector2(512, 200), color = Color.RoyalBlue, //rotation = -.2f, depth = .1f }, scale = new Vector2(.8f, .8f) }; Text tieMiddle = new Text("You're both", _font) { attributes = new Attributes() { position = new Vector2(512, 400), color = Color.Red, //rotation = -.2f, depth = .1f }, scale = new Vector2(.7f, .7f) }; Text tieBottom = new Text("SCRUBS!!!", _font) { attributes = new Attributes() { position = new Vector2(512, 600), color = Color.Red, //rotation = -.2f, depth = .1f }, scale = new Vector2(.7f, .7f) }; yourSelector.Fade(2); yourSelector.Move(Actions.ExpoMove, new Vector2(512, 400), 2); yourSelector.Scale(Actions.LinearMove, yourSelector.attributes.scale * 2, 2); oppSelector.Fade(2); oppSelector.Move(Actions.ExpoMove, new Vector2(512, 400), 2); oppSelector.WhenDoneMoving(delegate() { base.Add(tieTop); if (myType == gameType.Levels) { YouTie(); } base.Add(tieMiddle); base.Add(tieBottom); }); oppSelector.Scale(Actions.LinearMove, yourSelector.attributes.scale * 2, 2); Timer endGame = new Timer(2); base.Add(endGame); endGame.SetTimer(0, 6, delegate() { yourScore.attributes.color = Color.LightSkyBlue; yourScore.isSeeable = true; yourScore.attributes.position = new Vector2(400, 675); yourScore.height = 150; oppScore.attributes.color = Color.Red; oppScore.isSeeable = true; oppScore.attributes.position = new Vector2(624, 675); oppScore.height = 150; Text dash = new Text(" - ", _font); dash.attributes = new Attributes() { color = Color.Black, position = new Vector2(512, 675) }; dash.isSeeable = true; dash.height = 150; base.Add(dash); Reset(); }); endGame.SetTimer(1, 4, delegate() { tieTop.Fade(2); tieMiddle.Fade(2); tieBottom.Fade(2); }); }
// adds cards to game stacks if no cards are playable public void ReBegin() { if (!ableToReBegin || !ableToReBegin2) return; if (speedState == gameState.Winner) return; if (speedState == gameState.PlayAgain) return; ableToReBegin = false; speedState = gameState.ReBeginning; Timer watch = new Timer(1); base.Add(watch); watch.SetTimer(0, 1, delegate() { Text nomove = new Text("No Moves", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) }, scale = new Vector2(.5f, .5f) }; base.Add(nomove); nomove.Move(Actions.LinearMove, nomove.attributes.position, 1); nomove.WhenDoneMoving(delegate() { nomove.isSeeable = false; }); }); if (lSpitStack.Count() != 0) { Timer stopwatch = new Timer(5); base.Add(stopwatch); stopwatch.SetTimer(0, 3, delegate() { Text two = new Text("2", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(two); two.Fade(1); }); stopwatch.SetTimer(1, 4, delegate() { Text one = new Text("1", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(one); one.Fade(1); }); stopwatch.SetTimer(2, 5, delegate() { Text title = new Text("SPEED!", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(title); title.Fade(.5f); title.WhenDoneFading(new Tweener.EndHandler(BeginGame)); }); stopwatch.SetTimer(3, 2, delegate() { Text three = new Text("3", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(three); three.Fade(1); }); } else Winner(DetermineWinner()); }
// public void Begin() { base.RemoveLast(); if (myType == gameType.Timed) { //base.Add(time1); base.Add(time2); } if (myType == gameType.Levels) { levelss = new Text("Level " + level, _font) { height = 100, attributes = new Attributes() { color = Color.Black, position = new Vector2(rSpitStack.position.X + 50, yourName.attributes.position.Y), depth = .01f }, scale = new Vector2(.15f, .15f), }; base.Add(levelss); } base.Add(yourName); base.Add(oppName); base.Add(yourScore); base.Add(oppScore); speedState = gameState.Beginning; for (int i = 0; i < 5; i++) { DrawCard(yourStack, yourCards[i], i * .675f); DrawCard(opponentStack, opponentCards[i], i * .675f); } Timer stopwatch = new Timer(3); base.Add(stopwatch); Text three = new Text("3", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(three); three.Fade(1); stopwatch.SetTimer(0, 1, delegate() { Text two = new Text("2", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(two); two.Fade(1); }); stopwatch.SetTimer(1, 2, delegate() { Text one = new Text("1", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(one); one.Fade(1); }); stopwatch.SetTimer(2, 3, delegate() { Text title = new Text("SPEED!", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(title); title.Fade(.5f); title.WhenDoneFading(new Tweener.EndHandler(BeginGame)); if (myType == gameType.Timed) { title.WhenDoneFading(delegate() { base.Add(gameTimer); }); } }); }
// if game ends in a tie, displays certain text & fades some drawables& adds endgame actions public void Tie() { speedState = gameState.Winner; Text tieTop = new Text("It's a tie!", _font) { attributes = new Attributes() { position = new Vector2(512, 200), color = Color.RoyalBlue, //rotation = -.2f, depth = .1f }, scale = new Vector2(.8f,.8f) }; Text tieMiddle = new Text("You're both", _font) { attributes = new Attributes() { position = new Vector2(512, 400), color = Color.Red, //rotation = -.2f, depth = .1f }, scale = new Vector2(.7f,.7f) }; Text tieBottom = new Text("SCRUBS!!!", _font) { attributes = new Attributes() { position = new Vector2(512, 600), color = Color.Red, //rotation = -.2f, depth = .1f }, scale = new Vector2(.7f,.7f) }; yourSelector.Fade(2); yourSelector.Move(Actions.ExpoMove, new Vector2(512, 400), 2); yourSelector.Scale(Actions.LinearMove, yourSelector.attributes.scale * 2, 2); oppSelector.Fade(2); oppSelector.Move(Actions.ExpoMove, new Vector2(512, 400), 2); oppSelector.WhenDoneMoving( delegate() { base.Add(tieTop); if (myType == gameType.Levels) YouTie(); base.Add(tieMiddle); base.Add(tieBottom); }); oppSelector.Scale(Actions.LinearMove, yourSelector.attributes.scale * 2, 2); Timer endGame = new Timer(2); base.Add(endGame); endGame.SetTimer(0, 6, delegate() { yourScore.attributes.color = Color.LightSkyBlue; yourScore.isSeeable = true; yourScore.attributes.position = new Vector2(400, 675); yourScore.height = 150; oppScore.attributes.color = Color.Red; oppScore.isSeeable = true; oppScore.attributes.position = new Vector2(624, 675); oppScore.height = 150; Text dash = new Text(" - ", _font); dash.attributes = new Attributes() { color = Color.Black, position = new Vector2(512, 675) }; dash.isSeeable = true; dash.height = 150; base.Add(dash); Reset();}); endGame.SetTimer(1, 4, delegate() { tieTop.Fade(2); tieMiddle.Fade(2); tieBottom.Fade(2); }); }
// turns game on public override void TurnOn() { if (myType == gameType.Timed) { gameTimer = new Timer(1); gameTimer.SetTimer(0, gameLength, delegate() { Winner(DetermineWinner()); ableToReBegin = false; ableToReBegin2 = false; /*time1.Fade(4);*/ time2.Fade(4); speedState = gameState.Winner; }); /*time1 = new Text(gameTimer.getCountDown(0), _font); time1.height = 100; time1.attributes.position = new Vector2(yourName.attributes.position.X, oppName.attributes.position.Y); time1.isSeeable = true; time1.attributes.color = Color.Black; time1.attributes.depth = .02f; time1.scale = new Vector2(.15f, .15f);*/ time2 = new Text(gameTimer.getCountDown(0), _font); time2.height = 100; time2.attributes.position = new Vector2(oppName.attributes.position.X, yourName.attributes.position.Y); time2.isSeeable = true; time2.attributes.color = Color.Black; time2.attributes.depth = .02f; time2.scale = new Vector2(.12f, .12f); } Deal(); base.TurnOn(); }
// 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(); } }
// if bottom player wins, displays certain text & fades some drawables& adds endgame actions public void YourAWinner() { speedState = gameState.Winner; Text winner = new Text("Winner!!!", _font) { attributes = new Attributes() { color = Color.LightSkyBlue, position = new Vector2(512, 650), //rotation = -.2f, depth = .1f, }, scale = new Vector2(.8f,.8f) }; Text loser = new Text("Scrub!!!", _font) { attributes = new Attributes() { color = Color.DarkRed, position = new Vector2(512, 180), //rotation = -.2f, depth = .1f }, scale = new Vector2(.8f,.8f) }; oppSelector.Fade(2); yourSelector.Move(Actions.ExpoMove, new Vector2(512, 400), 2); yourSelector.Fade(2); yourSelector.WhenDoneMoving( delegate() { base.Add(winner); base.Add(loser); }); yourSelector.Scale(Actions.LinearMove, yourSelector.attributes.scale * 2, 2); Timer endGame = new Timer(2); base.Add(endGame); endGame.SetTimer(0, 6, delegate() { yourScore.attributes.color = Color.LightSkyBlue; yourScore.isSeeable = true; yourScore.attributes.position = new Vector2(400, 675); yourScore.height = 150; oppScore.attributes.color = Color.Red; oppScore.isSeeable = true; oppScore.attributes.position = new Vector2(624, 675); oppScore.height = 150; Text dash = new Text(" - ", _font); dash.attributes = new Attributes() { color = Color.Black, position = new Vector2(512, 675) }; dash.isSeeable = true; dash.height = 150; base.Add(dash); if (myType == gameType.Levels) YouWon(); else Reset(); }); endGame.SetTimer(1, 4, delegate() { winner.Fade(2); loser.Fade(2); }); }
// adds cards to game stacks if no cards are playable public void ReBegin() { if (!ableToReBegin || !ableToReBegin2) { return; } if (speedState == gameState.Winner) { return; } if (speedState == gameState.PlayAgain) { return; } ableToReBegin = false; speedState = gameState.ReBeginning; Timer watch = new Timer(1); base.Add(watch); watch.SetTimer(0, 1, delegate() { Text nomove = new Text("No Moves", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) }, scale = new Vector2(.5f, .5f) }; base.Add(nomove); nomove.Move(Actions.LinearMove, nomove.attributes.position, 1); nomove.WhenDoneMoving(delegate() { nomove.isSeeable = false; }); }); if (lSpitStack.Count() != 0) { Timer stopwatch = new Timer(5); base.Add(stopwatch); stopwatch.SetTimer(0, 3, delegate() { Text two = new Text("2", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(two); two.Fade(1); }); stopwatch.SetTimer(1, 4, delegate() { Text one = new Text("1", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(one); one.Fade(1); }); stopwatch.SetTimer(2, 5, delegate() { Text title = new Text("SPEED!", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(title); title.Fade(.5f); title.WhenDoneFading(new Tweener.EndHandler(BeginGame)); }); stopwatch.SetTimer(3, 2, delegate() { Text three = new Text("3", _font) { attributes = new Attributes() { color = Color.Yellow, position = new Vector2(512, 400) } }; base.Add(three); three.Fade(1); }); } else { Winner(DetermineWinner()); } }
// start game method public void StartGame() { // resets players, initializes to level 1, sets levelstate to playing _player1.Reset(); computer.Reset(); if (myState == LevelState.Starting) { _level = 1; } myState = LevelState.Playing; // switches computers timedelay based on difficulty of game switch (myDiff) { case Difficulty.Baby: ComputerPlayer.timeDelay = 2 - (.1f * _level); if (ComputerPlayer.timeDelay <= 0) { Winner(); } break; case Difficulty.Easy: ComputerPlayer.timeDelay = 1.2f - (.06f * _level); if (ComputerPlayer.timeDelay <= 0) { Winner(); } break; case Difficulty.Medium: ComputerPlayer.timeDelay = .6f - (.03f * _level); if (ComputerPlayer.timeDelay <= 0) { Winner(); } break; case Difficulty.Hard: ComputerPlayer.timeDelay = .44f - (.022f * _level); if (ComputerPlayer.timeDelay <= 0) { Winner(); } break; } // makes new instance of speed between computer and player speed = new Speed(deck, _background, _selector, _font, _player1, computer, _particles, Speed.gameType.Levels, shuffling, playingCard, shuffleInstance, isSoundOn, isPowerUpOn, isVibrateOn, freeze); // sets level to level, turns speed on, makes player's state the playing state speed.level = _level; speed.TurnOn(); myState = LevelState.Playing; // if player wins game, halts speed, increases level, and starts new game speed.YouWon += delegate() { speed.isHalted = true; timer = new Timer(1); timer.SetTimer(0, 2, delegate() { _level++; StartGame(); }); }; // if player loses game, calls loser method, which prompts player to start new game or exit speed.YouLost += delegate() { speed.isHalted = true; timer = new Timer(1); timer.SetTimer(0, 2, delegate() { Loser(); }); }; // if player ties computer, restarts game on the same level speed.YouTie += delegate() { speed.isHalted = true; timer = new Timer(1); timer.SetTimer(0, 2, delegate() { StartGame(); }); }; }