Exemplo n.º 1
0
        /*
         * //initialize a random color
         * private void PickBrush()
         * {
         *
         *  Random rnd = new Random();
         *
         *  Type brushesType = typeof(Brushes);
         *
         *  PropertyInfo[] properties = brushesType.GetProperties();
         *  while (color == Brushes.White)
         *  {
         *      int random = rnd.Next(properties.Length);
         *      color = (Brush)properties[random].GetValue(null, null);
         *  }
         * }
         */
        //add a CarBody to the end of the player
        public void AddEnd()
        {
            if (Body.Count > 0)
            {
                CarBody lastBlock = Body[Body.Count - 1];
                int     x         = 0;
                int     y         = 0;
                int     step      = CarBody.Size * 2;
                switch (Direction)
                {
                case Directions.Left:
                    x = lastBlock.Location.X + step;
                    y = lastBlock.Location.Y;
                    break;

                case Directions.Right:
                    x = lastBlock.Location.X - step;
                    y = lastBlock.Location.Y;
                    break;

                case Directions.Up:
                    x = lastBlock.Location.X;
                    y = lastBlock.Location.Y + step;
                    break;

                case Directions.Down:
                    x = lastBlock.Location.X;
                    y = lastBlock.Location.Y - step;
                    break;

                default:
                    break;
                }
                Body.Add(new CarBody(lastBlock.Location.X, lastBlock.Location.Y, COLOR));
            }
            else
            {
                if (Direction == Directions.Left)
                {
                    Body.Add(new CarBody(500, 350, COLOR));
                }
                else if (Direction == Directions.Up)
                {
                    Body.Add(new CarBody(600, 300, COLOR));
                }
                else if (Direction == Directions.Right)
                {
                    Body.Add(new CarBody(700, 350, COLOR));
                }
                else if (Direction == Directions.Down)
                {
                    Body.Add(new CarBody(600, 400, COLOR));
                }
            }
        }
Exemplo n.º 2
0
        public void crashBoundary()
        {
            CarBody head = Body[0];
            int     step = CarBody.Size;

            if ((head.Location.X <= 0) || (head.Location.X >= (1200)))
            {
                Dead = true;
            }
            if ((head.Location.Y <= 0) || (head.Location.Y >= (700)))
            {
                Dead = true;
            }
        }
Exemplo n.º 3
0
        public void HitSelf()
        {
            CarBody head  = Body[0];
            bool    crash = false;

            for (int i = 1; i < Body.Count; i++)
            {
                crash = head.recBody.IntersectsWith(Body[i].recBody);
                if (crash)
                {
                    Dead = true;
                }
            }
        }
Exemplo n.º 4
0
        public void UpdateCar(Directions newDirection)
        {
            direction = newDirection;

            for (int i = Body.Count - 1; i > 0; i--)
            {
                CarBody leader = Body[i - 1];
                Body[i].Update(leader.Location.X, leader.Location.Y);
            }

            //head changes direction
            CarBody head = Body[0];
            int     x = 0, y = 0;
            int     step = CarBody.Size * 2;

            switch (Direction)
            {
            case Directions.Left:
                x = head.Location.X - step;
                y = head.Location.Y;
                break;

            case Directions.Right:
                x = head.Location.X + step;
                y = head.Location.Y;
                break;

            case Directions.Up:
                x = head.Location.X;
                y = head.Location.Y - step;
                break;

            case Directions.Down:
                x = head.Location.X;
                y = head.Location.Y + step;
                break;

            default:
                break;
            }
            head.Update(x, y);
        }
Exemplo n.º 5
0
        private void collide()
        {
            if (playerList.Count == 2)
            {
                int index = 1;
                foreach (Car Player in playerList)
                {
                    CarBody head  = Player.Body[0];
                    bool    crash = false;
                    for (int i = 1; i < playerList[index].Body.Count; i++)
                    {
                        crash = head.recBody.IntersectsWith(playerList[index].Body[i].recBody);
                        if (crash)
                        {
                            Player.setDead(true);
                        }
                    }
                    index--;
                }
            }
            if (playerList.Count == 3)
            {
                int index1 = 1;
                int index2 = 2;
                foreach (Car Player in playerList)
                {
                    CarBody head  = Player.Body[0];
                    bool    crash = false;
                    for (int i = 1; i < playerList[index1].Body.Count; i++)
                    {
                        crash = head.recBody.IntersectsWith(playerList[index1].Body[i].recBody);
                        if (crash)
                        {
                            Player.setDead(true);
                        }
                    }
                    for (int i = 1; i < playerList[index2].Body.Count; i++)
                    {
                        crash = head.recBody.IntersectsWith(playerList[index2].Body[i].recBody);

                        if (crash)
                        {
                            Player.setDead(true);
                        }
                    }

                    if (index1 == 0)
                    {
                        index2--;
                    }
                    if (index1 > 0)
                    {
                        index1--;
                    }
                }
            }
            if (playerList.Count == 4)
            {
                int index1 = 1;
                int index2 = 2;
                int index3 = 3;
                foreach (Car Player in playerList)
                {
                    CarBody head  = Player.Body[0];
                    bool    crash = false;

                    for (int i = 1; i < playerList[index1].Body.Count; i++)
                    {
                        crash = head.recBody.IntersectsWith(playerList[index1].Body[i].recBody);
                        if (crash)
                        {
                            Player.setDead(true);
                        }
                    }
                    for (int i = 1; i < playerList[index2].Body.Count; i++)
                    {
                        crash = head.recBody.IntersectsWith(playerList[index2].Body[i].recBody);

                        if (crash)
                        {
                            Player.setDead(true);
                        }
                    }
                    for (int i = 1; i < playerList[index3].Body.Count; i++)
                    {
                        crash = head.recBody.IntersectsWith(playerList[index3].Body[i].recBody);
                        if (crash)
                        {
                            Player.setDead(true);
                        }
                    }
                    if (index2 == 1)
                    {
                        index3--;
                    }
                    if (index1 == 0)
                    {
                        index2--;
                    }
                    if (index1 > 0)
                    {
                        index1--;
                    }
                }
            }
        }