private void checkChosen() { ColourObjectComponent chosen = null; foreach (ColourObjectComponent c in playerColours) { if (c.Chosen) { chosen = c; break; } } if (chosen != null) { Random rand = new Random(); computerColour = new ColourObjectComponent(this, new Vector2(200, 200), Content.Load <Texture2D>(@"colourTx"), choices[rand.Next(0, choices.Length)]); if (computerColour.MyColour == chosen.MyColour) { msg = "You chose right, you win."; } else { msg = "You chose wrong, you lose."; } msg += "\nPress ESC to quit, P to play again."; gameOver = true; } }
private void Reset() { Components.Remove(computerColour); computerColour = null; foreach (ColourObjectComponent c in playerColours) { c.Chosen = false; } msg = "Choose a colour by clicking on a colour of your choice"; gameOver = false; }
private void setupPlayerChoices() { playerColours = new ColourObjectComponent[3]; int gap = 10; Texture2D tx = Content.Load <Texture2D>(@"colourTx"); font = Content.Load <SpriteFont>(@"msgFont"); Vector2 startPos = GraphicsDevice.Viewport.Bounds.Center.ToVector2() - new Vector2(playerColours.Length * (tx.Width + gap) / 2, tx.Height / 2); for (int i = 0; i < playerColours.Length; i++) { playerColours[i] = new ColourObjectComponent(this, startPos, tx, choices[i]); startPos += new Vector2(tx.Width + gap, 0); } }