コード例 #1
0
 private void reset()
 {
     _computerColor = null;
     foreach (colorObject c in _playerColors)
         c.Chosen = false;
     msg = "choose a color by clicking on the color of your choice";
     gameOver = false;
 }
コード例 #2
0
        /// <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.
            IsMouseVisible = true;
            spriteBatch = new SpriteBatch(GraphicsDevice);
            messages = Content.Load<SpriteFont>("message");
            _playerColors = new colorObject[_colorchoices.Length];
            Vector2 startPosition = new Vector2(100,100);
            Texture2D tx = Content.Load<Texture2D>("colorTexture");
            Random r = new Random();

            for (int i = 0; i < _playerColors.Length; i++)
            {
                _playerColors[i] =
                    new colorObject(messages,startPosition,
                        tx, _colorchoices[i],r.Next(1,10));
                startPosition += new Vector2(tx.Width + 10, 0);
            }
            _playerColors[_currentChoice].Selected = true;
            // TODO: use this.Content to load your game content here
            Texture2D cursorTx = Content.Load<Texture2D>("arrow");

            // Set up the arrow and point it at the first choice

            _cursor = new Cursor(cursorTx, _playerColors[_currentChoice].CenterPos
                - new Vector2(0,cursorTx.Height));

            reset();
        }
コード例 #3
0
 private void checkChosen()
 {
     // object to grab chosen object
     colorObject chosen = null;
     foreach (colorObject c in _playerColors)
         if (c.Chosen)
         {
             chosen = c;
             break;
         }
     if (chosen != null)
     {
         Random r = new Random();
         _computerColor = new colorObject(messages,new Vector2(200, 200),
             Content.Load<Texture2D>("colorTexture"),
             _colorchoices[r.Next(0, _colorchoices.Length)],0);
         if (_computerColor.MyColor == chosen.MyColor)
             msg = "You chose right you win ";
         else msg = "You chose wrong you loose ";
         msg += " Press Esc to quit. Press P to play again ";
         gameOver = true;
     }
 }