コード例 #1
0
    public void CreateStage()
    {
        //establish stage with data,todo

        //testing
        GameObject _stage = new GameObject("stage");

        for (int i = 0; i < m_Size.d_nWidth; i++)
        {
            for (int j = 0; j < m_Size.d_nHeight; j++)
            {
                DCell _tmp = m_Data[i + j * m_Size.d_nWidth];
                if (_tmp != null)
                {
                    GameObject _obj;
                    if (_tmp.d_bIsWall)
                    {
                        _obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    }
                    else if (_tmp.d_bIsDoor)
                    {
                        _obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    }
                    else
                    {
                        //_obj = GameObject.CreatePrimitive(PrimitiveType.Capsule);
                        continue;
                    }
                    _obj.transform.position = new Vector3(i * DCell.CELL_BORDER_LENGTH, 0.0f, j * DCell.CELL_BORDER_LENGTH);
                    _obj.transform.parent   = _stage.transform;
                }
            }
        }
    }
コード例 #2
0
        public void AddCell(DCell cell)
        {
            ListCells.Add(cell);

            Cells[cell.Row, cell.Column] = cell;

            cell.Parent = GUI;
        }
        private void AddLessonIndex(int startColumn, int numberofCell)
        {
            for (var i = 0; i < numberofCell; i++)
            {
                var columnIndex  = startColumn + i;
                var lessonHeader = new DCell(1, columnIndex, 1, 1);
                lessonHeader.BackgroundContent = (i + 1).ToString();

                TimeTableContext.AddCell(lessonHeader);
            }
        }
 /// <summary>
 /// InsertBackgroudForAllTimeItems
 /// </summary>
 private void InsertBackgroudForAllTimeItems()
 {
     // row form 2 to end
     for (var i = 2; i < TimeTableContext.Rows.Count; i++)
     {
         // column from 1 to end
         for (var j = 1; j < TimeTableContext.Columns.Count; j++)
         {
             var contentCell = new DCell(i, j, 1, 1);
             contentCell.BackgroundContent = "";
             TimeTableContext.AddCell(contentCell);
         }
     }
 }
コード例 #5
0
        // METHODS
        public override bool Search()
        {
            this.Clear();
            this.openSet.Add(new DCell(start));
            // while there are known cells ...
            while (openSet.Count != 0)
            {
                // ... get cell with shortest way
                DCell current = openSet.Min();

                // if it is goal...
                if (current.Cell == goal)
                {
                    // ... the path has been found
                    lastPos = current.Cell;
                    return(true);
                }
                // handle neighbours
                foreach (Cell neighbour in maze.GetNeighbours(current.Cell, (cell) => cell.Type != CellType.Visited))
                {
                    double WayFromStartToThisNeighbour = current.ShortestWay + 1;

                    DCell aNeighbourInOpen = openSet.FirstOrDefault(dcell => dcell.Cell == neighbour);

                    if (aNeighbourInOpen == null || aNeighbourInOpen.ShortestWay > WayFromStartToThisNeighbour)
                    {
                        aNeighbourInOpen = aNeighbourInOpen ?? new DCell(neighbour); // create if needed
                        openSet.Add(aNeighbourInOpen);                               // add if needed

                        // update values
                        aNeighbourInOpen.ShortestWay   = WayFromStartToThisNeighbour;
                        aNeighbourInOpen.Cell.Previous = current.Cell;
                    }
                    aNeighbourInOpen.Cell.Type = CellType.Current;
                    System.Threading.Thread.Sleep(delay);
                }

                // move cell from OpenSet to ClosedSet
                current.Cell.Type = CellType.Visited;
                openSet.Remove(current);
                closedSet.Add(current.Cell);
            }
            // no valid path
            return(false);
        }
コード例 #6
0
    //todo
    public static Stage NewMap(int times)
    {
        Clear();
        //Random pick a **start** room and register it;
        DRoom _room = RoomPresetsManager.GetInstance().RandomPicking().GetRoomInfo();

        //DRoom _room = RoomPresetsManager.GetInstance().GetPreset(0).GetRoomInfo();
        RegisterNewRoom(_room, _room.d_DoorList.First.Value, new DPointN(0, 0));

        for (int i = 0; i < times; i++)
        {
            AddNewRoom();
            if (m_OpeningDoorList.Count == 0)
            {
                Debug.Log(i);
                break;
            }
        }


        //make map

        Rect  _rct   = GetMapRect();
        Stage _stage = new Stage((int)_rct.width, (int)_rct.height);

        foreach (DSavedRoom _svroom in m_RoomList)
        {
            DRoomPreset _preset = RoomPresetsManager.GetInstance().GetPreset(_svroom.d_ID);
            if (_preset == null)
            {
                continue;
            }

            int _x = (int)_svroom.d_Rect.x - (int)_rct.x;
            int _y = (int)_svroom.d_Rect.y - (int)_rct.y;
            int _w = (int)_svroom.d_Rect.width + 1;
            int _h = (int)_svroom.d_Rect.height + 1;

            for (int i = 0; i < _w; i++)
            {
                for (int j = 0; j < _h; j++)
                {
                    int _mapPos    = (_x + i) + (_y + j) * (int)_rct.width;
                    int _presetPos = i + j * _w;

                    DCell _cell = _preset.d_Data[_presetPos];
                    if (_cell.d_bIsDoor)
                    {
                        _stage.GetMap()[_mapPos] = new DCell(0, false, true, false);
                    }
                    else
                    {
                        _stage.GetMap()[_mapPos] = _cell;
                    }
                }
            }
        }
        //Add ClosedDoors to data
        foreach (DDoor _door in m_ClosedDoorList)
        {
            int _x      = _door.d_ptGlobalPos.x - (int)_rct.x;
            int _y      = _door.d_ptGlobalPos.y - (int)_rct.y;
            int _mapPos = _x + _y * (int)_rct.width;
            _stage.GetMap()[_mapPos] = new DCell(0, true, false, false);//get data from DDoor?todo
        }

        return(_stage);
    }
コード例 #7
0
ファイル: luatest.cs プロジェクト: lozzmki/ZProject
    // Use this for initialization
    void Start()
    {
        //         GameObject obj = new GameObject("ItemPattern");
        //         obj.AddComponent<Item>();
        //         obj.GetComponent<Item>().m_LuaScript = "ItemRangePattern";
        //         _dic = ObjectManager.getInstance().addObject(obj);
        //
        //
        //         GameObject oobj = new GameObject("ItemPattern2");
        //         oobj.AddComponent<Item>();
        //         oobj.GetComponent<Item>().m_LuaScript = "ItemMeleePattern";
        //         _dic2 = ObjectManager.getInstance().addObject(oobj);

        //Debug.Log(Resources.Load("Meshes/Shell"));

        GameObject _obj = ObjectDictionary.GetItemDic().CreateObject("ItemRangePattern",
                                                                     gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                                     Quaternion.AngleAxis(0, Vector3.up));

        ObjectDictionary.GetItemDic().CreateObject("ItemRangePattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));

        ObjectDictionary.GetItemDic().CreateObject("ItemPartsPattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("CubeAmmo",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("ItemPartsPattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("CubeAmmo",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("ItemPartsPattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("CubeAmmo",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));


        //map test
        DCell W = new DCell(0, false, true, false);
        DCell R = new DCell();
        DCell D = new DCell(0, true, false);

        DRoomPreset _room1 = new DRoomPreset();

        _room1.d_Size = new DSizeN(7, 7);
        _room1.d_Data = new DCell[]
        {
            W, W, W, D, W, W, W,
            W, R, R, R, R, R, W,
            W, R, R, R, R, R, W,
            D, R, R, R, R, R, D,
            W, R, R, R, R, R, W,
            W, R, R, R, R, R, W,
            W, W, W, D, W, W, W,
        };

        DRoomPreset _room2 = new DRoomPreset();

        _room2.d_Size = new DSizeN(5, 13);
        _room2.d_Data = new DCell[]
        {
            W, W, W, D, W,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            D, R, R, R, W,
            W, R, R, R, D,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            D, R, R, R, W,
            W, W, D, W, W,
        };

        DRoomPreset _room3 = new DRoomPreset();

        _room3.d_Size = new DSizeN(13, 5);
        _room3.d_Data = new DCell[]
        {
            W, W, D, W, W, W, W, W, D, W, W, W, W,
            W, R, R, R, R, R, R, R, R, R, R, R, W,
            W, R, R, R, R, R, R, R, R, R, R, R, W,
            D, R, R, R, R, R, R, R, R, R, R, R, D,
            W, W, W, W, W, D, W, W, W, W, W, D, W,
        };

        //RoomPresetsManager.GetInstance().AddPreset(_room1);
        //RoomPresetsManager.GetInstance().AddPreset(_room2);
        //RoomPresetsManager.GetInstance().AddPreset(_room3);
        //test
        RoomPresetsManager.GetInstance().AddPreset(mapEditor.Output.GetPresetByMap("C:/Users/FLYPLUSSS/Desktop/ZProject-dev/maps/7x7.txt"));

        Stage _stage = MapGenerator.NewMap(100);

        _stage.CreateStage();


        GameObject go = new GameObject("aaa");

        go.AddComponent(typeof(ttest));
        go.GetComponent <ttest>().tc    = new testClass();
        go.GetComponent <ttest>().tc.aa = 10;
        go.GetComponent <ttest>().tc.bb = 10;
        GameObject go2 = Instantiate(go);

        go.GetComponent <ttest>().tc.aa = 20;
        go.GetComponent <ttest>().tc.bb = 20;
        GameObject go3 = Instantiate(go);

        go.GetComponent <ttest>().tc.aa = 30;
        go.GetComponent <ttest>().tc.bb = 30;

        Debug.Log(go.GetComponent <ttest>().tc.aa);
        Debug.Log(go.GetComponent <ttest>().tc.bb);
        Debug.Log(go2.GetComponent <ttest>().tc.aa);
        Debug.Log(go2.GetComponent <ttest>().tc.bb);
        Debug.Log(go3.GetComponent <ttest>().tc.aa);
        Debug.Log(go3.GetComponent <ttest>().tc.bb);
    }
コード例 #8
0
ファイル: Output.cs プロジェクト: lozzmki/ZProject
        public static DRoomPreset GetPresetByMap(string filename)
        {
            FileStream   fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);

            //var map = GameObject.Find("CellContainer").GetComponent<CellManager>();


            int width  = br.ReadInt32();
            int height = br.ReadInt32();

            //map.RegenerateMap_Editor(width, height);
            DRoomPreset rlsPreset = new DRoomPreset(width, height);

            SCENEOBJ_TYPE[,] objmap = new SCENEOBJ_TYPE[width, height];
            int[,] texMap           = new int[width, height];

            Debug.Log(width + " , " + height);
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    var mat_id = br.ReadInt32();
                    texMap[i, j] = mat_id;
                    Debug.Log(mat_id);
                    //map.getCell(new Vector2(i, j)).GetComponent<Cell>().ChangeFoorMat(mat_id);
                }
            }

            var objLength = br.ReadInt32();

            for (int i = 0; i < objLength; i++)
            {
                var mapx     = br.ReadInt32();
                var mapy     = br.ReadInt32();
                var rotateId = br.ReadInt32();
                var name     = br.ReadString();
                Debug.Log(mapx + " , " + mapy + "ROTATE :" + rotateId + " NAME:" + name);
                objmap[mapx, mapy] = NameToSceneObj(name);
                //map.getCell(new Vector2(mapx, mapy)).GetComponent<Cell>().BuildBox(
                //   GameObject.Find("GameStone").GetComponent<ResrouceManager>().NameToSceneObj(name));
                //map.getCell(new Vector2(mapx, mapy)).GetComponent<Cell>().GetBuilding.GetObjRotate = rotateId;
            }
            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    DCell cell = new DCell(texMap[w, h]);
                    if (objmap[w, h] == SCENEOBJ_TYPE.DOOR0)
                    {
                        cell.d_bIsDoor = true;
                    }
                    if (objmap[w, h] == SCENEOBJ_TYPE.WALL_1 || objmap[w, h] == SCENEOBJ_TYPE.WALL_CORNER_1)
                    {
                        cell.d_bIsWall = true;
                    }
                    rlsPreset.d_Data[h * width + w] = cell;
                }
            }
            fs.Close();
            br.Close();
            return(rlsPreset);
        }
        /// <summary>
        /// InitalizeTimeTableContext
        /// </summary>
        private void InitalizeTimeTableContext()
        {
            TimeTableContext = new DContext();

            // Create List Columns
            TimeTableContext.Columns = new ObservableCollection <DColumn>
            {
            };

            // Add Label Column
            DColumn labelColum = new DColumn {
                Width = 20
            };

            TimeTableContext.Columns.Add(labelColum);

            // Add 7x12 column for content
            for (var i = 0; i < 84; i++)
            {
                var contentColumn = new DColumn()
                {
                    Width = 30
                };
                TimeTableContext.Columns.Add(contentColumn);
            }

            TimeTableContext.Rows = new ObservableCollection <DRow>()
            {
            };
            // Add row for Day
            var dayRow = new DRow()
            {
                Height = 20
            };

            TimeTableContext.Rows.Add(dayRow);
            // Add row for index
            var indexRow = new DRow()
            {
                Height = 15
            };

            TimeTableContext.Rows.Add(indexRow);

            // Add 50 content Row
            for (var i = 0; i < 50; i++)
            {
                var contentRow = new DRow()
                {
                    Height = 30
                };
                TimeTableContext.Rows.Add(contentRow);
            }

            // Add Monday
            var mondayCell = new DCell(0, 1, 1, 12);

            mondayCell.BackgroundContent = "Monday";
            mondayCell.UIContent         = new lessonView();

            TimeTableContext.AddCell(mondayCell);
            AddLessonIndex(1, 12);

            // Add Tuesday
            var tuesdayCell = new DCell(0, 13, 1, 12);

            tuesdayCell.BackgroundContent = "Tuesday";
            TimeTableContext.AddCell(tuesdayCell);
            AddLessonIndex(13, 12);
            // Add Wednesday
            var wednesDayCell = new DCell(0, 25, 1, 12);

            wednesDayCell.BackgroundContent = "Wesnesday";
            TimeTableContext.AddCell(wednesDayCell);
            AddLessonIndex(25, 12);


            // Add Thursday
            var thursdayCell = new DCell(0, 37, 1, 12);

            thursdayCell.BackgroundContent = "Thursday";
            TimeTableContext.AddCell(thursdayCell);
            AddLessonIndex(37, 12);

            // Add Friday
            var fridayCell = new DCell(0, 49, 1, 12);

            fridayCell.BackgroundContent = "Friday";
            TimeTableContext.AddCell(fridayCell);
            AddLessonIndex(49, 12);

            // Add Saturday
            var saturdayCell = new DCell(0, 61, 1, 12);

            saturdayCell.BackgroundContent = "Saturday";
            TimeTableContext.AddCell(saturdayCell);
            AddLessonIndex(61, 12);

            // Add Sunday
            var sundayCell = new DCell(0, 73, 1, 12);

            sundayCell.BackgroundContent = "Sunday";
            TimeTableContext.AddCell(sundayCell);
            AddLessonIndex(73, 12);

            //var dumyCell = new DCell(1, 1, 1, 1);

            //TimeTableContext.AddCell(dumyCell);
            // InsertBackgroudForAllTimeItems
            InsertBackgroudForAllTimeItems();
        }
コード例 #10
0
    // Use this for initialization
    void Start()
    {
        //         GameObject obj = new GameObject("ItemPattern");
        //         obj.AddComponent<Item>();
        //         obj.GetComponent<Item>().m_LuaScript = "ItemRangePattern";
        //         _dic = ObjectManager.getInstance().addObject(obj);
        //
        //
        //         GameObject oobj = new GameObject("ItemPattern2");
        //         oobj.AddComponent<Item>();
        //         oobj.GetComponent<Item>().m_LuaScript = "ItemMeleePattern";
        //         _dic2 = ObjectManager.getInstance().addObject(oobj);

        //Debug.Log(Resources.Load("Meshes/Shell"));

        ObjectDictionary.GetItemDic().CreateObject("ItemRangePattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));

        ObjectDictionary.GetItemDic().CreateObject("ItemPartsPattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("CubeAmmo",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("ItemPartsPattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("CubeAmmo",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("ItemPartsPattern",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));
        ObjectDictionary.GetItemDic().CreateObject("CubeAmmo",
                                                   gameObject.transform.position + new Vector3(5.0f * Random.value, 0.0f, 5.0f * Random.value),
                                                   Quaternion.AngleAxis(0, Vector3.up));


        //map test
        DCell W = new DCell(0, false, true, false);
        DCell R = new DCell();
        DCell D = new DCell(0, true, false);

        DRoomPreset _room1 = new DRoomPreset();

        _room1.d_Size = new DSizeN(7, 7);
        _room1.d_Data = new DCell[]
        {
            W, W, W, D, W, W, W,
            W, R, R, R, R, R, W,
            W, R, R, R, R, R, W,
            D, R, R, R, R, R, D,
            W, R, R, R, R, R, W,
            W, R, R, R, R, R, W,
            W, W, W, D, W, W, W,
        };

        DRoomPreset _room2 = new DRoomPreset();

        _room2.d_Size = new DSizeN(5, 13);
        _room2.d_Data = new DCell[]
        {
            W, W, W, D, W,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            D, R, R, R, W,
            W, R, R, R, D,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            W, R, R, R, W,
            D, R, R, R, W,
            W, W, D, W, W,
        };

        DRoomPreset _room3 = new DRoomPreset();

        _room3.d_Size = new DSizeN(13, 5);
        _room3.d_Data = new DCell[]
        {
            W, W, D, W, W, W, W, W, D, W, W, W, W,
            W, R, R, R, R, R, R, R, R, R, R, R, W,
            W, R, R, R, R, R, R, R, R, R, R, R, W,
            D, R, R, R, R, R, R, R, R, R, R, R, D,
            W, W, W, W, W, D, W, W, W, W, W, D, W,
        };

        RoomPresetsManager.GetInstance().AddPreset(_room1);
        RoomPresetsManager.GetInstance().AddPreset(_room2);
        RoomPresetsManager.GetInstance().AddPreset(_room3);

        Stage _stage = MapGenerator.NewMap(100);

        _stage.CreateStage();
    }