Пример #1
0
        /*Public methods*/

        public void TakeLoan(int amount, int paymentsCount)
        {
            if (Loan != null && false == Loan.IsPaidOff)
            {
                throw new InvalidOperationException(
                          "Only one loan can be active at a time");
            }

            int amountToPayOff = CalculateLoanAmountWithInterest(amount);

            Loan = new BankLoan(amountToPayOff, paymentsCount);
            SimulationManagerComponent.ControlledCompany.Balance += amount;
            GameTimeComponent.MonthChanged += UpdateLoan;
            LoanAdded?.Invoke(Loan);
        }
Пример #2
0
        private void PaySinglePayment(BankLoan loan)
        {
            int companyPayment;

            //This might happen because single payment is floor of calculated value
            //so last payment may be bigger than the others
            if (loan.PaymentsPaid == loan.PaymentsCount - 1 && loan.AmountPaid < loan.Amount)
            {
                companyPayment = loan.Amount - loan.AmountPaid;
            }
            else
            {
                companyPayment = loan.SinglePayment;
            }

            ++loan.PaymentsPaid;
            loan.AmountPaid += companyPayment;
            SimulationManagerComponent.ControlledCompany.Balance -= companyPayment;
        }