Пример #1
0
        public static AModulableRoom BuildModularRoom(RoomType rType, GenericRoom r)
        {
            switch (rType)
            {
            case RoomType.STORAGE:
                return(new StorageRoom(r));

            case RoomType.AIRLOCK:
                if (r == null)
                {
                    return(new AirlockRoom(Vector2Int.zero, 0));
                }
                return(new AirlockRoom(r.GameObject.transform.position, r.Size.x * r.Size.y));

            case RoomType.DEFENSE:
                return(new DefenseRoom());

            case RoomType.FACTORY:
                return(new FactoryRoom(r));

            case RoomType.MINING:
                return(new MiningRoom(r));

            case RoomType.EMPTY:
                return(new EmptyRoom());

            default:
                throw new System.ArgumentException("Can't build modular room of type " + rType, nameof(rType));
            }
        }
Пример #2
0
        public void CombineWithTest()
        {
            string layoutConnect =
                @"........
........
		"        ;
            GenericRoom roomConnect = new GenericRoom(layoutConnect, new MapCoordinates(10, 7), null);
            string      layout1     =
                @"    
....
....";
            GenericRoom room1 = new GenericRoom(layout1, new MapCoordinates(10, 9), null);
            GenericRoom room2 = new GenericRoom(layout1, new MapCoordinates(14, 9), null);

            roomConnect.AddExit(room1, new MapCoordinates(10, 9));
            roomConnect.AddExit(room2, new MapCoordinates(14, 9));
            room1.AddExit(roomConnect, new MapCoordinates(10, 9));
            room2.AddExit(roomConnect, new MapCoordinates(14, 9));
            room1.CombineWith(room2);
            Assert.AreEqual(2, room1.ExitMap.Count);
            Assert.AreEqual(8, room1.Width);
            Assert.AreEqual(3, room1.Height);
            Assert.IsTrue(room1.ExitMap.ContainsKey(new MapCoordinates(10, 9)));
            Assert.IsTrue(room1.ExitMap.ContainsKey(new MapCoordinates(14, 9)));
            Assert.AreSame(roomConnect, room1.ExitMap[new MapCoordinates(10, 9)]);
            Assert.AreSame(roomConnect, room1.ExitMap[new MapCoordinates(14, 9)]);
        }
Пример #3
0
        public void MarkTerrainTest()
        {
            GenericRoom    target      = new GenericRoom(_layout4X2, new MapCoordinates(10, 10), null);
            MapCoordinates mapLocation = new MapCoordinates(10, 10);

            target[mapLocation] = '#';
            Assert.AreEqual('#', target[mapLocation]);
        }
Пример #4
0
 private void putPutinInRoom(GenericRoom instance)
 {
     Transform putinTransform = FindObjectOfType<TurnPutin> ().gameObject.transform;
     Transform playerTransform = GameManager.instance.player.gameObject.transform;
     // Assign putin position
     playerTransform.position = new Vector3 (instance.GetSpawn ().x, 0f, instance.GetSpawn ().z);
     putinTransform.localPosition = new Vector3 (0f, 0f, 0f);
     GameManager.instance.player.GetComponent<Player> ().room = instance;
 }
Пример #5
0
    private void putPutinInRoom(GenericRoom instance)
    {
        Transform putinTransform  = FindObjectOfType <TurnPutin> ().gameObject.transform;
        Transform playerTransform = GameManager.instance.player.gameObject.transform;

        // Assign putin position
        playerTransform.position     = new Vector3(instance.GetSpawn().x, 0f, instance.GetSpawn().z);
        putinTransform.localPosition = new Vector3(0f, 0f, 0f);
        GameManager.instance.player.GetComponent <Player> ().room = instance;
    }
Пример #6
0
        public void GenericRoomConstructorTest()
        {
            string layout =
                @"....
....";

            List <GenericRoom> exits    = null;
            MapCoordinates     location = new MapCoordinates();
            GenericRoom        target   = new GenericRoom(layout, location, exits);

            Assert.AreEqual(2, target.Height);
            Assert.AreEqual(4, target.Width);
        }
Пример #7
0
 public void UpdateRoom(GenericRoom room)
 {
     if (room.RoomType.IsMining())
     {
         var metals = GetMetalsCloseEnough(room.GameObject.transform.position);
         if (metals.Length > 0)
         {
             var mr = (MiningRoom)room.RoomType;
             mr.CurrentMining = metals[0];
             mr.Possibilities = metals;
         }
         _miningRooms.Add(room);
     }
 }
Пример #8
0
 public void UpdateRoom(GenericRoom room)
 {
     if (room.RoomType.IsAirlock())
     {
         var airlock = (AirlockRoom)room.RoomType;
         if (airlock.Emplacements.Any(x => x == null))
         {
             foreach (var sub in _submarines)
             {
                 sub.GetNewAirlock(airlock);
             }
         }
     }
 }
Пример #9
0
 public FactoryRoom(GenericRoom r) : base()
 {
     Stock   = new Resources.ResourceStock(r, ConfigManager.S.Config.FactoryStorageMaxSize);
     Formula = ConfigManager.S.Config.Formulas[0];
     req     = new Requirement(r, Formula.Input.Select(x => new ResourceInfo()
     {
         Type   = x,
         Amount = ConfigManager.S.Config.NbOfResourcePerTransportation
     }).ToArray(), true);
     if (r != null)
     {
         r.Requirement = req;
     }
 }
Пример #10
0
 public MiningRoom(GenericRoom r) : base()
 {
     Stock = new Resources.ResourceStock(r, ConfigManager.S.Config.MiningStorageMaxSize);
 }
Пример #11
0
 public StorageRoom(GenericRoom r) : base()
 {
     Stock = new ResourceStock(r, ConfigManager.S.Config.NormalStorageMaxSize);
 }
Пример #12
0
 public ResourceStock(GenericRoom r, int maxSize)
 {
     Room    = r;
     MaxSize = maxSize;
     ResourcesManager.S.AddStock(this);
 }
Пример #13
0
        private void Update()
        {
            // We want the user to click and release his mouse on the same element
            if (Input.GetMouseButtonDown(0))
            {
                currInfoD = null;
                var mousePos = Input.mousePosition;
                mousePos.z = -Camera.main.transform.position.z;
                var pos   = Camera.main.ScreenToWorldPoint(mousePos);
                var pos2d = (Vector2)pos;
                var room  = MapManager.S.MapRooms.FirstOrDefault((x) =>
                {
                    var xSize = x.Size.x / 2f;
                    return(pos2d.x > x.GameObject.transform.position.x - xSize && pos2d.x < x.GameObject.transform.position.x + xSize &&
                           pos2d.y > x.GameObject.transform.position.y && pos2d.y < x.GameObject.transform.position.y + x.Size.y);
                });
                if (room != null)
                {
                    if (_currentSelection != null && room.IsBuilt) // We want to change the type of a room
                    {
                        clicked = room as GenericRoom;
                        if (clicked != null && !clicked.RoomType.IsEmpty())
                        {
                            clicked = null;
                        }
                    }
                    else // Display info about a room
                    {
                        _roomInfo.Name.text        = room.GetName();
                        _roomInfo.Description.text = room.GetDescription();
                        if (_roomInfo.DetailPanel.transform.childCount > 0)
                        {
                            Destroy(_roomInfo.DetailPanel.transform.GetChild(0).gameObject);
                        }
                        var gRoom = room as GenericRoom;
                        if (gRoom != null || room.IsBuilt)
                        {
                            var p = room.IsBuilt
                                ? gRoom.RoomType.GetDescriptionPanel()
                                : room.GetDescriptionPanel();
                            if (p != null)
                            {
                                var go = Instantiate(p, _roomInfo.DetailPanel.transform);
                                var t  = (RectTransform)go.transform;
                                var pT = (RectTransform)_roomInfo.DetailPanel.transform;
                                t.sizeDelta = Vector2.zero;
                                t.position  = pT.position;
                                if (room.IsBuilt)
                                {
                                    gRoom.RoomType.SetupConfigPanel(go);
                                }
                                else
                                {
                                    room.SetupConfigPanel(go);
                                }
                            }
                        }
                        _roomInfo.gameObject.SetActive(true);
                        currInfoD = gRoom;
                    }
                }
                else if (Input.mousePosition.x < Screen.width - 200 ||
                         Input.mousePosition.y < Screen.height - 300)
                {
                    _roomInfo.gameObject.SetActive(false);
                }
            }
            if (Input.GetMouseButtonUp(0) && clicked != null && clicked.IsBuilt)
            {
                clicked.RoomType = ModularRoomFactory.BuildModularRoom(_currentSelection.Value, clicked);
                int index;
                if (clicked.Size.x == 2)
                {
                    if (clicked.Size.y == 1)
                    {
                        index = 0;
                    }
                    else
                    {
                        index = 1;
                    }
                }
                else
                {
                    if (clicked.Size.y == 1)
                    {
                        index = 2;
                    }
                    else
                    {
                        index = 3;
                    }
                }
                GameObject go;
                if (_currentSelection.Value == RoomType.AIRLOCK)
                {
                    go = PAirlock[index];
                }
                else if (_currentSelection.Value == RoomType.DEFENSE)
                {
                    go = PDefense[index];
                }
                else if (_currentSelection.Value == RoomType.FACTORY)
                {
                    go = PFactory[index];
                }
                else if (_currentSelection.Value == RoomType.MINING)
                {
                    go = PMining[index];
                }
                else if (_currentSelection.Value == RoomType.STORAGE)
                {
                    go = PStorage[index];
                }
                else
                {
                    go = null;
                }

                if (go != null)
                {
                    var n = Instantiate(go, clicked.GameObject.transform.position, Quaternion.Euler(0f, 180f, 0f));
                    Destroy(clicked.GameObject);
                    clicked.GameObject = n;
                }
                EventManager.S.NotifyManager(Events.Event.RoomSetType, clicked);
                clicked = null;
                SetCurrentBuild(-1);
            }
            if (Input.GetMouseButtonDown(1)) // Reset selection
            {
                currInfoD = null;
                if (_currentSelection != null)
                {
                    SetCurrentBuild(-1);
                }
                SubmarineManager.S.RemoveSubmarinePlacementMode();
            }
        }
Пример #14
0
    public void generateLevel()
    {
        int length = map.GetLength(0);

        for (int i = 0; i < length; i++)
        {
            for (int j = 0; j < length; j++)
            {
                if (map[i, j] > 0)
                {
                    Vector3    currentRoomPosition = start + (rightRoom * j) + (bottomRoom * i);
                    GameObject currentRoom         = spawnRoom(map[i, j], currentRoomPosition);

                    //Set room id
                    GenericRoom roomScript = currentRoom.GetComponent <GenericRoom>();
                    roomScript.roomId = "[ " + i + "," + j + " ]";

                    //Set generic room script
                    mapGenericRoom[i, j] = roomScript;

                    //Instantiate links and connect
                    //South Room
                    if (i + 1 < length && map[i + 1, j] > 0)
                    {
                        Vector3    currentLinkPosition = currentRoomPosition + (bottomLink);
                        GameObject currentLink         = Instantiate(linkX, currentLinkPosition, Quaternion.Euler(0, 0, 0));

                        Door door = currentLink.GetComponentInChildren(typeof(Door)) as Door;
                        door.cost = (baseDoorCost * (i + 1) + baseDoorCost * (j + 1));
                        door.id   = "[" + i + "," + j + "]" + " South";
                        door.rooms.Add(roomScript);

                        roomScript.south = door;
                    }
                    else
                    {
                        //Dead End
                        Vector3    currentLinkPosition = currentRoomPosition + (bottomLink);
                        GameObject deadEnd             = Instantiate(endSouth, currentLinkPosition, Quaternion.Euler(0, 0, 0));
                    }

                    //Right Room / East Room
                    //j + 1 < length && map[i, j + 1] == 1
                    if (j + 1 < length && map[i, j + 1] > 0)
                    {
                        Vector3    currentLinkPosition = currentRoomPosition + (rightLink);
                        GameObject currentLink         = Instantiate(link, currentLinkPosition, Quaternion.Euler(0, 0, 0));

                        Door door = currentLink.GetComponentInChildren(typeof(Door)) as Door;
                        door.cost = (baseDoorCost * (i + 1) + baseDoorCost * (j + 1));
                        door.id   = "[" + i + "," + j + "]" + " East";
                        door.rooms.Add(roomScript);

                        roomScript.east = door;
                    }
                    else
                    {
                        Vector3    currentLinkPosition = currentRoomPosition + (rightLink);
                        GameObject deadEnd             = Instantiate(endEast, currentLinkPosition, Quaternion.Euler(0, 0, 0));
                    }

                    //Left Room / West Room
                    if (j - 1 >= 0 && map[i, j - 1] > 0)
                    {
                        //1.Make 2D array of GenericRooms
                        //2.Ask for left room's east door
                        if (mapGenericRoom[i, j - 1] != null)
                        {
                            GenericRoom leftGenericRoom = mapGenericRoom[i, j - 1];

                            roomScript.west = leftGenericRoom.east;

                            roomScript.west.rooms.Add(roomScript);
                        }
                        else
                        {
                            Debug.Log("ERROR. Somehow null but it shouldn't be");
                        }
                    }
                    else
                    {
                        Vector3    currentLinkPosition = currentRoomPosition + (leftLink);
                        GameObject deadEnd             = Instantiate(endWest, currentLinkPosition, Quaternion.Euler(0, 0, 0));
                    }

                    //Top Room / North
                    if (i - 1 >= 0 && map[i - 1, j] > 0)
                    {
                        //Ask for top room's south door
                        if (mapGenericRoom[i - 1, j] != null)
                        {
                            GenericRoom topGenericRoom = mapGenericRoom[i - 1, j];

                            roomScript.north = topGenericRoom.south;

                            roomScript.north.rooms.Add(roomScript);
                        }
                        else
                        {
                            Debug.Log("ERROR. Somehow null but it shouldn't be");
                        }
                    }
                    else
                    {
                        Vector3    currentLinkPosition = currentRoomPosition + (topLink);
                        GameObject deadEnd             = Instantiate(endNorth, currentLinkPosition, Quaternion.Euler(0, 0, 0));
                    }
                }
            }
        }
    }
Пример #15
0
 public ReceptionRoom(GenericRoom r) : base()
 {
     Stock = new Resources.ResourceStock(r, ConfigManager.S.Config.StartingResources.Select(x => x.Amount).Sum());
 }