예제 #1
0
        /// <summary>
        /// Edits a new user depending if the uderID already exists
        /// </summary>
        /// <param name="user">the user that is being added</param>
        /// <param name="sector">the sector that is being added</param>
        /// <returns>a new user</returns>
        public tblUser AddUser(tblUser user, tblSector sector)
        {
            InputCalculator iv = new InputCalculator();

            try
            {
                using (WorkerContext context = new WorkerContext())
                {
                    if (user.UserID == 0)
                    {
                        user.DateOfBirth = iv.CountDateOfBirth(user.JMBG);

                        tblUser newUser = new tblUser();
                        newUser.FirstName   = user.FirstName;
                        newUser.LastName    = user.LastName;
                        newUser.JMBG        = user.JMBG;
                        newUser.IDCard      = user.IDCard;
                        newUser.DateOfBirth = user.DateOfBirth;
                        newUser.Gender      = user.Gender;
                        newUser.PhoneNumber = user.PhoneNumber;
                        newUser.SectorID    = sector.SectorID;
                        newUser.LocationID  = user.LocationID;
                        newUser.MenagerID   = user.MenagerID;

                        context.tblUsers.Add(newUser);
                        context.SaveChanges();
                        user.UserID = newUser.UserID;

                        return(user);
                    }
                    else
                    {
                        tblUser usersToEdit = (from ss in context.tblUsers where ss.UserID == user.UserID select ss).First();
                        // Get the date of birth
                        user.DateOfBirth = iv.CountDateOfBirth(user.JMBG);

                        usersToEdit.FirstName   = user.FirstName;
                        usersToEdit.LastName    = user.LastName;
                        usersToEdit.JMBG        = user.JMBG;
                        usersToEdit.IDCard      = user.IDCard;
                        usersToEdit.DateOfBirth = user.DateOfBirth;
                        usersToEdit.Gender      = user.Gender;
                        usersToEdit.PhoneNumber = user.PhoneNumber;
                        usersToEdit.SectorID    = sector.SectorID;
                        usersToEdit.LocationID  = user.LocationID;
                        usersToEdit.MenagerID   = user.MenagerID;
                        usersToEdit.UserID      = user.UserID;

                        context.SaveChanges();
                        return(user);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
    void Init()
    {
        GameObject gameManager = GameObject.Find("GameManager");

        if (gameManager)
        {
            inputCalculator = gameManager.GetComponent <InputCalculator>();
        }
    }
예제 #3
0
        static void RunInputCalculator()
        {
            var inputCalculator = new InputCalculator();

            machineModifier = 0.0m;
            do
            {
                var result = PrintInputMessage("Recipe Time");
                if (decimal.TryParse(result, out decimal value))
                {
                    inputCalculator.RecipeTime = value;
                }
                else
                {
                    Console.WriteLine("Invalid Value");
                }
            } while (inputCalculator.RecipeTime == 0.0m);

            do
            {
                Console.WriteLine("Build Modifier:");
                _inputCalcualtorMenu.Display();
                inputCalculator.MachineModifier = machineModifier;
            } while (inputCalculator.MachineModifier == 0.0m);

            do
            {
                var result = PrintInputMessage("Belt Speed");
                if (int.TryParse(result, out int value))
                {
                    inputCalculator.BeltSpeed = value;
                }
                else
                {
                    Console.WriteLine("Invalid Value");
                }
            } while (inputCalculator.BeltSpeed == 0);

            do
            {
                var result = PrintInputMessage("Input Amount");
                if (int.TryParse(result, out int value))
                {
                    inputCalculator.InputAmount = value;
                }
                else
                {
                    Console.WriteLine("Invalid Value");
                }
            } while (inputCalculator.InputAmount == 0);

            Console.WriteLine($"The number of machines needed is {inputCalculator.CalculateMachinesNeeded()}");

            ReShowMenu();
        }
        public void given_a_belt_speed_of_1800_and_a_recipetime_of_6_seconds_and_an_input_of_10_and_a_modifier_of_1_5_when_calculated_the_result_is_12()
        {
            var inputCalculator = new InputCalculator();

            inputCalculator.InputAmount     = 10;
            inputCalculator.MachineModifier = 1.5m;
            inputCalculator.RecipeTime      = 6;
            inputCalculator.BeltSpeed       = 1800;

            var result = inputCalculator.CalculateMachinesNeeded();

            Assert.IsTrue(result == 12m);
        }
예제 #5
0
        public void CalculatorDoesBasicCalculations()
        {
            InputCalculator calculator = new InputCalculator("2 3");

            Assert.AreEqual(calculator.Calculate(), 5);

            calculator = new InputCalculator("* 2 3");
            Assert.AreEqual(calculator.Calculate(), 6);

            calculator = new InputCalculator("- 2 3");
            Assert.AreEqual(calculator.Calculate(), -5);

            calculator = new InputCalculator("/ 6 2");
            Assert.AreEqual(calculator.Calculate(), 3);
        }
        /// <summary>
        /// Creates or edits a report
        /// </summary>
        /// <param name="report">the report that is being added</param>
        /// <returns>a new or edited report</returns>
        public vwUserReport AddReport(vwUserReport report)
        {
            InputCalculator iv = new InputCalculator();

            try
            {
                using (ReportDBEntities context = new ReportDBEntities())
                {
                    if (report.ReportID == 0)
                    {
                        tblReport newReport = new tblReport
                        {
                            Project     = report.Project,
                            ReportDate  = report.ReportDate,
                            ReportHours = report.ReportHours,
                            UserID      = Service.LoggedInUser[0].UserID
                        };

                        context.tblReports.Add(newReport);
                        context.SaveChanges();
                        report.ReportID = newReport.ReportID;
                        return(report);
                    }
                    else
                    {
                        tblReport reportToEdit = (from ss in context.tblReports where ss.ReportID == report.ReportID select ss).First();

                        reportToEdit.Project     = report.Project;
                        reportToEdit.ReportDate  = report.ReportDate;
                        reportToEdit.ReportHours = report.ReportHours;
                        reportToEdit.UserID      = report.UserID;

                        reportToEdit.ReportID = report.ReportID;

                        tblReport reportEdit = (from ss in context.tblReports
                                                where ss.ReportID == report.ReportID
                                                select ss).First();
                        context.SaveChanges();
                        return(report);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
예제 #7
0
        /// <summary>
        /// Calcualtes the birth date and places it in the textbox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TextBox_TextChanged(object sender, EventArgs e)
        {
            InputCalculator iv   = new InputCalculator();
            string          text = "";

            if (txtJMBG.Text.Length >= 7)
            {
                text = iv.CountDateOfBirth(txtJMBG.Text).ToString("dd.MM.yyy.");
            }
            else
            {
                text = "";
            }

            txtDateOfBirth.Text = text;
        }
예제 #8
0
        public void OperatorStateChangesBasedOnInput()
        {
            InputCalculator calculator = new InputCalculator("-");

            calculator.Calculate();
            Assert.AreEqual(new Subtract().GetType(), calculator.currentState.GetType());
            calculator = new InputCalculator("+");
            calculator.Calculate();
            Assert.AreEqual(new Add().GetType(), calculator.currentState.GetType());
            calculator = new InputCalculator("*");
            calculator.Calculate();
            Assert.AreEqual(new Multiply().GetType(), calculator.currentState.GetType());
            calculator = new InputCalculator("/");
            calculator.Calculate();
            Assert.AreEqual(new Divide().GetType(), calculator.currentState.GetType());
        }
        /// <summary>
        /// Deletes user, users records and identification card depending if the uderID already exists
        /// </summary>
        /// <param name="userID">the user that is being deleted</param>
        /// <returns>list of users</returns>
        public void DeleteWorker(int userID)
        {
            InputCalculator  iv         = new InputCalculator();
            List <tblReport> AllReports = GetAllReports();

            try
            {
                using (ReportDBEntities context = new ReportDBEntities())
                {
                    bool isUser = IsUserID(userID);
                    // Delete are evidences from the user
                    for (int i = 0; i < AllReports.Count; i++)
                    {
                        if (AllReports[i].UserID == userID)
                        {
                            tblReport report = (from r in context.tblReports where r.UserID == userID select r).First();
                            context.tblReports.Remove(report);
                            context.SaveChanges();
                        }
                    }
                    if (isUser == true)
                    {
                        // find the user and identification card before removing them
                        tblUser userToDelete = (from r in context.tblUsers where r.UserID == userID select r).First();

                        context.tblUsers.Remove(userToDelete);
                        context.SaveChanges();
                    }
                    else
                    {
                        MessageBox.Show("Cannot delete the user");
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
            }
        }
예제 #10
0
    // Start is called before the first frame update
    void Start()
    {
        inputs            = GameObject.Find("GameManager").GetComponent <InputManager>();
        inputCalculator   = GameObject.Find("GameManager").GetComponent <InputCalculator>();
        jumpParticles     = GameObject.Find("JumpParticles").GetComponent <ParticleSystem>();
        rocketParticles   = GameObject.Find("RocketParticles").GetComponent <ParticleSystem>();
        smokeParticles    = GameObject.Find("SmokeParticles").GetComponent <ParticleSystem>();
        playerAudioSource = GameObject.Find("PlayerAudio").GetComponent <AudioSource>();
        if (GameObject.Find("PersistentDataManager"))
        {
            persistentDataManager = GameObject.Find("PersistentDataManager").GetComponent <PersistentDataManager>();
        }
        rigidbody = GetComponent <Rigidbody2D>();
        animator  = GetComponent <Animator>();

        velocity            = new Vector2(0, 0);
        maxSpeedReducer     = maxSpeed * 0.1f;
        accelerationReducer = acceleration * 0.001f; // We reduce the velocity and traction by this multiplier to keep the public numbers simple
        tractionReducer     = traction * 0.001f;
        jumpReducer         = jumpPower * 0.1f;
        gravityReducer      = gravity * 0.01f;
    }
        /// <summary>
        /// Creates or edits a manager
        /// </summary>
        /// <param name="manager">the manager that is esing added</param>
        /// <returns>a new or edited manager</returns>
        public vwManager AddManager(vwManager manager)
        {
            InputCalculator iv = new InputCalculator();

            try
            {
                using (ReportDBEntities context = new ReportDBEntities())
                {
                    if (manager.UserID == 0)
                    {
                        manager.DateOfBirth = iv.CountDateOfBirth(manager.JMBG);

                        tblUser newManager = new tblUser
                        {
                            FirstName    = manager.FirstName,
                            LastName     = manager.LastName,
                            JMBG         = manager.JMBG,
                            DateOfBirth  = manager.DateOfBirth,
                            BankAccount  = manager.BankAccount,
                            Email        = manager.Email,
                            Position     = manager.Position,
                            Salary       = manager.Salary,
                            Username     = manager.Username,
                            UserPassword = manager.UserPassword,
                            Sector       = manager.Sector,
                            Access       = manager.Access
                        };

                        context.tblUsers.Add(newManager);
                        context.SaveChanges();
                        manager.UserID = newManager.UserID;
                        return(manager);
                    }
                    else
                    {
                        tblUser managerToEdit = (from ss in context.tblUsers where ss.UserID == manager.UserID select ss).First();

                        // Get the date of birth
                        manager.DateOfBirth = iv.CountDateOfBirth(manager.JMBG);

                        managerToEdit.FirstName    = manager.FirstName;
                        managerToEdit.LastName     = manager.LastName;
                        managerToEdit.JMBG         = manager.JMBG;
                        managerToEdit.DateOfBirth  = manager.DateOfBirth;
                        managerToEdit.BankAccount  = manager.BankAccount;
                        managerToEdit.Email        = manager.Email;
                        managerToEdit.Salary       = manager.Salary;
                        managerToEdit.Username     = manager.Username;
                        managerToEdit.Position     = manager.Position;
                        managerToEdit.UserPassword = manager.UserPassword;
                        managerToEdit.Sector       = manager.Sector;
                        managerToEdit.Access       = manager.Access;

                        managerToEdit.UserID = manager.UserID;

                        tblUser managerEdit = (from ss in context.tblUsers
                                               where ss.UserID == manager.UserID
                                               select ss).First();
                        context.SaveChanges();
                        return(manager);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
        /// <summary>
        /// Creates or edits a worker
        /// </summary>
        /// <param name="worker">the worker that is esing added</param>
        /// <returns>a new or edited worker</returns>
        public vwUser AddWorker(vwUser worker)
        {
            InputCalculator iv = new InputCalculator();

            try
            {
                using (ReportDBEntities context = new ReportDBEntities())
                {
                    if (worker.UserID == 0)
                    {
                        worker.DateOfBirth = iv.CountDateOfBirth(worker.JMBG);

                        tblUser newWorker = new tblUser
                        {
                            FirstName    = worker.FirstName,
                            LastName     = worker.LastName,
                            JMBG         = worker.JMBG,
                            DateOfBirth  = worker.DateOfBirth,
                            BankAccount  = worker.BankAccount,
                            Email        = worker.Email,
                            Position     = worker.Position,
                            Salary       = worker.Salary,
                            Username     = worker.Username,
                            UserPassword = worker.UserPassword
                        };

                        context.tblUsers.Add(newWorker);
                        context.SaveChanges();
                        worker.UserID = newWorker.UserID;
                        return(worker);
                    }
                    else
                    {
                        tblUser workerToEdit = (from ss in context.tblUsers where ss.UserID == worker.UserID select ss).First();

                        // Get the date of birth
                        worker.DateOfBirth = iv.CountDateOfBirth(worker.JMBG);

                        workerToEdit.FirstName    = worker.FirstName;
                        workerToEdit.LastName     = worker.LastName;
                        workerToEdit.JMBG         = worker.JMBG;
                        workerToEdit.DateOfBirth  = worker.DateOfBirth;
                        workerToEdit.BankAccount  = worker.BankAccount;
                        workerToEdit.Email        = worker.Email;
                        workerToEdit.Salary       = worker.Salary;
                        workerToEdit.Username     = worker.Username;
                        workerToEdit.Position     = worker.Position;
                        workerToEdit.UserPassword = worker.UserPassword;

                        workerToEdit.UserID = worker.UserID;

                        tblUser workerEdit = (from ss in context.tblUsers
                                              where ss.UserID == worker.UserID
                                              select ss).First();
                        context.SaveChanges();
                        return(worker);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
예제 #13
0
        // Update is called once per frame
        void Update()
        {
            if (paused)
            {
                movement      = new Vector2(0, 0);
                body.velocity = movement;
                return;
            }

            if (IsScriptedActionPlaying)
            {
                animator.SetFloat("WalkSpeed", 2f);
                MoveToForActionScripted();
                return;
            }
            MoveInputDirection directionX;
            MoveInputDirection directionY;
            Vector3?           inputPosition = GetInputPosition();

            if (inputPosition.HasValue)
            {
                List <MoveInputDirection> inputDirections = getDirectionToInput(inputPosition.Value);
                directionX = inputDirections[0];
                directionY = inputDirections[1];
            }
            else
            {
                directionX = InputCalculator.MovementInputX(Input.GetAxis("Horizontal"));
                directionY = InputCalculator.MovementInputY(Input.GetAxis("Vertical"));
            }

            float xMovement = (speed.x * (float)directionX) * 5f;
            float yMovement = (speed.y * (float)directionY) * 5f;

            // 4 - Movement per direction
            movement = new Vector2(xMovement, yMovement);

            body.velocity = movement;

            if (directionX == MoveInputDirection.WalkRight && isFacingLeft)
            {
                FlipRight();
            }
            else if (directionX == MoveInputDirection.WalkLeft && !isFacingLeft)
            {
                FlipLeft();
            }

            if (directionX == MoveInputDirection.NoMovement &&
                directionY == MoveInputDirection.NoMovement)
            {
                // we aren't moving so make sure we dont animate
                //animator.speed = 0.0f;
                animator.SetFloat("WalkSpeed", 0f);
            }
            else
            {
                //animator.speed = 2f;
                animator.SetFloat("WalkSpeed", 2f);
            }

            // if we are dead do not move anymore
            if (isDead == true)
            {
                GetComponent <Rigidbody2D>().velocity = new Vector2(0.0f, 0.0f);
                animator.speed = 0.0f;
            }
        }
예제 #14
0
    void GetMultiTouchInput()
    {
        for (int i = 0; i < Input.touchCount; i++)
        {
            if (Input.GetTouch(i).phase == TouchPhase.Began)
            {
                //if the last press time is less than allowed, reset the dictionary.
                if (Mathf.Abs(multiFinger.lastPressTime - Time.time) < multiTouchWindow)
                {
                    multiFinger.numFinger++;
                }
                else
                {
                    multiTouchDictionary.Clear();
                    fingerIDs.Clear();
                    multiFinger.numFinger     = 1;
                    multiFinger.lastPressTime = Time.time;
                }
                //Add the finger to the dictionary,
                multiTouchDictionary.Add(Input.GetTouch(i).fingerId, new Finger(Input.GetTouch(i), i));
                fingerIDs.Add(Input.GetTouch(i).fingerId);
                //Clear the action stack because a new press is detected.
                actionList.Clear();
            }

            if (Input.GetTouch(i).phase == TouchPhase.Ended || Input.GetTouch(i).phase == TouchPhase.Canceled)
            {
                if (multiTouchDictionary.TryGetValue(Input.GetTouch(i).fingerId, out tempFinger))
                {
                    //Before we remove it, calculate the current swipe value for each finger and save it onto the stack.
                    actionList.Add(CalculateSwipe(tempFinger.DeltaPosition));
                    //Debug text.
                    //Check if it exists in dictionary, and remove if so.
                    multiTouchDictionary.Remove(Input.GetTouch(i).fingerId);
                    fingerIDs.Remove(Input.GetTouch(i).fingerId);
                }

                //Compare the last tap time.
                if (Mathf.Abs(multiFinger.lastFingerLeaveTime - Time.time) < multiTouchWindow)
                {
                    multiFinger.numFingerLeft++;
                }
                else
                {
                    multiFinger.numFingerLeft       = 1;
                    multiFinger.lastFingerLeaveTime = Time.time;
                }
            }
        }

        if (multiTouchDictionary.Count == 0)
        {
            //The number of fingers presse is equal to the number of fingers left. It also has to have more than 1 finger so that it is a multi touch.
            if (multiFinger.numFinger == multiFinger.numFingerLeft && multiFinger.numFinger > 1)
            {
                //Check if the inputs are swipes.
                InputAction curInput     = actionList[0];
                bool        isSameAction = true;
                for (int i = 1; i < actionList.Count; i++)
                {
                    if (curInput != actionList[i])
                    {
                        isSameAction = false;
                    }
                }

                if (!isSameAction)                   //One of the finger had different from the rest of fingers.
                {
                    multiFinger.ResetFinger();

                    /*}else if (multiFinger.lastPressTime + dragThreshold + multiTouchWindow < Time.time) { Uncomment this if you want to have drag threshold on multi finger.
                     *      //Will need to be a drag, not a swipe.
                     *      multiFinger.ResetFinger();*/
                }
                else
                {
                    if (curInput == InputAction.Click)
                    {
                        //It is a successful tap. Now we check if the number of fingers previously is same as the currently saved.
                        if (multiFinger.numTap > 0)
                        {
                            bool isSameNumFinger = multiFinger.numFinger == multiFinger.numFingerTapped;
                            if (!isSameNumFinger)
                            {
                                multiFinger.numTap = 0;                                 //Reset the number of tap because the number of fingers tapped is now different.
                            }
                        }
                        else                           //This is the first tap with this number of fingers.
                        {
                            multiFinger.numFingerTapped = multiFinger.numFinger;
                        }
                        multiFinger.lastTapTime = Time.time;
                        multiFinger.numTap++;
                        multiFinger.ResetFinger();
                    }
                    else                       //It is a swipe.
                    {
                        currentInput = InputCalculator.Calculate(multiFinger.numFinger, curInput);
                    }
                }
            }

            if (multiFinger.lastTapTime + doubleClickThreshold < Time.time)
            {
                //Only count as tap IF the last finger pressed time is less than the drag threshold.
                if (multiFinger.lastPressTime + dragThreshold + multiTouchWindow > Time.time && multiFinger.lastPressTime != 0)
                {
                    //Calculate the tap and reset the value.
                    if (multiFinger.numTap == 1)
                    {
                        currentInput = InputCalculator.Calculate(multiFinger.numFingerTapped, InputAction.Click);
                    }
                    else if (multiFinger.numTap == 2)
                    {
                        currentInput = InputCalculator.Calculate(multiFinger.numFingerTapped, InputAction.DoubleClick);
                    }                     //We don't do beyond double tap.
                }

                //Reset the tap.
                multiFinger.Reset();
            }
        }
        else
        {
            //Check if any of the finger left the screen OR if there are more than 5 fingers. We don't calculate beyond 5 fingers.
            if (multiFinger.numFingerLeft > 0 || multiFinger.numFinger > 5)
            {
                currentInput = InputAction.Null;
            }

            //Check if the finger has been pressed long enough to count as a drag.
            if (multiFinger.lastPressTime + multiTouchWindow < Time.time && multiFinger.lastPressTime != 0)
            {
                //Calculate the drag.
                multiTouchDictionary[fingerIDs[0]].action = CalculateDrag(multiTouchDictionary[fingerIDs[0]].DeltaPosition);
                bool isSameAction = true;
                for (int i = 1; i < multiTouchDictionary.Count; i++)
                {
                    multiTouchDictionary[fingerIDs[i]].action = CalculateDrag(multiTouchDictionary[fingerIDs[i]].DeltaPosition);
                    if (multiTouchDictionary[fingerIDs[0]].action != multiTouchDictionary[fingerIDs[i]].action)
                    {
                        isSameAction = false;
                    }
                }
                if (isSameAction)
                {
                    //It becomes a drag.
                    currentInput = InputCalculator.Calculate(Input.touchCount, multiTouchDictionary[fingerIDs[0]].action);
                }
                else
                {
                    //The input isnt the same. Now we check if the input is pinch in/out.
                    if (multiFinger.numFinger == 2)
                    {
                        currentInput = CalculatePinch();
                    }
                }
            }
        }
    }
예제 #15
0
        public void InputCalculatorIsSetToAddOnStart()
        {
            InputCalculator calculator = new InputCalculator("asd");

            Assert.AreEqual(calculator.currentState.GetType(), new Add().GetType());
        }