private static bool IsPlayerInClose(List <Fence> fences, FenceType type, Farmer player)
        {
            if (fences == null || !fences.Any())
            {
                return(false);
            }
            foreach (Fence fence in fences.Where(f => f != null))
            {
                Vector2 oVec = fence.TileLocation;
                Vector2 pVec = player.getTileLocation();
                if (oVec == pVec)
                {
                    return(true);
                }

                switch (type)
                {
                case FenceType.Vertical when(pVec == oVec + new Vector2(1, 0) || pVec == oVec + new Vector2(-1, 0)):
                case FenceType.Horizontal when(pVec == oVec + new Vector2(0, 1) || pVec == oVec + new Vector2(0, -1)):
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
    /// <summary>
    /// Create an instance of Fence
    /// </summary>
    /// <param name="room">room where it belong</param>
    /// <param name="position">position of fence. ex: room.leftPos.pos</param>
    /// <param name="fenceType">type: may be hor | ver</param>
    private void MakeFence(Room room, Vector3 position, FenceType fenceType)
    {
        // check null
        if (position == null)
        {
            return;
        }

        // get prefab
        GameObject fenceUse = null;

        switch (fenceType)
        {
        case FenceType.Horizontal:
            fenceUse = fenceHorPrefab;
            break;

        case FenceType.Vertical:
            fenceUse = fenceVerPrefab;
            break;
        }

        // error
        if (fenceUse == null)
        {
            Debug.Log("Make fence: no fence Prefab");
            return;
        }

        // instantiate
        Instantiate(fenceUse,
                    position,
                    Quaternion.identity,
                    room.roomObject.transform);
    }
        public static void TryToggleGate(Farmer player)
        {
            GameLocation location = player.currentLocation;

            foreach (Fence fence in Util.GetObjectsWithin <Fence>(2, true).Where(x => x.isGate))
            {
                bool         flag            = false;
                List <Fence> fencesToOperate = new List <Fence> {
                    fence
                };
                FenceType type = GetFenceType(location, fence);
                if (type != FenceType.Invalid)
                {
                    fencesToOperate.Add(GetConnectedGate(location, fence.TileLocation, type));
                    if (IsPlayerInClose(fencesToOperate, type, player) && IsPlayerFaceOrBack(type, player))
                    {
                        flag = true;
                    }
                }
                else if (IsSingleFence(location, fence))
                {
                    if (IsPlayerInClose(fence, player))
                    {
                        flag = true;
                    }
                }
                OperateFences(fencesToOperate, flag);
            }
        }
예제 #4
0
        private FenceType GetFenceTypeByName(string fenceType)
        {
            FenceType getFenceType = TipezeNyumbaUnitOfWork.Repository <FenceType>()
                                     .Get(u => u.typeOfFence.ToLower() == fenceType.ToLower());

            return(getFenceType);
        }
예제 #5
0
        public bool UpdateHouseDetails(int id, HouseModel houseDetails)
        {
            District checkDistrictHouseIsLocated = GetDistrictByName(houseDetails.districtHouseIsLocated);

            if (checkDistrictHouseIsLocated == null)
            {
                return(false);
            }
            LocationsInDistrict checkLocationInDistrict = GetLocationInDistrictByName(checkDistrictHouseIsLocated.districtID, houseDetails.districtHouseIsLocated);

            if (checkLocationInDistrict == null)
            {
                return(false);
            }
            HouseState checkHouseState = GetHouseStatesByName(houseDetails.houseState);

            if (checkHouseState == null)
            {
                return(false);
            }
            FenceType checkFenceType = GetFenceTypeByName(houseDetails.fenceType);

            if (checkFenceType == null)
            {
                return(false);
            }

            House houseToUpdate = TipezeNyumbaUnitOfWork.Repository <House>().Get(u => u.houseID == id);

            if (houseToUpdate == null)
            {
                return(false);
            }
            houseToUpdate.districtHouseIsLocated = checkDistrictHouseIsLocated.districtID;
            houseToUpdate.locationWithInDistrict = checkLocationInDistrict.districtLocationID;
            houseToUpdate.bedrooms                 = houseDetails.bedrooms;
            houseToUpdate.masterBedroomEnsuite     = houseDetails.masterBedroomEnsuite;
            houseToUpdate.selfContained            = houseDetails.selfContained;
            houseToUpdate.numberOfGarages          = houseDetails.numberOfGarages;
            houseToUpdate.fenceType                = checkFenceType.fenceTypeID;
            houseToUpdate.dateHouseWillBeAvailable = Convert.ToDateTime(houseDetails.dateHouseWillBeAvailable);
            houseToUpdate.price             = houseDetails.price;
            houseToUpdate.modeOfPayment     = Convert.ToInt32(houseDetails.modeOfPayment);
            houseToUpdate.dateUploaded      = Convert.ToDateTime(houseDetails.dateUploaded);
            houseToUpdate.description       = houseDetails.description;
            houseToUpdate.currentHouseState = checkHouseState.houseStateID;

            houseToUpdate.HouseContactDetail.phoneNumber1          = houseDetails.phoneNumber1;
            houseToUpdate.HouseContactDetail.phoneNumber2          = houseDetails.phoneNumber2;
            houseToUpdate.HouseContactDetail.whatsAppContactNumber = houseDetails.whatsAppContactNumber;
            houseToUpdate.HouseContactDetail.email = houseDetails.email;

            TipezeNyumbaUnitOfWork.Repository <House>().Attach(houseToUpdate);
            TipezeNyumbaUnitOfWork.SaveChanges();
            return(true);
        }
        private static bool IsPlayerFaceOrBack(FenceType type, Farmer farmer)
        {
            int facing = farmer.FacingDirection;

            if (facing % 2 == 0)
            {
                //Player is facing upside/downside.
                return(type == FenceType.Horizontal);
            }

            return(type == FenceType.Vertical);
        }
예제 #7
0
            /// <summary>
            /// Geofence application sub class.
            /// </summary>
            /// <param name="placeID">the place id</param>
            /// <param name="sender">Specifies the sender of this event</param>
            public SelectFenceTypePage(int placeID, object sender)
            {
                // Set the title of this page
                Title = ((Button)sender).Text;

                // Create a list view
                var listView = new ListView
                {
                    VerticalOptions = LayoutOptions.Center,
                    // Create a list about geofence type
                    ItemsSource = new List <string>()
                    {
                        "GPS", "Wi-Fi", "Bluetooth"
                    },
                };

                // Add a handler for list view
                listView.ItemSelected += async(o, e) =>
                {
                    // Set the selected fence type
                    FenceType type = FenceType.GeoPoint;
                    if (e.SelectedItem.ToString() == "Wi-Fi")
                    {
                        type = FenceType.Wifi;
                    }
                    else if (e.SelectedItem.ToString() == "Bluetooth")
                    {
                        type = FenceType.Bluetooth;
                    }
                    else
                    {
                        type = FenceType.GeoPoint;
                    }

                    // Display a page for inserting information
                    await Navigation.PushAsync(new InsertInfoPage(placeID, type, sender));
                };

                // Create a layout for this page
                Content = new StackLayout
                {
                    Children = { listView },
                    Margin   = 10
                };
            }
예제 #8
0
        /*********
        ** Private methods
        *********/
        /// <summary>Get the equivalent menu item for the specified target. (For example, the inventory item matching a fence object.)</summary>
        /// <param name="item">The target item.</param>
        private Item GetMenuItem(Item item)
        {
            // fence
            if (item is Fence)
            {
                Fence fence = (Fence)item;

                // get equivalent object's sprite ID
                FenceType fenceType = (FenceType)fence.whichType;
                int?      spriteID  = null;
                if (fence.isGate)
                {
                    spriteID = 325;
                }
                else if (fenceType == FenceType.Wood)
                {
                    spriteID = 322;
                }
                else if (fenceType == FenceType.Stone)
                {
                    spriteID = 323;
                }
                else if (fenceType == FenceType.Iron)
                {
                    spriteID = 324;
                }
                else if (fenceType == FenceType.Hardwood)
                {
                    spriteID = 298;
                }

                // get object
                if (spriteID.HasValue)
                {
                    return(new Object(spriteID.Value, 1));
                }
            }

            return(item);
        }
        private static Fence GetConnectedGate(GameLocation location, Vector2 fenceLoc, FenceType type)
        {
            if (type == FenceType.Horizontal)
            {
                if (location.Objects.TryGetValue(fenceLoc + new Vector2(-1, 0), out Object obj) &&
                    obj is Fence fence && fence.isGate)
                {
                    return(fence);
                }
                if (location.Objects.TryGetValue(fenceLoc + new Vector2(1, 0), out obj) &&
                    obj is Fence fence2 && fence2.isGate)
                {
                    return(fence2);
                }
            }
            else if (type == FenceType.Vertical)
            {
                if (location.Objects.TryGetValue(fenceLoc + new Vector2(0, -1), out Object obj2) &&
                    obj2 is Fence fence3 && fence3.isGate)
                {
                    return(fence3);
                }
                if (location.Objects.TryGetValue(fenceLoc + new Vector2(0, 1), out obj2) &&
                    obj2 is Fence fence4 && fence4.isGate)
                {
                    return(fence4);
                }
            }

            return(null);
        }
예제 #10
0
    /// <summary>
    /// Create fence of hallway in particular direction of room
    /// </summary>
    /// <param name="room">input</param>
    /// <param name="nextPos">next location of room on Board, ex: [2,3]</param>
    /// <param name="direction">direction from cur room to next room</param>
    private void MakeHallWayOrFence(Room room, int[] nextPos, Room.Direction direction)
    {
        // check
        if (room == null || nextPos == null)
        {
            return;
        }

        // get variable to use
        FenceType fenceType = FenceType.Horizontal; // default, avoid errors
        Transform roomPos   = null;

        if (direction == Room.Direction.Left)
        {
            roomPos          = room.leftPos;
            fenceType        = FenceType.Vertical;
            room.leftConnect = true;
        }
        if (direction == Room.Direction.Right)
        {
            roomPos           = room.rightPos;
            fenceType         = FenceType.Vertical;
            room.rightConnect = true;
        }
        if (direction == Room.Direction.Up)
        {
            roomPos        = room.upPos;
            fenceType      = FenceType.Horizontal;
            room.upConnect = true;
        }
        if (direction == Room.Direction.Down)
        {
            roomPos          = room.downPos;
            fenceType        = FenceType.Horizontal;
            room.downConnect = true;
        }



        // if next location is valid
        if (isValidLocation(nextPos[0], nextPos[1]))
        {
            if (direction == Room.Direction.Left)
            {
                MakeHallWay(room.leftPos);
                rooms[nextPos[0], nextPos[1]].rightConnect = true;
            }
            if (direction == Room.Direction.Right)
            {
                MakeHallWay(room.rightPos);
                rooms[nextPos[0], nextPos[1]].leftConnect = true;
            }
            if (direction == Room.Direction.Up)
            {
                MakeHallWay(room.upPos);
                rooms[nextPos[0], nextPos[1]].downConnect = true;
            }
            if (direction == Room.Direction.Down)
            {
                MakeHallWay(room.downPos);
                rooms[nextPos[0], nextPos[1]].upConnect = true;
            }
        }

        // if next position is invalid
        else
        {
            MakeFence(room, roomPos.position, fenceType);
        }
    }
예제 #11
0
            /// <summary>
            /// Create the view for InsertInfoPage class.
            /// </summary>
            /// <param name="placeID">the place id</param>
            /// <param name="fenceType">the fence type</param>
            /// <param name="sender">Specifies the sender of this event</param>
            private void CreatePage(int placeID, FenceType fenceType, object sender)
            {
                // Set the title of this page
                Title = ((Button)sender).Text;

                // Create an entry
                var FirstEntry = new Entry
                {
                    BackgroundColor = Color.White,
                    VerticalOptions = LayoutOptions.Center
                };

                // Set the guide text for the entry
                if (sender == ButtonList[0] || sender == ButtonList[6])
                {
                    FirstEntry.Placeholder = "Place Name";
                }
                else if (sender == ButtonList[2])
                {
                    if (fenceType == FenceType.GeoPoint)
                    {
                        FirstEntry.Placeholder = "Latitude";
                    }
                    else
                    {
                        FirstEntry.Placeholder = "BSSID";
                    }
                }

                // Create a second entry
                var SecondEntry = new Entry
                {
                    // Set the guide text
                    Placeholder = "Longitude",
                    // Set the background color
                    BackgroundColor = Color.White,
                    VerticalOptions = LayoutOptions.Center
                };

                // Create a cancel button
                var cancelButton = new Button {
                    Text = "Cancel"
                };

                // Move to the main page when cancel button is selected
                cancelButton.Clicked += async(o, e) => await Navigation.PopToRootAsync();

                // Create a done button
                var doneButton = new Button {
                    Text = "Done"
                };

                // Run the function about inserted information
                doneButton.Clicked += async(o, e) =>
                {
                    try
                    {
                        // Check the value of the first entry
                        if (string.IsNullOrEmpty(FirstEntry.Text))
                        {
                            // Throw an argument exception with message
                            throw new ArgumentException("Content cannot be null or empty");
                        }

                        if (sender == ButtonList[0])
                        {
                            // Add place with inserted name
                            perimeter.AddPlaceName(FirstEntry.Text);
                        }
                        else if (sender == ButtonList[2])
                        {
                            Fence fence = null;
                            switch (fenceType)
                            {
                            case FenceType.GeoPoint:
                                // Check the value of the second entry
                                if (string.IsNullOrEmpty(SecondEntry.Text))
                                {
                                    // Throw an argument exception with message
                                    throw new ArgumentException("Content cannot be null or empty");
                                }

                                // Create a gps fence with inserted information
                                fence = Fence.CreateGPSFence(placeID, double.Parse(FirstEntry.Text), double.Parse(SecondEntry.Text), 100, "TestAddress");
                                break;

                            case FenceType.Wifi:
                                // Create a wifi fence with inserted information
                                fence = Fence.CreateWifiFence(placeID, FirstEntry.Text, "TestAddress");
                                break;

                            case FenceType.Bluetooth:
                                // Create a bt fence with inserted information
                                fence = Fence.CreateBTFence(placeID, FirstEntry.Text, "TestAddress");
                                break;

                            default:
                                break;
                            }

                            if (fence != null)
                            {
                                // Add the fence
                                perimeter.AddGeofence(fence);
                            }
                        }
                        else if (sender == ButtonList[6])
                        {
                            // Update the place name
                            perimeter.UpdatePlace(placeID, FirstEntry.Text);
                        }
                    }
                    catch (Exception exception)
                    {
                        // Display the exception message
                        await DisplayAlert("Alert", exception.Message, "OK");
                    }

                    // Move to the main page
                    await Navigation.PopToRootAsync();
                };

                // Create a layout for buttons
                var ButtonGridLayout = new Grid
                {
                    RowDefinitions =
                    {
                        new RowDefinition {
                            Height = GridLength.Star
                        },
                    },
                    ColumnDefinitions =
                    {
                        new ColumnDefinition {
                            Width = GridLength.Star
                        },
                        new ColumnDefinition {
                            Width = GridLength.Star
                        },
                    },
                    VerticalOptions = LayoutOptions.End
                };

                ButtonGridLayout.Children.Add(cancelButton, 0, 0);
                ButtonGridLayout.Children.Add(doneButton, 1, 0);

                // Create a layout for this page
                StackLayout parent = new StackLayout
                {
                    Margin = 10
                };

                parent.Children.Add(FirstEntry);
                if (sender == ButtonList[2] && fenceType == FenceType.GeoPoint)
                {
                    parent.Children.Add(SecondEntry);
                }

                parent.Children.Add(ButtonGridLayout);

                Content = parent;
            }
예제 #12
0
 /// <summary>
 /// Constructor of InsertInfoPage class.
 /// </summary>
 /// <param name="placeID">the place id</param>
 /// <param name="fenceType">the fence type</param>
 /// <param name="sender">Specifies the sender of this event</param>
 public InsertInfoPage(int placeID, FenceType fenceType, object sender)
 {
     CreatePage(placeID, fenceType, sender);
 }
예제 #13
0
 internal static extern int FenceType(IntPtr handle, out FenceType type);
예제 #14
0
        public bool AddHouse(HouseModel newHouseModel)
        {
            District checkDistrictHouseIsLocated = GetDistrictByName(newHouseModel.districtHouseIsLocated);

            if (checkDistrictHouseIsLocated == null)
            {
                return(false);
            }
            LocationsInDistrict checkLocationInDistrict = GetLocationInDistrictByName(checkDistrictHouseIsLocated.districtID, newHouseModel.locationInDistrict);

            if (checkLocationInDistrict == null)
            {
                return(false);
            }
            HouseState checkHouseState = GetHouseStatesByName(newHouseModel.houseState);

            if (checkHouseState == null)
            {
                return(false);
            }
            FenceType checkFenceType = GetFenceTypeByName(newHouseModel.fenceType);

            if (checkFenceType == null)
            {
                return(false);
            }
            int activatedState = _fieldStateManagement.GetActivatedState().fieldStateID;

            House newHouse = new House()
            {
                districtHouseIsLocated = checkDistrictHouseIsLocated.districtID,
                locationWithInDistrict = checkLocationInDistrict.districtLocationID,
                bedrooms                 = newHouseModel.bedrooms,
                masterBedroomEnsuite     = newHouseModel.masterBedroomEnsuite,
                selfContained            = newHouseModel.selfContained,
                numberOfGarages          = newHouseModel.numberOfGarages,
                fenceType                = checkFenceType.fenceTypeID,
                dateHouseWillBeAvailable = Convert.ToDateTime(newHouseModel.dateHouseWillBeAvailable),
                price             = newHouseModel.price,
                modeOfPayment     = Convert.ToInt32(newHouseModel.modeOfPayment),
                dateUploaded      = DateTime.Now,
                description       = newHouseModel.description,
                currentHouseState = checkHouseState.houseStateID,
                state             = activatedState
            };

            HouseContactDetail houseContactDetail = new HouseContactDetail()
            {
                houseID               = newHouse.houseID,
                phoneNumber1          = newHouseModel.phoneNumber1,
                phoneNumber2          = newHouseModel.phoneNumber2,
                whatsAppContactNumber = newHouseModel.whatsAppContactNumber,
                email = newHouseModel.email,
                state = activatedState
            };


            HouseOwner setHouseOwner = new HouseOwner()
            {
                userID  = newHouseModel.userId,
                houseID = newHouseModel.houseID,
                status  = activatedState
            };

            TipezeNyumbaUnitOfWork.Repository <House>().Add(newHouse);
            TipezeNyumbaUnitOfWork.Repository <HouseContactDetail>().Add(houseContactDetail);
            TipezeNyumbaUnitOfWork.Repository <HouseOwner>().Add(setHouseOwner);
            TipezeNyumbaUnitOfWork.SaveChanges();
            return(true);
        }