Example #1
0
        public void FloatConstructor(float x, float y)
        {
            //Arrange

            //Act
            Corner corner = new Corner(1, x, y);

            //Assert
            Assert.IsNotNull(corner);
            Assert.IsInstanceOf(typeof(Corner), corner);
            Assert.AreEqual(1, corner.GetID());
            Assert.AreEqual(x, corner.GetPoint().X);
            Assert.AreEqual(y, corner.GetPoint().Y);
        }
Example #2
0
        /**
         * This method will load all corners from the database for local use.
         * TODO: Only load things for a floor, because otherwise this bloody list will be HUGE.
         */
        public void LoadFromDatabase()
        {
            _corners.Clear();
            _cornerIdDict.Clear();

            const string query = "SELECT * FROM `WallCorners`";
            DataTable data = DatabaseHandler.GetInstance().SelectSQL(query);
            if(data != null) {
                foreach(DataRow row in data.Rows) {
                    uint id = DatabaseUtil.parseInt(row, "ID");
                    Corner corner = new Corner(id, row.Field<float>("X"), row.Field<float>("Y"));
                    corner.IsLoaded = true;

                    this._corners.Add(corner);
                    this._cornerIdDict.Add(corner.GetID(), corner);
                }

                DataTable data_conns = DatabaseHandler.GetInstance().SelectSQL("SELECT * FROM `Wall`");
                if(data_conns != null) {
                    foreach(DataRow row_conns in data_conns.Rows) {
                        uint id = DatabaseUtil.parseInt(row_conns, "ID");
                        bool isDoor = row_conns.Field<bool>("IsDoor");
                        uint hinge = (uint)row_conns.Field<byte>("Hinge");
                        uint direction = (uint)row_conns.Field<byte>("Direction");
                        Corner left = this._cornerIdDict[DatabaseUtil.parseInt(row_conns,"LeftPointID")];
                        Corner right = this._cornerIdDict[DatabaseUtil.parseInt(row_conns,"RightPointID")];

                        if(left != null && right != null) {
                            Wall wall;
                            if(isDoor) wall = new Door(id, left, right, (hinge == 0 ? left : right), (direction == 0 ? Door.HingeDirection.Left : Door.HingeDirection.Right));
                            else wall = new Wall(id, left, right);
                            left.AddWall(wall);
                            right.AddWall(wall);

                            wall.IsLoaded = true;
                            this._walls.Add(wall);
                        }
                    }
                }
            }
        }