예제 #1
0
    private Vector3Int RandomlyFitPart(HousePart newBlock)
    {
        float xsize = newBlock.xsize;
        float ysize = newBlock.ysize;
        float zsize = newBlock.zsize;

        bool[] adjacencies = newBlock.faces;
        bool   locomotion  = newBlock.locomotion;

        List <Vector3Int> validPositions = new List <Vector3Int>();

        if (locomotion)
        {
            for (int x = -1; x <= 1; x++)
            {
                for (int z = -1; z <= 1; z++)
                {
                    if (!GridContainsPart(x, -1, z))
                    {
                        validPositions.Add(new Vector3Int(x, -1, z));
                    }
                }
            }
            TrackController track = newBlock.gameObject.GetComponent <TrackController>();
            track.Enable();
        }
        else
        {
            for (int i = 0; i < 6; i++)
            {
                if (adjacencies[i])
                {
                    for (int j = 0; j < freeSpaces.Count; j++)
                    {
                        switch (i)
                        {
                        case 0:
                            if (GridContainsPart(freeSpaces[j].x, freeSpaces[j].y + 1, freeSpaces[j].z))
                            {
                                for (int x = 0; x < xsize; x++)
                                {
                                    for (int z = 0; z < zsize; z++)
                                    {
                                        if (TestPartFit(new Vector3Int(freeSpaces[j].x - x, freeSpaces[j].y,
                                                                       freeSpaces[j].z - z), xsize, ysize, zsize))
                                        {
                                            validPositions.Add(new Vector3Int(freeSpaces[j].x - x, freeSpaces[j].y,
                                                                              freeSpaces[j].z - z));
                                        }
                                    }
                                }
                            }
                            break;

                        case 1:
                            if (GridContainsPart(freeSpaces[j].x, freeSpaces[j].y - 1, freeSpaces[j].z))
                            {
                                for (int x = 0; x < xsize; x++)
                                {
                                    for (int z = 0; z < zsize; z++)
                                    {
                                        if (TestPartFit(new Vector3Int(freeSpaces[j].x - x, freeSpaces[j].y,
                                                                       freeSpaces[j].z - z), xsize, ysize, zsize))
                                        {
                                            validPositions.Add(new Vector3Int(freeSpaces[j].x - x, freeSpaces[j].y,
                                                                              freeSpaces[j].z - z));
                                        }
                                    }
                                }
                            }
                            break;

                        case 2:
                            if (GridContainsPart(freeSpaces[j].x + 1, freeSpaces[j].y, freeSpaces[j].z))
                            {
                                for (int y = 0; y < ysize; y++)
                                {
                                    for (int z = 0; z < zsize; z++)
                                    {
                                        if (TestPartFit(new Vector3Int(freeSpaces[j].x, freeSpaces[j].y - y,
                                                                       freeSpaces[j].z - z), xsize, ysize, zsize))
                                        {
                                            validPositions.Add(new Vector3Int(freeSpaces[j].x, freeSpaces[j].y - y,
                                                                              freeSpaces[j].z - z));
                                        }
                                    }
                                }
                            }
                            break;

                        case 3:
                            if (GridContainsPart(freeSpaces[j].x - 1, freeSpaces[j].y, freeSpaces[j].z))
                            {
                                for (int y = 0; y < ysize; y++)
                                {
                                    for (int z = 0; z < zsize; z++)
                                    {
                                        if (TestPartFit(new Vector3Int(freeSpaces[j].x, freeSpaces[j].y - y,
                                                                       freeSpaces[j].z - z), xsize, ysize, zsize))
                                        {
                                            validPositions.Add(new Vector3Int(freeSpaces[j].x, freeSpaces[j].y - y,
                                                                              freeSpaces[j].z - z));
                                        }
                                    }
                                }
                            }
                            break;

                        case 4:
                            if (GridContainsPart(freeSpaces[j].x, freeSpaces[j].y, freeSpaces[j].z + 1))
                            {
                                for (int x = 0; x < xsize; x++)
                                {
                                    for (int y = 0; y < ysize; y++)
                                    {
                                        if (TestPartFit(new Vector3Int(freeSpaces[j].x - x, freeSpaces[j].y - y,
                                                                       freeSpaces[j].z), xsize, ysize, zsize))
                                        {
                                            validPositions.Add(new Vector3Int(freeSpaces[j].x - x, freeSpaces[j].y - y,
                                                                              freeSpaces[j].z));
                                        }
                                    }
                                }
                            }
                            break;

                        case 5:
                            if (GridContainsPart(freeSpaces[j].x, freeSpaces[j].y, freeSpaces[j].z - 1))
                            {
                                for (int x = 0; x < xsize; x++)
                                {
                                    for (int y = 0; y < ysize; y++)
                                    {
                                        if (TestPartFit(new Vector3Int(freeSpaces[j].x - x, freeSpaces[j].y - y,
                                                                       freeSpaces[j].z), xsize, ysize, zsize))
                                        {
                                            validPositions.Add(new Vector3Int(freeSpaces[j].x - x, freeSpaces[j].y - y,
                                                                              freeSpaces[j].z));
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }

        if (validPositions.Count > 0)
        {
            score += newBlock.score;
            if (locomotion)
            {
                locomotors += 1;
            }
            resourceManager.MaxFuel += newBlock.storage;
            return(validPositions[Random.Range(0, validPositions.Count)]);
        }
        else
        {
            Debug.Log("No Valid Spaces");
            return(new Vector3Int(0, 0, 0));
        }
    }
예제 #2
0
 public void Work(HousePart housePart, int left, int top)
 {
     Console.SetCursorPosition(left, top);
     Console.WriteLine($"{housePart} is ready.");
 }
예제 #3
0
 public void Work(HousePart housePart, int left, int top)
 {
     housePart.PrintPart(left, top);
 }
예제 #4
0
        static void Main(string[] args)
        {
            House      house      = new House();
            TeamLeader teamLeader = new TeamLeader(house);

            Worker[] workers = new Worker[9] {
                new Worker(),
                new Worker(),
                new Worker(),
                new Worker(),
                new Worker(),
                new Worker(),
                new Worker(),
                new Worker(),
                new Worker()
            }
            ;

            Team team = new Team(teamLeader, workers);

            HousePart[] houseParts = new HousePart[9]
            {
                new Basement(),
                new Door(),
                new Wall(),
                new Wall(),
                new Window(),
                new Window(),
                new Window(),
                new Window(),
                new Roof()
            };
            Console.WriteLine("TeamLeader:");
            Console.WriteLine("We start to build the house!");
            Thread.Sleep(2000);

            Console.Clear();
            Console.SetCursorPosition(28, 0);
            Console.WriteLine("TeamLeader: ");

            int k = 1;

            int l = 0, t = 0;

            for (int i = 0; i < 9; i++)
            {
                if (i == 0)
                {
                    l = 2; t = 10;
                }
                if (i == 1)
                {
                    l = 2; t = 7;
                }
                if (i == 2)
                {
                    l = 2; t = 3;
                }
                if (i == 3)
                {
                    l = 16; t = 3;
                }
                if (i == 4)
                {
                    l = 5; t = 4;
                }
                if (i == 5)
                {
                    l = 10; t = 4;
                }
                if (i == 6)
                {
                    l = 5; t = 6;
                }
                if (i == 7)
                {
                    l = 10; t = 6;
                }
                if (i == 8)
                {
                    l = 2; t = 2;
                }



                Console.SetCursorPosition(30, k);
                Console.WriteLine("Working...");
                k++;
                Thread.Sleep(2000);

                team.Workers[i].Work(houseParts[i], l, t);

                team.Leader.Work(houseParts[i], 30, k);
                Thread.Sleep(2000);
                k++;
            }
        }