Example #1
0
        private void DrawCard()
        {
            if (Card.Text != "")
            {
                // they've clicked to draw a card!
                // figure out who the player is
                IPlayer thisPlayer = Players[_whoseTurn];

                // should it be a toy card or a color card?
                int colorOrToy = rnd.Next(0, 10);
                if (colorOrToy == 0) //  should be (colorOrToy == 0)
                {
                    // toy card!
                    Bitmap[] toys = { Properties.Resources.basketball, Properties.Resources.car,       Properties.Resources.keyboard,
                                      Properties.Resources.dinosaur,   Properties.Resources.teddybear, Properties.Resources.tricycle,
                                      Properties.Resources.blocks };
                    string[] imageNames = { "basketball", "car", "keyboard", "dinosaur", "teddybear", "tricycle", "blocks" };

                    // there are 7 toys on the board?
                    int    imgNum      = rnd.Next(0, 7); // to do: should be 0, 7
                    Bitmap chosenImage = toys[imgNum];
                    // make sure this card is still available to be drawn, because toys can only be drawns once eacyh per game

                    /* to do: uncomment this?
                     * if (toysAlreadyDrawn.Contains(imageNames[imgNum]))
                     * {
                     *  // draw a different card
                     *  this.Card_Click(sender, e);
                     *  return;
                     * }*/

                    toysAlreadyDrawn.Add(imageNames[imgNum]);
                    ToyCard drawnCard = new ToyCard(chosenImage, imageNames[imgNum]);
                    synth.SpeakAsync("Go to the " + imageNames[imgNum]);
                    CardColor3.BackgroundImage = drawnCard.Image;
                    CardColor3.BackColor       = Color.Empty;
                    CardColor3.Visible         = true;

                    // the player needs to know where the target is on the trail
                    thisPlayer.DetermineNextPosition(drawnCard, this.Players);
                    this.debug.Text = "next: " + thisPlayer.NextPosition.ToString();
                }
                else
                {
                    // color card!
                    ColorCard drawnCard = new ColorCard(rnd);
                    if (drawnCard.NumSquares == 1)
                    {
                        CardColor3.BackColor = drawnCard.Color;
                        CardColor3.Visible   = true;
                        synth.SpeakAsync("Move one " + this.ColorNameOnly(drawnCard.Color) + " square");
                    }
                    else
                    {
                        CardColor1.BackColor = drawnCard.Color;
                        CardColor2.BackColor = drawnCard.Color;
                        CardColor1.Visible   = true;
                        CardColor2.Visible   = true;
                        synth.SpeakAsync("Move two " + this.ColorNameOnly(drawnCard.Color) + " squares");
                    }
                    // the player needs to know where the target is on the trail
                    thisPlayer.DetermineNextPosition(drawnCard, this.Players);
                    //this.debug.Text = thisPlayer.NextPosition.ToString();
                }
                Card.Text         = "";
                Card.Visible      = false;
                this.cardWasDrawn = true;
            }
        }
Example #2
0
        public void DetermineNextPosition(ColorCard Card, List <IPlayer> Players)
        {
            // DetermineNextPosition determines where the player is supposed to move to.
            // Each color is made up of 4 squares. There are 6 colors, and one 4-square toy, then repeat.
            // That's why it's mod 28.
            int modPosition;

            if (this.Position == null)
            {
                modPosition = -1;
            }
            else
            {
                modPosition = Position % 28 ?? 0;
            }
            int destination = 0; // Red

            if (Card.Color == Color.Orange)
            {
                destination = 4;
            }
            else if (Card.Color == Color.Yellow)
            {
                destination = 8;
            }
            else if (Card.Color == Color.Green)
            {
                destination = 12;
            }
            else if (Card.Color == Color.Blue)
            {
                destination = 16;
            }
            else if (Card.Color == Color.Purple)
            {
                destination = 20;
            }

            if (destination <= modPosition)
            {
                destination += 28;
            }

            int displacement = destination - modPosition;

            // if they're moving two squares of that color, add 28
            if (Card.NumSquares == 2)
            {
                displacement += 28;
            }
            this._nextPosition = (Position ?? -1) + displacement + _offset;
            // square 200 is the winner square, don't let them go past it
            if (this._nextPosition > 200)
            {
                this._nextPosition = 200;
            }

            /*
             * // make sure the position isn't already occupied
             * foreach (IPlayer p in Players)
             * {
             *  if (p.Position == this._nextPosition)
             *  {
             *      this._offset += 1;
             *      this._nextPosition += 1;
             *  }
             * }
             */
        }