Пример #1
0
        public void DecideAction(RaceEnd raceEnd, Building[,] buildings, GameTime gameTime)
        {
            //-3.14 is straight
            Console.WriteLine(dir);
            Console.WriteLine(vehicle.GetAngle().ToString());
            Console.WriteLine(vehicle.GetVelocity().ToString() + " m/s");
            double DgridX, DgridZ;
            DgridX = vehicle.GetPosition().X / 1.25;
            DgridZ = vehicle.GetPosition().Z / 1.25 * -1;

            if (DgridX < 1)
            {
                DgridX = 1;
            }

            if (DgridZ < 1)
            {
                DgridZ = 1;
            }

            int gridX, gridZ;
            gridX = (int)DgridX;
            gridZ = (int)DgridZ;

            double angle = Math.Round(vehicle.GetAngle(), 2);

            if (dir == "NORTH")
            {
                if (RoadEnds(gridX, gridZ++, buildings))
                {
                    vehicle.Brake();
                    //       Console.WriteLine(gridX.ToString());
                    //       Console.WriteLine(gridZ.ToString());
                }

                else
                {
                    if (IsTurning)
                    {
                        vehicle.Turn(turnDir);
                        if (vehicle.GetVelocity() < 0.008)
                        {
                            vehicle.Accelerate();
                            vehicle.Accelerate();
                        }

                        else
                        {
                            vehicle.Coast();
                        }

                        /*     if ((gameTime.TotalGameTime.TotalMilliseconds - turnStartTime.TotalGameTime.TotalMilliseconds) >= 300)
                             {
                                 IsTurning = false;
                                 Console.WriteLine("END");
                             } */

                        angle = Math.Round(vehicle.GetAngle(), 2);

                        if (angle == -4.71 || (angle >= -4.73 && angle <= -4.69))
                        {
                            IsTurning = false;
                            dir = "EAST";
                            vehicle.SetAngle(-MathHelper.Pi - (MathHelper.Pi / 2));
                        }

                        else if (angle == -1.57 || (angle >= -1.59 && angle <= -1.55))
                        {
                            IsTurning = false;
                            dir = "WEST";
                            vehicle.SetAngle(-MathHelper.Pi + (MathHelper.Pi / 2));
                        }

                        //         Console.WriteLine("turnin");
                    }

                    else
                    {
                        turnDir = InIntersection(gridX, gridZ, buildings, dir, raceEnd);

                        if (interDone == false)
                        {
                            if ((gridX != prevInterX || gridZ != prevInterZ) && !checkTwoLane(gridX, gridZ, buildings, dir))
                            {
                                interDone = true;
                                prevXZ = false;
                            }
                        }

                        if (turnDir == "STRAIGHT")
                        {
                            vehicle.Accelerate();
                            interDone = checkTwoLane(gridX, gridZ, buildings, dir);

                            if (interDone == false && prevXZ == false)
                            {
                                prevInterX = gridX;
                                prevInterZ = gridZ;
                                prevXZ = true;
                            }
                      //                  Console.WriteLine("STRRR");
                        }

                        else if (turnDir != null)
                        {
                            if (interDone == true)
                            {
                                IsTurning = true;
                                turnStartTime = gameTime;
                                vehicle.Turn(turnDir);
                                    vehicle.Coast();
                                //              Console.WriteLine("TURN");
                            }
                            //               Console.WriteLine("gea");
                        }

                        else
                        {
                            vehicle.Accelerate();
                            interDone = true;
                        }
                    }
                }
            }

            if (dir == "EAST")
            {
                //      Console.WriteLine("now heading eastbound");
                if (RoadEnds(gridX++, gridZ, buildings))
                {
                    vehicle.Brake();
                    //       Console.WriteLine(gridX.ToString());
                    //       Console.WriteLine(gridZ.ToString());
                }

                else
                {
                    if (IsTurning)
                    {
                        //         Console.WriteLine("turnin after EAST");
                        vehicle.Turn(turnDir);
                        if (vehicle.GetVelocity() < 0.008)
                        {
                            vehicle.Accelerate();
                            vehicle.Accelerate();
                        }

                        else
                        {
                            vehicle.Coast();
                        }

                        /*     if ((gameTime.TotalGameTime.TotalMilliseconds - turnStartTime.TotalGameTime.TotalMilliseconds) >= 300)
                             {
                                 IsTurning = false;
                                 Console.WriteLine("END");
                             } */

                        //      Console.WriteLine("turnin after EAST");
                        angle = Math.Round(vehicle.GetAngle(), 2);

                        if (angle == -6.28 || (angle >= -6.30 && angle <= -6.26))
                        {
                            IsTurning = false;
                            vehicle.SetAngle(0);
                            dir = "SOUTH";
                        }

                        else if (angle == -3.14 || (angle >= -3.16 && angle <= -3.12))
                        {
                            IsTurning = false;
                            dir = "NORTH";
                            vehicle.SetAngle(-MathHelper.Pi);
                        }

                        //        Console.WriteLine("turnin");
                    }

                    else
                    {
                        turnDir = InIntersection(gridX, gridZ, buildings, dir, raceEnd);

                        if (interDone == false)
                        {
                            if ((gridX != prevInterX || gridZ != prevInterZ) && !checkTwoLane(gridX, gridZ, buildings, dir))
                            {
                                interDone = true;
                                prevXZ = false;
                            }
                        }

                        if (turnDir == "STRAIGHT")
                        {
                            vehicle.Accelerate();
                            interDone = checkTwoLane(gridX, gridZ, buildings, dir);

                            if (interDone == false && prevXZ == false)
                            {
                                prevInterX = gridX;
                                prevInterZ = gridZ;
                                prevXZ = true;
                            }

                            //            Console.WriteLine("STRRR");
                        }

                        else if (turnDir != null)
                        {
                            if (interDone == true)
                            {
                                IsTurning = true;
                                turnStartTime = gameTime;
                                vehicle.Turn(turnDir);
                                vehicle.Coast();
                            }
                        }

                        else
                        {
                            vehicle.Accelerate();
                            interDone = true;
                        }
                    }
                }
            }

            if (dir == "SOUTH")
            {
                if (RoadEnds(gridX, gridZ--, buildings))
                {
                    vehicle.Brake();
                }

                else
                {
                    if (IsTurning)
                    {
                        vehicle.Turn(turnDir);

                        if (vehicle.GetVelocity() < 0.008)
                        {
                            vehicle.Accelerate();
                            vehicle.Accelerate();
                        }

                        else
                        {
                            vehicle.Coast();
                        }

                        angle = Math.Round(vehicle.GetAngle(), 2);

                        if (angle == -1.57 || (angle >= -1.59 && angle <= -1.55))
                        {
                            IsTurning = false;
                            dir = "WEST";
                            vehicle.SetAngle(-MathHelper.Pi + (MathHelper.Pi / 2));
                        }

                        else if (angle == 1.57f || (angle >= 1.55 && angle <= 1.59))
                        {
                            IsTurning = false;
                            dir = "EAST";
                            vehicle.SetAngle(-MathHelper.Pi - (MathHelper.Pi / 2));
                        }
                    }

                    else
                    {
                        turnDir = InIntersection(gridX, gridZ, buildings, dir, raceEnd);

                        if (interDone == false)
                        {
                            if ((gridX != prevInterX || gridZ != prevInterZ) && !checkTwoLane(gridX, gridZ, buildings, dir))
                            {
                                interDone = true;
                                prevXZ = false;
                            }
                        }

                        if (turnDir == "STRAIGHT")
                        {
                            vehicle.Accelerate();
                            interDone = checkTwoLane(gridX, gridZ, buildings, dir);

                            if (interDone == false && prevXZ == false)
                            {
                                prevInterX = gridX;
                                prevInterZ = gridZ;
                                prevXZ = true;
                            }
                        }

                        else if (turnDir != null)
                        {
                            if (interDone == true)
                            {
                                IsTurning = true;
                                turnStartTime = gameTime;
                                vehicle.Turn(turnDir);
                                    vehicle.Coast();
                            }
                        }

                        else
                        {
                            vehicle.Accelerate();
                            interDone = true;
                        }
                    }
                }
            }

            if (dir == "WEST")
            {
                //      Console.WriteLine("now heading eastbound");
                if (RoadEnds(gridX--, gridZ, buildings))
                {
                    vehicle.Brake();
                    //       Console.WriteLine(gridX.ToString());
                    //       Console.WriteLine(gridZ.ToString());
                }

                else
                {
                    if (IsTurning)
                    {
                        //         Console.WriteLine("turnin after EAST");
                        vehicle.Turn(turnDir);

                        if (vehicle.GetVelocity() < 0.008)
                        {
                            vehicle.Accelerate();
                            vehicle.Accelerate();
                        }

                        else
                        {
                            vehicle.Coast();
                        }

                        /*     if ((gameTime.TotalGameTime.TotalMilliseconds - turnStartTime.TotalGameTime.TotalMilliseconds) >= 300)
                             {
                                 IsTurning = false;
                                 Console.WriteLine("END");
                             } */

                        angle = Math.Round(vehicle.GetAngle(), 2);

                        if (angle == -6.28 || (angle >= -6.30 && angle <= -6.26))
                        {
                            IsTurning = false;
                            vehicle.SetAngle(0);
                            dir = "SOUTH";
                        }

                        else if (angle == -3.14 || (angle >= -3.16 && angle <= -3.12))
                        {
                            IsTurning = false;
                            dir = "NORTH";
                            vehicle.SetAngle(-MathHelper.Pi);
                        }

                        //        Console.WriteLine("turnin");
                    }

                    else
                    {
                        turnDir = InIntersection(gridX, gridZ, buildings, dir, raceEnd);

                        if (interDone == false)
                        {
                            if ((gridX != prevInterX || gridZ != prevInterZ) && !checkTwoLane(gridX, gridZ, buildings, dir))
                            {
                                interDone = true;
                                prevXZ = false;
                            }
                        }

                        if (turnDir == "STRAIGHT")
                        {
                            vehicle.Accelerate();
                            interDone = checkTwoLane(gridX, gridZ, buildings, dir);

                            if (interDone == false && prevXZ == false)
                            {
                                prevInterX = gridX;
                                prevInterZ = gridZ;
                                prevXZ = true;
                            }
                        }

                        else if (turnDir != null)
                        {
                            if (interDone == true)
                            {
                                IsTurning = true;
                                turnStartTime = gameTime;
                                vehicle.Turn(turnDir);
                                    vehicle.Coast();
                            }
                        }

                        else
                        {
                            vehicle.Accelerate();
                            interDone = true;
                        }
                    }
                }
            }
        }
Пример #2
0
        // NOTE: THERE IS A BUG HERE. If the AI gets close to the border, the game thinks it is in the border tile and checks outside of the map
        // crashing the game with an out of bounds error. This may be a problem with the bounding boxes of the AIs, or everything in the game.
        public String InIntersection(double xCoord, double zCoord, Building[,] buildings, string dir, RaceEnd raceEnd)
        {
            int x = (int)xCoord;
            int z = (int)zCoord;
            Boolean[] canGo = new Boolean[3];
            Boolean[] shouldGo = new Boolean[3];
            canGo[0] = false;
            canGo[1] = false;
            canGo[2] = false;
            shouldGo[0] = false;
            shouldGo[1] = false;
            shouldGo[2] = false;
            int randInt;
            //0 straight, 1 left, 2 right
            if (dir == "NORTH")
            {
                /*       if (!buildings[x - 1, z].exists() && !buildings[x + 1, z].exists())
                       {
                           return "RIGHT";
                       }

                       else if (!buildings[x - 1, z].exists())
                       {
                           return "LEFT";
                       }

                       else if (!buildings[x + 1, z].exists())
                       {
                           return "RIGHT";
                       } */

                // Out of bounds error can happen here
                if (!buildings[x, z + 1].exists())
                {
                    canGo[0] = true;
                }

                if (!buildings[x - 1, z].exists())
                {
                    canGo[1] = true;
                }

                if (!buildings[x + 1, z].exists())
                {
                    canGo[2] = true;
                }

                int count = 0;
                for (int i = 0; i < 3; i++)
                {
                    if (canGo[i])
                    {
                        count++;
                    }
                }

                if (count == 0)
                {
                    return "RIGHT";
                }

                else if (count == 1)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (canGo[i])
                        {
                            if (i == 0)
                            {
                                return null;
                            }

                            else if (i == 1)
                            {
                                return "LEFT";
                            }

                            else if (i == 2)
                            {
                                return "RIGHT";
                            }
                        }
                    }
                }

                else
                {
                    //       Console.WriteLine("should");
             //       Boolean[] shouldGo = new Boolean[3];
               //         shouldGo[0] = false;
             //           shouldGo[1] = false;
               //             shouldGo[2] = false;

                    if (z + 1 <= raceEnd.GetPosition().Z && canGo[0])
                    {
                        shouldGo[0] = true;
                    }

                    if (x - 1 >= raceEnd.GetPosition().X && canGo[1])
                    {
                        shouldGo[1] = true;
                    }

                    if (x + 1 <= raceEnd.GetPosition().X && canGo[2])
                    {
                        shouldGo[2] = true;
                    }

                    count = 0;
                    for (int i = 0; i < 3; i++)
                    {
                        if (shouldGo[i])
                        {
                            count++;
                        }
                    }
                    //        Console.WriteLine(count.ToString());
                    if (count == 0)
                    {
                        randInt = rand.Next(0, 3);

                        while (canGo[randInt] == false)
                        {
                            randInt = rand.Next(0, 3);
                        }

                        if (randInt == 0)
                        {
                            return "STRAIGHT";
                        }

                        else if (randInt == 1)
                        {
                            return "LEFT";
                        }

                        else if (randInt == 2)
                        {
                            return "RIGHT";
                        }
                    }

                    else if (count == 1)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            if (shouldGo[i])
                            {
                                if (i == 0)
                                {
                                    return "STRAIGHT";
                                }

                                else if (i == 1)
                                {
                                    return "LEFT";
                                }

                                else if (i == 2)
                                {
                                    return "RIGHT";
                                }
                            }
                        }
                    }

                    else
                    {
                        randInt = rand.Next(0, 3);

                        while (shouldGo[randInt] == false)
                        {
                            randInt = rand.Next(0, 3);
                        }
                        //        randInt = 0;
                        //         Console.WriteLine(randInt.ToString());

                        if (randInt == 0)
                        {
                            return "STRAIGHT";
                        }

                        else if (randInt == 1)
                        {
                            return "LEFT";
                        }

                        else if (randInt == 2)
                        {
                            return "RIGHT";
                        }
                    }
                }
            }

            if (dir == "EAST")
            {
                /*       if (!buildings[x, z + 1].exists() && !buildings[x, z - 1].exists())
                       {
                           return "RIGHT";
                       }

                       else if (!buildings[x, z + 1].exists())
                       {
                           return "LEFT";
                       }

                       else if (!buildings[x, z - 1].exists())
                       {
                           return "RIGHT";
                       } */

                if (!buildings[x + 1, z].exists())
                {
                    canGo[0] = true;
                }

                if (!buildings[x, z + 1].exists())
                {
                    canGo[1] = true;
                }

                if (!buildings[x, z - 1].exists())
                {
                    canGo[2] = true;
                }

                int count = 0;
                for (int i = 0; i < 3; i++)
                {
                    if (canGo[i])
                    {
                        count++;
                    }
                }

                if (count == 0)
                {
                    return "RIGHT";
                }

                else  if (count == 1)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (canGo[i])
                        {
                            if (i == 0)
                            {
                                return null;
                            }

                            else if (i == 1)
                            {
                                return "LEFT";
                            }

                            else if (i == 2)
                            {
                                return "RIGHT";
                            }
                        }
                    }
                }

                else
                {
                    //       Console.WriteLine("should");
                    //        Boolean[] shouldGo = new Boolean[3];
                    //         shouldGo[0] = false;
                    //         shouldGo[1] = false;
                    //          shouldGo[2] = false;

                    if (x + 1 <= raceEnd.GetPosition().X && canGo[0])
                    {
                        shouldGo[0] = true;
                    }

                    if (z + 1 <= raceEnd.GetPosition().Z && canGo[1])
                    {
                        shouldGo[1] = true;
                    }

                    if (z - 1 >= raceEnd.GetPosition().Z && canGo[2])
                    {
                        shouldGo[2] = true;
                    }

                    count = 0;
                    for (int i = 0; i < 3; i++)
                    {
                        if (shouldGo[i])
                        {
                            count++;
                        }
                    }
                    //        Console.WriteLine(count.ToString());
                    if (count == 0)
                    {
                        randInt = rand.Next(0, 3);

                        while (canGo[randInt] == false)
                        {
                            randInt = rand.Next(0, 3);
                        }

                        if (randInt == 0)
                        {
                            return "STRAIGHT";
                        }

                        else if (randInt == 1)
                        {
                            return "LEFT";
                        }

                        else if (randInt == 2)
                        {
                            return "RIGHT";
                        }
                    }

                    else if (count == 1)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            if (shouldGo[i])
                            {
                                if (i == 0)
                                {
                                    return "STRAIGHT";
                                }

                                else if (i == 1)
                                {
                                    return "LEFT";
                                }

                                else if (i == 2)
                                {
                                    return "RIGHT";
                                }
                            }
                        }
                    }

                    else
                    {
                        randInt = rand.Next(0, 3);

                        while (shouldGo[randInt] == false)
                        {
                            randInt = rand.Next(0, 3);
                        }
                        //        randInt = 0;
                        //            Console.WriteLine(randInt.ToString());

                        if (randInt == 0)
                        {
                            return "STRAIGHT";
                        }

                        else if (randInt == 1)
                        {
                            return "LEFT";
                        }

                        else if (randInt == 2)
                        {
                            return "RIGHT";
                        }
                    }
                }
            }

            if (dir == "SOUTH")
            {
                if (!buildings[x, z - 1].exists())
                {
                    canGo[0] = true;
                }

                if (!buildings[x + 1, z].exists())
                {
                    canGo[1] = true;
                }

                if (!buildings[x - 1, z].exists())
                {
                    canGo[2] = true;
                }

                int count = 0;
                for (int i = 0; i < 3; i++)
                {
                    if (canGo[i])
                    {
                        count++;
                    }
                }

                if (count == 0)
                {
                    return "RIGHT";
                }

                else if (count == 1)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (canGo[i])
                        {
                            if (i == 0)
                            {
                                return null;
                            }

                            else if (i == 1)
                            {
                                return "LEFT";
                            }

                            else if (i == 2)
                            {
                                return "RIGHT";
                            }
                        }
                    }
                }

                else
                {
              //              Boolean[] shouldGo = new Boolean[3];
              //              shouldGo[0] = false;
               //             shouldGo[1] = false;
              //              shouldGo[2] = false;

                    if (z - 1 >= raceEnd.GetPosition().Z && canGo[0])
                    {
                        shouldGo[0] = true;
                    }

                    if (x + 1 <= raceEnd.GetPosition().X && canGo[1])
                    {
                        shouldGo[1] = true;
                    }

                    if (x - 1 >= raceEnd.GetPosition().X && canGo[2])
                    {
                        shouldGo[2] = true;
                    }

                    count = 0;
                    for (int i = 0; i < 3; i++)
                    {
                        if (shouldGo[i])
                        {
                            count++;
                        }
                    }
                    //        Console.WriteLine(count.ToString());
                    if (count == 0)
                    {
                        randInt = rand.Next(0, 3);

                        while (canGo[randInt] == false)
                        {
                            randInt = rand.Next(0, 3);
                        }

                        if (randInt == 0)
                        {
                            return "STRAIGHT";
                        }

                        else if (randInt == 1)
                        {
                            return "LEFT";
                        }

                        else if (randInt == 2)
                        {
                            return "RIGHT";
                        }
                    }

                    else if (count == 1)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            if (shouldGo[i])
                            {
                                if (i == 0)
                                {
                                    return "STRAIGHT";
                                }

                                else if (i == 1)
                                {
                                    return "LEFT";
                                }

                                else if (i == 2)
                                {
                                    return "RIGHT";
                                }
                            }
                        }
                    }

                    else
                    {
                        randInt = rand.Next(0, 3);

                        while (shouldGo[randInt] == false)
                        {
                            randInt = rand.Next(0, 3);
                        }
                        //          Console.WriteLine(randInt.ToString());

                        if (randInt == 0)
                        {
                            return "STRAIGHT";
                        }

                        else if (randInt == 1)
                        {
                            return "LEFT";
                        }

                        else if (randInt == 2)
                        {
                            return "RIGHT";
                        }
                    }
                }
            }

            if (dir == "WEST")
            {
                if (!buildings[x - 1, z].exists())
                {
                    canGo[0] = true;
                }

                if (!buildings[x, z - 1].exists())
                {
                    canGo[1] = true;
                }

                if (!buildings[x, z + 1].exists())
                {
                    canGo[2] = true;
                }

                int count = 0;
                for (int i = 0; i < 3; i++)
                {
                    if (canGo[i])
                    {
                        count++;
                    }
                }

                if (count == 0)
                {
                    return "RIGHT";
                }

                else if (count == 1)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        if (canGo[i])
                        {
                            if (i == 0)
                            {
                                return null;
                            }

                            else if (i == 1)
                            {
                                return "LEFT";
                            }

                            else if (i == 2)
                            {
                                return "RIGHT";
                            }
                        }
                    }
                }

                else
                {
                    //       Console.WriteLine("should");
              //              Boolean[] shouldGo = new Boolean[3];
              //              shouldGo[0] = false;
              //              shouldGo[1] = false;
              //              shouldGo[2] = false;

                    if (x - 1 >= raceEnd.GetPosition().X && canGo[0])
                    {
                        shouldGo[0] = true;
                    }

                    if (z - 1 >= raceEnd.GetPosition().Z && canGo[1])
                    {
                        shouldGo[1] = true;
                    }

                    if (z + 1 <= raceEnd.GetPosition().Z && canGo[2])
                    {
                        shouldGo[2] = true;
                    }

                    count = 0;
                    for (int i = 0; i < 3; i++)
                    {
                        if (shouldGo[i])
                        {
                            count++;
                        }
                    }
                    //        Console.WriteLine(count.ToString());
                    if (count == 0)
                    {
                        randInt = rand.Next(0, 3);

                        while (canGo[randInt] == false)
                        {
                            randInt = rand.Next(0, 3);
                        }

                        if (randInt == 0)
                        {
                            return "STRAIGHT";
                        }

                        else if (randInt == 1)
                        {
                            return "LEFT";
                        }

                        else if (randInt == 2)
                        {
                            return "RIGHT";
                        }
                    }

                    else if (count == 1)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            if (shouldGo[i])
                            {
                                if (i == 0)
                                {
                                    return "STRAIGHT";
                                }

                                else if (i == 1)
                                {
                                    return "LEFT";
                                }

                                else if (i == 2)
                                {
                                    return "RIGHT";
                                }
                            }
                        }
                    }

                    else
                    {
                        randInt = rand.Next(0, 3);

                        while (shouldGo[randInt] == false)
                        {
                            randInt = rand.Next(0, 3);
                        }
                        //        randInt = 0;
                        //                 Console.WriteLine(randInt.ToString());

                        if (randInt == 0)
                        {
                            return "STRAIGHT";
                        }

                        else if (randInt == 1)
                        {
                            return "LEFT";
                        }

                        else if (randInt == 2)
                        {
                            return "RIGHT";
                        }
                    }
                }
            }

            return null;
        }
Пример #3
0
        private Boolean checkTwoLane(int x, int z, Building[,] buildings, string dir)
        {
            if (dir == "NORTH" || dir == "SOUTH")
            {
                if (z + 2 < 100)
                {
                    if (!buildings[x + 1, z].exists() && !buildings[x + 1, z + 1].exists() && !buildings[x + 1, z + 2].exists())
                    {
                        return true;
                    }

                    if (!buildings[x - 1, z].exists() && !buildings[x - 1, z + 1].exists() && !buildings[x - 1, z + 2].exists())
                    {
                        return true;
                    }
                }

                else
                {
                    if (!buildings[x + 1, z].exists() && !buildings[x + 1, z - 1].exists() && !buildings[x + 1, z - 2].exists())
                    {
                        return true;
                    }

                    if (!buildings[x - 1, z].exists() && !buildings[x - 1, z - 1].exists() && !buildings[x - 1, z - 2].exists())
                    {
                        return true;
                    }
                }
            }

            if (dir == "EAST" || dir == "WEST")
            {
                if (x + 2 < 100)
                {
                    if (!buildings[x, z - 1].exists() && !buildings[x + 1, z - 1].exists() && !buildings[x + 2, z - 1].exists())
                    {
                        return true;
                    }

                    if (!buildings[x, z + 1].exists() && !buildings[x + 1, z + 1].exists() && !buildings[x + 2, z + 1].exists())
                    {
                        return true;
                    }
                }

                else
                {
                    if (!buildings[x, z - 1].exists() && !buildings[x - 1, z - 1].exists() && !buildings[x - 2, z - 1].exists())
                    {
                        return true;
                    }

                    if (!buildings[x, z + 1].exists() && !buildings[x - 1, z + 1].exists() && !buildings[x - 2, z + 1].exists())
                    {
                        return true;
                    }
                }
            }

            return false;
        }
Пример #4
0
        public Boolean RoadEnds(int x, int z, Building[,] buildings)
        {
            if (buildings[x, z].exists())
            {
                return true;
            }

            return false;
        }
Пример #5
0
 private void GiveBuildingValues(int i, int j)
 {
     int type = rand.Next(1, 7);
     int height = type;
     buildings[i, j] = new Building(height, true);
 }
Пример #6
0
        public Building[,] CreateBuildings()
        {
            buildings = new Building[100, 100];
            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    //BORDER
                    if (i == 0 || i == 99 || j == 0 || j == 99)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //1
                    else if (i >= 2 && i <= 11 && j >= 2 && j <= 11)
                    {
                        GiveBuildingValues(i, j);
                    }

                         //2
                    else if (i >= 2 && i <= 11 && j >= 13 && j <= 22)
                    {
                        GiveBuildingValues(i, j);
                    }

                         //3
                    else if (i >= 13 && i <= 22 && j >= 2 && j <= 11)
                    {
                        GiveBuildingValues(i, j);
                    }

                         //4
                    else if (i >= 13 && i <= 22 && j >= 13 && j <= 22)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //5
                    else if (i >= 24 && i <= 36 && j >= 2 && j <= 22)
                    {
                        GiveBuildingValues(i, j);
                    }

                       //6
                    else if (i >= 38 && i <= 42 && j >= 2 && j <= 22)
                    {
                        GiveBuildingValues(i, j);
                    }

                       //7
                    else if (i >= 45 && i <= 69 && j >= 1 && j <= 22)
                    {
                        GiveBuildingValues(i, j);
                    }

                       //8
                    else if (i >= 71 && i <= 72 && j >= 2 && j <= 22)
                    {
                        GiveBuildingValues(i, j);
                    }

                         //9
                    else if (i >= 75 && i <= 85 && j >= 2 && j <= 22)
                    {
                        GiveBuildingValues(i, j);
                    }

                         //10
                    else if (i >= 87 && i <= 97 && j >= 12 && j <= 22)
                    {
                        GiveBuildingValues(i, j);
                    }

                         //11
                    else if (i >= 87 && i <= 97 && j >= 2 && j <= 10)
                    {
                        GiveBuildingValues(i, j);
                    }

                         //12
                    else if (i >= 2 && i <= 22 && j >= 25 && j <= 34)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //13
                    else if (i >= 24 && i <= 42 && j >= 25 && j <= 34)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //14
                    else if (i >= 45 && i <= 63 && j >= 25 && j <= 34)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //15
                    else if (i >= 65 && i <= 83 && j >= 25 && j <= 34)
                    {
                        GiveBuildingValues(i, j);
                    }

                       //16
                    else if (i >= 85 && i <= 96 && j >= 25 && j <= 34)
                    {
                        GiveBuildingValues(i, j);
                    }

                       //17
                    else if (i >= 1 && i <= 11 && j >= 36 && j <= 41)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //18
                    else if (i >= 13 && i <= 29 && j >= 36 && j <= 41)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //19
                    else if (i >= 31 && i <= 35 && j >= 36 && j <= 41)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //20
                    else if (i >= 38 && i <= 42 && j >= 36 && j <= 64)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //21
                    else if (i >= 45 && i <= 56 && j >= 36 && j <= 64)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //22
                    else if (i >= 59 && i <= 76 && j >= 36 && j <= 47)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //23
                    else if (i >= 79 && i <= 83 && j >= 36 && j <= 47)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //24
                    else if (i >= 85 && i <= 87 && j >= 36 && j <= 47)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //25
                    else if (i >= 89 && i <= 96 && j >= 36 && j <= 55)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //26
                    else if (i >= 2 && i <= 18 && j >= 43 && j <= 53)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //27
                    else if (i >= 21 && i <= 29 && j >= 43 && j <= 53)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //28
                    else if (i >= 31 && i <= 35 && j >= 43 && j <= 47)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //29
                    else if (i >= 30 && i <= 35 && j >= 49 && j <= 53)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //30
                    else if (i >= 57 && i <= 74 && j >= 49 && j <= 53)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //31
                    else if (i >= 76 && i <= 87 && j >= 49 && j <= 53)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //32
                    else if (i >= 2 && i <= 18 && j >= 55 && j <= 68)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //33
                    else if (i >= 21 && i <= 35 && j >= 55 && j <= 64)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //34
                    else if (i >= 59 && i <= 70 && j >= 56 && j <= 64)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //35
                    else if (i >= 72 && i <= 74 && j >= 56 && j <= 64)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //36
                    else if (i >= 76 && i <= 86 && j >= 56 && j <= 64)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //37
                    else if (i >= 89 && i <= 96 && j >= 57 && j <= 64)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //38
                    else if (i >= 2 && i <= 18 && j >= 70 && j <= 73)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //39
                    else if (i >= 20 && i <= 22 && j >= 67 && j <= 73)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //40
                    else if (i >= 24 && i <= 28 && j >= 67 && j <= 73)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //41
                    else if (i >= 31 && i <= 42 && j >= 67 && j <= 72)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //42
                    else if (i >= 45 && i <= 60 && j >= 67 && j <= 84)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //43
                    else if (i >= 63 && i <= 75 && j >= 67 && j <= 84)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //44
                    else if (i >= 78 && i <= 86 && j >= 66 && j <= 74)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //45
                    else if (i >= 89 && i <= 98 && j >= 66 && j <= 74)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //46
                    else if (i >= 2 && i <= 28 && j >= 75 && j <= 97)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //47
                    else if (i >= 31 && i <= 42 && j >= 74 && j <= 75)
                    {
                        GiveBuildingValues(i, j);
                    }

                         //48
                    else if (i >= 31 && i <= 42 && j >= 77 && j <= 88)
                    {
                        GiveBuildingValues(i, j);
                    }

                         //49
                    else if (i >= 31 && i <= 42 && j >= 90 && j <= 98)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //50
                    else if (i >= 45 && i <= 57 && j >= 86 && j <= 98)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //51
                    else if (i >= 59 && i <= 75 && j >= 86 && j <= 90)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //52
                    else if (i >= 59 && i <= 90 && j >= 92 && j <= 97)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //53
                    else if (i >= 78 && i <= 90 && j >= 89 && j <= 90)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //54
                    else if (i >= 78 && i <= 90 && j >= 86 && j <= 87)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //55
                    else if (i >= 78 && i <= 84 && j >= 77 && j <= 84)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //56
                    else if (i >= 87 && i <= 96 && j >= 77 && j <= 82)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //57
                    else if (i >= 87 && i <= 96 && j >= 84 && j <= 84)
                    {
                        GiveBuildingValues(i, j);
                    }

                        //58
                    else if (i >= 92 && i <= 96 && j >= 86 && j <= 97)
                    {
                        GiveBuildingValues(i, j);
                    }

                    else
                    {
                        buildings[i, j] = new Building(false);
                    }
                }
            }

            return buildings;
        }