Пример #1
0
        public static DumboCar getInstance(MatrixCoords topLeft, Lane lane, int speed)
        {
            if (instance == null)
                instance = new DumboCar(topLeft,lane,speed);

            return instance;
        }
Пример #2
0
        public static DumboCar getInstance(MatrixCoords topLeft, Lane lane, int speed)
        {
            if (instance == null)
            {
                instance = new DumboCar(topLeft, lane, speed);
            }

            return(instance);
        }
Пример #3
0
 public static void HandleCollisions(DumboCar car, List<GameObject> movingObjects)
 {
     foreach (var obj in movingObjects)
     {
         if (car.Lane == obj.Lane)
         {
             for (int i = 0; i < obj.Body.GetLength(0); i++)
             {
                 for (int j = 0; j < car.Body.GetLength(0); j++)
                 {
                     if (car.TopLeft.Row + j == obj.TopLeft.Row + i || car.TopLeft.Row + j == obj.TopLeft.Row + i)
                     {
                         obj.RespondToCollision(car);
                         return;
                     }
                 }
             }
         }
     }
 }
Пример #4
0
 public static void HandleCollisions(DumboCar car, List <GameObject> movingObjects)
 {
     foreach (var obj in movingObjects)
     {
         if (car.Lane == obj.Lane)
         {
             for (int i = 0; i < obj.Body.GetLength(0); i++)
             {
                 for (int j = 0; j < car.Body.GetLength(0); j++)
                 {
                     if (car.TopLeft.Row + j == obj.TopLeft.Row + i || car.TopLeft.Row + j == obj.TopLeft.Row + i)
                     {
                         obj.RespondToCollision(car);
                         return;
                     }
                 }
             }
         }
     }
 }
Пример #5
0
 public override void RespondToCollision(DumboCar car)
 {
     car.DecreaseSpeed(140);
     this.isDestroyed = true;
 }
Пример #6
0
 public override void RespondToCollision(DumboCar car)
 {
     car.Points      += value * 10;
     this.isDestroyed = true;
 }
Пример #7
0
 public override void RespondToCollision(DumboCar car)
 {
     car.DecreaseSpeed(80);
     this.isDestroyed = true;
 }
Пример #8
0
        public List <GameObject> GenerateObjects(DumboCar car) // Generates one or many objects
        {
            List <GameObject> objList       = new List <GameObject>();
            List <Lane>       occupiedLanes = new List <Lane>();

            int chanceObj = randomGenerator.Next(1, 4); //randomize number of obj produced

            for (int i = 0; i < chanceObj; i++)
            {
                // initial value, no effect
                Lane lane = Lane.Left;

                bool   isLaneFound = false;
                Array  values      = Enum.GetValues(typeof(Lane));
                Random random      = new Random();

                while (!isLaneFound)
                {
                    lane = (Lane)values.GetValue(random.Next(values.Length)); //randomize lane
                    if (!occupiedLanes.Contains(lane))
                    {
                        isLaneFound = true;
                    }
                }

                MatrixCoords topLeft;
                if (lane == Lane.Left)
                {
                    occupiedLanes.Add(Lane.Left);
                    topLeft = new MatrixCoords(0, 14);
                }
                else if (lane == Lane.MiddleLeft)
                {
                    occupiedLanes.Add(Lane.MiddleLeft);
                    topLeft = new MatrixCoords(0, 25);
                }
                else if (lane == Lane.MiddleRight)
                {
                    occupiedLanes.Add(Lane.MiddleRight);
                    topLeft = new MatrixCoords(0, 36);
                }
                else
                {
                    occupiedLanes.Add(Lane.Right);
                    topLeft = new MatrixCoords(0, 47);
                }

                GameObject obj;
                int        chance = randomGenerator.Next(0, 100); //randomize TimeBonus or else
                if (Timer.TimeLeft < 25 && chance < 20 - car.Points / 100)
                {
                    obj = new TimeBonus(topLeft, lane);
                }
                else
                {
                    chance = randomGenerator.Next(0, 100); //randomize object types
                    if (chance < 25)
                    {
                        obj = new Reward(topLeft, lane, randomGenerator.Next(1, 10)); //randomize reward values
                    }
                    else if (chance < 50)
                    {
                        obj = new Cone(topLeft, lane);
                    }
                    else if (chance < 75)
                    {
                        obj = new OtherCar(topLeft, lane);
                    }
                    else
                    {
                        obj = new Spill(topLeft, lane);
                    }
                }
                objList.Add(obj);
            }

            return(objList);
        }
Пример #9
0
        public virtual void Run()
        {
            Timer.StartTime             = DateTime.Now;
            Timer.timeToReachCheckpoint = 30;
            Timer.TimeLeft = Timer.timeToReachCheckpoint;
            var playerCar = DumboCar.getInstance(new MatrixCoords(20, 47), Lane.Right, 40);

            playerCar.Speed  = 40;
            playerCar.Points = 0;

            while (true)
            {
                this.renderer.RenderAll();

                if (playerCar.Speed == 0)
                {
                    sleepTime = 1000;
                }
                else
                {
                    sleepTime = (1 - playerCar.Speed / 310.0) * 900;
                }

                System.Threading.Thread.Sleep((int)sleepTime);

                this.userController.ProcessInput();

                this.renderer.ClearQueue();
                this.allObjects.RemoveAll(obj => obj.IsDestroyed);

                this.renderer.EnqueueForRendering(field);
                this.renderer.EnqueueForRendering(playerCar);


                SpeedInfo speedInfo = new SpeedInfo(playerCar.Speed);
                this.renderer.EnqueueForRendering(speedInfo);

                TimeLeftInfo timeInfo = new TimeLeftInfo(Timer.TimeLeft);
                this.renderer.EnqueueForRendering(timeInfo);

                PointsInfo pointsInfo = new PointsInfo(playerCar.Points);
                this.renderer.EnqueueForRendering(pointsInfo);

                playerCar.Update();

                foreach (var obj in this.allObjects)
                {
                    obj.Update();
                    this.renderer.EnqueueForRendering(obj);
                }

                CollisionDetector.HandleCollisions(playerCar, allObjects);
                CollisionDetector.HandleScreenExit(allObjects, field);

                bool isProduced = true;
                if (allObjects.Count != 0)
                {
                    foreach (var obj in allObjects)
                    {
                        if (obj.TopLeft.Row >= 0 && obj.TopLeft.Row <= 7)
                        {
                            isProduced = false;
                            break;
                        }
                    }
                    if (isProduced)
                    {
                        List <GameObject> producedObjects = randomObjectGenerator.GenerateObjects(playerCar);
                        allObjects.AddRange(producedObjects);
                    }
                }
                else
                {
                    List <GameObject> producedObjects = randomObjectGenerator.GenerateObjects(playerCar);
                    allObjects.AddRange(producedObjects);
                }

                Timer.EndTime = DateTime.Now;
                if (Timer.EndTime > Timer.StartTime.AddSeconds(Timer.timeToReachCheckpoint))
                {
                    break;
                }
                Timer.Tick();
            }
        }
Пример #10
0
 public virtual void MovePlayerCarRight()
 {
     DumboCar.getInstance(new MatrixCoords(20, 47), Lane.Right, 40).MoveRight();
 }
Пример #11
0
 public virtual void RespondToCollision(DumboCar car)
 {
 }
Пример #12
0
 public virtual void RespondToCollision(DumboCar car)
 {
 }
Пример #13
0
 public override void RespondToCollision(DumboCar car)
 {
     car.Points += value*10;
     this.isDestroyed = true;
 }
Пример #14
0
        // Generates one or many objects
        public List<GameObject> GenerateObjects(DumboCar car)
        {
            List<GameObject> objList = new List<GameObject>();
            List<Lane> occupiedLanes = new List<Lane>();

            int chanceObj = randomGenerator.Next(1, 4); //randomize number of obj produced
            for (int i = 0; i < chanceObj; i++)
            {
                // initial value, no effect
                Lane lane = Lane.Left;

                bool isLaneFound = false;
                Array values = Enum.GetValues(typeof(Lane));
                Random random = new Random();

                while (!isLaneFound)
                {
                    lane = (Lane)values.GetValue(random.Next(values.Length)); //randomize lane
                    if (!occupiedLanes.Contains(lane))
                    {
                        isLaneFound = true;
                    }
                }

                MatrixCoords topLeft;
                if (lane == Lane.Left)
                {
                    occupiedLanes.Add(Lane.Left);
                    topLeft = new MatrixCoords(0, 14);
                }
                else if (lane == Lane.MiddleLeft)
                {
                    occupiedLanes.Add(Lane.MiddleLeft);
                    topLeft = new MatrixCoords(0, 25);
                }
                else if (lane == Lane.MiddleRight)
                {
                    occupiedLanes.Add(Lane.MiddleRight);
                    topLeft = new MatrixCoords(0, 36);
                }
                else
                {
                    occupiedLanes.Add(Lane.Right);
                    topLeft = new MatrixCoords(0, 47);
                }

                GameObject obj;
                int chance = randomGenerator.Next(0, 100); //randomize TimeBonus or else
                if (Timer.TimeLeft<25 && chance < 20 - car.Points/100)
                {
                    obj = new TimeBonus(topLeft, lane);
                }
                else
                {
                    chance = randomGenerator.Next(0, 100); //randomize object types
                    if (chance < 25)
                    {
                        obj = new Reward(topLeft, lane, randomGenerator.Next(1, 10)); //randomize reward values
                    }
                    else if (chance < 50)
                    {
                        obj = new Cone(topLeft, lane);
                    }
                    else if (chance < 75)
                    {
                        obj = new OtherCar(topLeft, lane);
                    }
                    else
                    {
                        obj = new Spill(topLeft, lane);
                    }
                }
                objList.Add(obj);
            }

            return objList;
        }
Пример #15
0
 public override void RespondToCollision(DumboCar car)
 {
     Timer.timeToReachCheckpoint += 10;
     this.isDestroyed             = true;
 }
Пример #16
0
 public override void RespondToCollision(DumboCar car)
 {
     Timer.timeToReachCheckpoint += 10;
     this.isDestroyed = true;
 }