Ejemplo n.º 1
0
        /// <summary>
        /// Returns the sample kurtosis of the elements of an array.
        /// </summary>
        /// <param name="v">An array of real numbers.</param>
        /// <returns>The sample kurtosis of the elements of v.</returns>
        public static double SampleKurtosis(IEnumerable <double> v)
        {
            double mean = Mean(v);

            int    count = 0;
            double num   = 0.0;
            double sumsq = 0.0;

            foreach (double item in v)
            {
                double c  = item - mean;
                double sq = c * c;
                num   += sq * sq;
                sumsq += sq;
                count++;
            }

            if (count < 4)
            {
                return(double.NaN);
            }

            double Stdev4 = ExMath.Pow(sumsq / (count - 1), 2);

            return((count * (count + 1.0) / ((count - 1.0) * (count - 2.0) * (count - 3.0))) * (num / Stdev4) -
                   3 * ((count - 1.0) * (count - 1.0)) / ((count - 2.0) * (count - 3.0)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the sample skewness of the elements of an array.
        /// </summary>
        /// <param name="v">An array of real numbers.</param>
        /// <returns>The sample skewness of the elements of v.</returns>
        public static double SampleSkewness(IEnumerable <double> v)
        {
            double mean = Mean(v);

            int    count   = 0;
            double sumcube = 0.0;
            double sumsq   = 0.0;

            foreach (double item in v)
            {
                double c  = item - mean;
                double sq = c * c;
                sumcube += sq * c;
                sumsq   += sq;
                count++;
            }

            if (count < 3)
            {
                return(double.NaN);
            }

            double Stdev = Math.Sqrt(sumsq / (count - 1));

            return((count * sumcube) / ((count - 1.0) * (count - 2.0) * ExMath.Pow(Stdev, 3)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the population kurtosis of the elements of an array.
        /// </summary>
        /// <param name="v">An array of real numbers.</param>
        /// <returns>The population kurtosis of the elements of v.</returns>
        public static double PopulationKurtosis(IEnumerable <double> v)
        {
            double mean = Mean(v);

            int    count = 0;
            double num   = 0.0;
            double sumsq = 0.0;

            foreach (double item in v)
            {
                double c  = item - mean;
                double sq = c * c;
                num   += sq * sq;
                sumsq += sq;
                count++;
            }

            if (count < 4)
            {
                return(double.NaN);
            }

            double Stdev4 = ExMath.Pow(sumsq / count, 2);

            return((num / count) / Stdev4 - 3);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns the population skewness of the elements of an array.
        /// </summary>
        /// <param name="v">An array of real numbers.</param>
        /// <returns>The population skewness of the elements of v.</returns>
        public static double PopulationSkewness(IEnumerable <double> v)
        {
            double mean = Mean(v);

            int    count   = 0;
            double sumcube = 0.0;
            double sumsq   = 0.0;

            foreach (double item in v)
            {
                double c  = item - mean;
                double sq = c * c;
                sumcube += sq * c;
                sumsq   += sq;
                count++;
            }

            if (count < 3)
            {
                return(double.NaN);
            }

            double stdev = Math.Sqrt(sumsq / count);

            return((sumcube / count) / ExMath.Pow(stdev, 3));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the central moment of a specific order of the elements of an array.
        /// </summary>
        /// <param name="v">An array of real numbers.</param>
        /// <param name="k">The order of the central moment.</param>
        /// <returns>The central moment of k-order of the elements of v.</returns>
        /// <exception cref="System.ArgumentException">The value of k less than one.</exception>
        public static double PopulationCentralMoment(IEnumerable <double> v, int k)
        {
            if (k < 1)
            {
                throw new ArgumentException("The order of the central moment must be greater than zero.");
            }

            if (!v.Any())
            {
                return(double.NaN);
            }

            if (k == 1)
            {
                return(0.0);
            }

            int    count = 0;
            double mean  = Mean(v);
            double sum   = 0.0;

            foreach (double item in v)
            {
                sum += ExMath.Pow(item - mean, k);
                count++;
            }

            return(sum / count);
        }
        private void CalcUnitPrice()
        {
            if (this.dg == null)
            {
                return;
            }
            if (this.dg.SelectedIndex == -1)
            {
                return;
            }

            switch (this.dg.SelectedIndex)
            {
            case 0:         // 上代
                this.txtUnitPrice.Text = ExCast.zCStr(ExMath.zFloor(this.retail_price * ExCast.zCInt(this.numUpCreditRate.Value) / 100, this.unit_decimal_digit));
                break;

            case 1:         // 売上単価
                this.txtUnitPrice.Text = ExCast.zCStr(ExMath.zFloor(this.sales_unit_price * ExCast.zCInt(this.numUpCreditRate.Value) / 100, this.unit_decimal_digit));
                break;

            case 2:         // 売上原価
                this.txtUnitPrice.Text = ExCast.zCStr(ExMath.zFloor(this.sales_cost_price * ExCast.zCInt(this.numUpCreditRate.Value) / 100, this.unit_decimal_digit));
                break;
            }
        }
        /// <summary>
        /// Returns the value of complementary error function for the specified argument.
        /// </summary>
        /// <param name="x">A real number.</param>
        /// <returns>The value of the complementary error function for x.</returns>
        public static double Erfc(double x)
        {
            double absx = Math.Abs(x);

            if (absx > MaxArgVal)
            {
                return((x > 0.0) ? 0.0 : 2.0);
            }

            if (absx <= Intval1)
            {
                return(1.0 - Erf(x));
            }

            if (x < 0.0)
            {
                return(2.0 - Erfc(-x));
            }

            if (absx <= Intval2)
            {
                return(Math.Exp(-(x * x)) * RationalFunc(erfc_p1, erfc_q1, x));
            }
            else
            {
                double xsq    = x * x;
                double invxsq = 1.0 / xsq;
                double R      = RationalFunc(erfc_p2, erfc_q2, invxsq);
                double t      = 1.0 / ExMath.SqrtPi + invxsq * R;
                return(Math.Exp(-xsq) / x * (t - ExMath.Truncate(t)));
            }
        }
Ejemplo n.º 8
0
    //NOTE: there are still some weird artifacts going on as if something is being rounded the wrong way --- no idea if this is still the case i hafta look into it - TODO
    //yes there are indeed still some artifacts around the 0 coordinate but that will hafta wait
    public void RenderScreen()
    {
        Vector2 localPos;
        Vector2 AdditionVector;
        Vector2 LastPos;

        GetCollision(Camera);
        DisplayBuffer = DrawPoint.Const(BackgroundChar, Background, DisplayBuffer);
        for (int i = 0; i < Camera.CollidingObjects.Count; i++)
        {
            if (Camera.CollidingObjects[i].Visible)
            {
                if (Camera.CollidingObjects[i].NAME != Camera.NAME && !Camera.CollidingObjects[i].TEXT_OBJ)
                {
                    LastPos  = Camera.CollidingObjects[i].GetPos() - 1;
                    localPos = Camera.LocalizePos(Camera.CollidingObjects[i]);
                    if (Camera.CollidingObjects[i].GetSize() > 1)
                    {
                        localPos -= Camera.CollidingObjects[i].GetSize() / 2;
                    }
                    for (int y = 0; y < Camera.CollidingObjects[i].GetSize().y; y++)
                    {
                        AdditionVector = Vector2.Copy(localPos);
                        LastPos.y      = y + localPos.y - 1;
                        if (LastPos.y == ExMath.Round(y + localPos.y))
                        {
                            AdditionVector.y++;
                        }
                        for (int x = 0; x < Camera.CollidingObjects[i].GetSize().x; x++)
                        {
                            LastPos.x = x + localPos.x - 1;
                            if (LastPos.x == ExMath.Round(x + localPos.x))
                            {
                                AdditionVector.x++;
                            }
                            DisplayBuffer = DrawPoint.InsertAsMiddle(DisplayBuffer, (int)ExMath.Round(x + AdditionVector.x), (int)ExMath.Round(y + AdditionVector.y), '#', Camera.CollidingObjects[i].Color);
                        }
                    }
                }
                else if (Camera.CollidingObjects[i].TEXT_OBJ)
                {
                    localPos = Camera.LocalizePos(Camera.CollidingObjects[i]);
                    string[] TEXT = Camera.CollidingObjects[i].Text.Split("\r\n");
                    for (int y = 0; y < TEXT.Length; y++)
                    {
                        for (int x = 0; x < TEXT[y].Length; x++)
                        {
                            DisplayBuffer = DrawPoint.InsertAsMiddle(DisplayBuffer, (int)ExMath.Round(x + localPos.x), (int)ExMath.Round(localPos.y - y), TEXT[y][x], Camera.CollidingObjects[i].Color);
                        }
                    }
                }
            }
        }
        Renderer.UpdateBuffer(DisplayBuffer);
    }
 public static long AsInt64(Complex c)
 {
     if (c.IsReal)
     {
         if (ExMath.IsInt64(c.Re))
         {
             return((long)c.Re);
         }
         throw ExceptionHelper.ThrowInvalidArgumentType("integer", "real");
     }
     throw ExceptionHelper.ThrowInvalidArgumentType("integer", "complex");
 }
Ejemplo n.º 10
0
        public void IntPartTest(double re, double im, double reRes, double imRes)
        {
            //arrange
            Complex c        = new Complex(re, im);
            Complex expected = new Complex(reRes, imRes);

            //action
            Complex actual = ExMath.IntPart(c);

            //assert
            actual.Should().Be(expected);
        }
Ejemplo n.º 11
0
        public void FracPartTest(double re, double im, double reRes, double imRes)
        {
            //arrange
            Complex c        = new Complex(re, im);
            Complex expected = new Complex(reRes, imRes);

            //action
            Complex actual = ExMath.FracPart(c);

            //assert
            NumericUtil.FuzzyEquals(actual, expected, 10E-15).Should().BeTrue();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Returns the population variance of the elements of an array.
        /// </summary>
        /// <param name="v">An array of real numbers.</param>
        /// <returns>The population variance of the elements of v.</returns>
        public static double PopulationVariance(IEnumerable <double> v)
        {
            int    count = 0;
            double sum   = 0.0;
            double mean  = Mean(v);

            foreach (double item in v)
            {
                sum += ExMath.Pow(item - mean, 2);
                count++;
            }

            return(sum / count);
        }
        private void ExChildWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // 画面初期化
            ExVisualTreeHelper.initDisplay(this.LayoutRoot);

            EntityUnitPriceSetting _entity = null;

            switch (this.kbn)
            {
            case eKbn.Sales:
                _entity = new EntityUnitPriceSetting();
                _entity.unit_kind_nm = "上代";
                _entity.unit_price   = this.retail_price;
                _lstUnit.Add(_entity);
                _entity = new EntityUnitPriceSetting();
                _entity.unit_kind_nm = "売上単価";
                _entity.unit_price   = this.sales_unit_price;
                _lstUnit.Add(_entity);
                _entity = new EntityUnitPriceSetting();
                _entity.unit_kind_nm = "売上原価";
                _entity.unit_price   = this.sales_cost_price;
                _lstUnit.Add(_entity);
                break;

            case eKbn.Purchase:
                _entity = new EntityUnitPriceSetting();
                _entity.unit_kind_nm = "上代";
                _entity.unit_price   = this.retail_price;
                _lstUnit.Add(_entity);
                _entity = new EntityUnitPriceSetting();
                _entity.unit_kind_nm = "仕入単価";
                _entity.unit_price   = this.sales_unit_price;
                _lstUnit.Add(_entity);
                _entity = new EntityUnitPriceSetting();
                _entity.unit_kind_nm = "売上原価";
                _entity.unit_price   = this.sales_cost_price;
                _lstUnit.Add(_entity);
                break;
            }
            this.dg.ItemsSource   = _lstUnit;
            this.dg.SelectedIndex = 0;

            this.numUpCreditRate.SetValue(this.credit_rate);
            //this.numUpCreditRate.Value = this.credit_rate;

            this.txtUnitPrice.Text = ExCast.zCStr(ExMath.zFloor(this.retail_price * ExCast.zCInt(this.numUpCreditRate.Value) / 100, this.unit_decimal_digit));
            this.txtUnitPrice.OnFormatString();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Returns the sample variance of the elements of an array.
        /// </summary>
        /// <param name="v">An array of real numbers.</param>
        /// <returns>The sample variance of the elements of v.</returns>
        public static double SampleVariance(IEnumerable <double> v)
        {
            int    count = 0;
            double sum   = 0.0;
            double mean  = Mean(v);

            foreach (double item in v)
            {
                sum += ExMath.Pow(item - mean, 2);
                count++;
            }

            if (count == 1)
            {
                return(0.0);
            }
            return(sum / (count - 1));
        }
 private Complex EvaluateComplexComplex(Complex left, Complex right)
 {
     if (right.IsReal)
     {
         if (ExMath.IsInt32(right.Re))
         {
             return(Complex.Pow((Complex)left, (int)right.Re));
         }
         else
         {
             return(Complex.Pow((Complex)left, right.Re));
         }
     }
     else
     {
         return(Complex.Pow((Complex)left, right));
     }
 }
 private CMatrix EvaluateCMatrixComplex(CMatrix left, Complex right)
 {
     if (left.IsVector)
     {
         return(CMatrix.Pow(left, right));
     }
     else if (left.IsSquare)
     {
         if (right.IsReal && ExMath.IsInt32(right.Re))
         {
             return(CMatrix.Pow(left, (int)right.Re));
         }
         else
         {
             throw new ArgumentException(Properties.Resources.EXC_MATRIX_NOT_INTEGER_POWER);
         }
     }
     else
     {
         throw new ArgumentException(Properties.Resources.EXC_MATRIX_MUST_BE_SQUARE_OR_VECTOR);
     }
 }
Ejemplo n.º 17
0
        // 名称マスタリストから個別名称リストへセット
        private void SetIndividualList(object objList)
        {
            objNameList = (ObservableCollection <EntityName>)objList;
            for (int i = 0; i <= objNameList.Count - 1; i++)
            {
                switch ((geNameKbn)objNameList[i].division_id)
                {
                case geNameKbn.TAX_CHANGE_ID:                   // 税転換ID
                    glstTaxChange.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.BUSINESS_DIVISION_ID:            // 取引区分ID
                    glstBusinessDivison.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.BREAKDOWN_ID:                    // 内訳ID
                    glstBreakdown.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.DELIVER_DIVISION_ID:             // 納品区分ID
                    glstDeliverDivision.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.UNIT_ID:                         // 単位ID
                    glstUnit.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.TAX_DIVISION_ID:                 // 課税区分ID
                    glstTaxDivision.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.INVENTORY_DIVISION_ID:           // 在庫管理区分ID
                    glstInventoryDivison.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.UNIT_PRICE_DIVISION_ID:          // 単価区分ID
                    glstUnitPriceDivision.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.DISPLAY_DIVISION_ID:             // 表示区分ID
                    glstDisplayDivision.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.TITLE_ID:                        // 敬称ID
                    glstTitle.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.FRACTION_PROC_ID:                // 端数処理ID
                    glstFractionProc.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.COLLECT_CYCLE_ID:                // 回収サイクルID
                    glstCollectCycle.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.CLASS:                           // 分類区分ID
                    int _id = 0;
                    try
                    {
                        _id = ExCast.zCInt(ExMath.zCeiling(ExCast.zCDbl(ExCast.zCDbl(objNameList[i].id) / 3), 0));
                    }
                    catch
                    {
                    }
                    glstClass.Add(new ListData(_id, objNameList[i].description));
                    break;

                case geNameKbn.DIVIDE_PERMISSION_ID:            // 分納許可ID
                    glstDividePermission.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.INQUIRY_DIVISION_ID:             // 問い合わせ区分ID
                    glstInquiryDivision.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.LEVEL_ID:                // 問い合わせ緊急度ID
                    glstLevel.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.INQUIRY_STATE_ID:                // 問い合わせ状態ID
                    glstInquiryState.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.APPROVAL_STATE_ID:               // 承認状態ID
                    glstApprovalState.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.ACCOUNT_KBN:                     // 預金種別
                    glstAccountKbn.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.OPEN_CLOSE_STATE_ID:             // 状態ID
                    glstOpenCloseState.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.BUSINESS_DIVISION_PU_ID:         // 取引区分ID(仕入)
                    glstBusinessDivisonPu.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.SEND_KBN:                        // 発送区分
                    glstSendkbn.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.TAX_CHANGE_PU_ID:                // 税転換ID(仕入)
                    glstTaxChangePu.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.UNIT_PRICE_DIVISION_PU_ID:       // 単価区分ID(仕入)
                    glstUnitPriceDivisionPu.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.IN_OUT_DELIVERY_KBN:             // 入出庫区分
                    glstInOutDeliveryKbn.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.IN_OUT_DELIVERY_PROC_KBN:        // 入出庫処理区分
                    glstInOutDeliveryProcKbn.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                case geNameKbn.IN_OUT_DELIVERY_TO_KBN:          // 入出庫先区分
                    glstInOutDeliveryToKbn.Add(new ListData(objNameList[i].id, objNameList[i].description));
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Returns the value of the probability density function for the specified value.
        /// </summary>
        /// <param name="x">A real number within the domain of the distribution.</param>
        /// <returns>The value of the probability density function for x.</returns>
        public override double ProbabilityDensityFunction(double x)
        {
            double var = _stdev * _stdev;

            return((1.0 / Math.Sqrt(ExMath.TwoPi * var)) * Math.Exp(-ExMath.Pow(x - _mean, 2) / (2 * var)));
        }
Ejemplo n.º 19
0
 public override object Evaluate()
 {
     return((Complex)ExMath.ToDegrees(SubExpression.EvaluateAsReal()));
 }
Ejemplo n.º 20
0
 public override object Evaluate()
 {
     return(ExMath.FracPart(SubExpression.EvaluateAsComplex()));
 }
Ejemplo n.º 21
0
        public double GetHeading()
        {
            ThreeAxisScaledData sd;
            double Xm, Ym, Zm;
            double Xh, Yh;
            double cp, sp, cr, sr; // Cos and Sin of Pitch and Roll
            double result;

            sd = this.ScaledData; // this ensures we are only reading once from the bus
            Xm = sd.ScaledX;      // swapping X=Y due to installment
            Ym = sd.ScaledY;
            Zm = sd.ScaledZ;

            cp = ExMath.Cos(pitch);
            sp = ExMath.Sin(pitch);
            cr = ExMath.Cos(roll);
            sr = ExMath.Sin(roll);
#if false
// Below algorithm for tilt taken from LoveElectronics and proved to be wrong:
// Roll causes heading to swing and be incorrect
            Xh     = Xm * cp + Zm * sp;
            Yh     = Xm * sr * sp + Ym * cr - Zm * sr * cp;
            result = ExMath.Atan(Yh / Xh);
#else
            // Below algorthing for tilt compensation taken from
            // http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-documents/Magnetic__Literature_Technical_Article-documents/Applications_of_Magnetic_Sensors_for_Low_Cost_Compass_Systems.pdf
            // Goto http://www.magneticsensors.com choose Literature and on the "Technical Articles" select the above article
            // results are great!
            Xh     = Xm * cp + Ym * sr * sp - Zm * cr * sp;
            Yh     = Ym * cr + Zm * sr;
            result = ExMath.Atan(Yh / Xh);
            if (Xh < 0)
            {
                result = ExMath.PI - result;
            }
            else if (Xh > 0)
            {
                if (Yh < 0)
                {
                    result = -result;
                }
                else if (Yh > 0)
                {
                    result = 2 * ExMath.PI - result;
                }
                else
                {
                    ;
                }
            }
            else // Xh == 0
            if (Yh < 0)
            {
                result = ExMath.PI / 2; // 90 degrees
            }
            else
            {
                result = ExMath.PI + ExMath.PI / 2; // 270 degrees
            }
#endif

            // Add the declination value
            result += declination;
            return(result);
        }
Ejemplo n.º 22
0
 public double GetRollDegrees()
 {
     return((int)ExMath.RadiansToDegrees(roll));
 }
Ejemplo n.º 23
0
        public double GetHeadingRaw()
        {
            ThreeAxisScaledData sd = this.ScaledData; // this ensures we are reading data only once from the bus

            return(ExMath.Atan(sd.ScaledY / sd.ScaledX));
        }
Ejemplo n.º 24
0
 /// <summary>
 /// Transforms Cartesian coordinates to polar.
 /// </summary>
 /// <param name="x">A real number representing the x-coordinate.</param>
 /// <param name="y">A real number representing the y-coordinate.</param>
 /// <param name="r">Output parameter, the real number representing the polar radius.</param>
 /// <param name="theta">Output parameter, the real number representing the polar angle.</param>
 public static void CartesianToPolar(double x, double y, out double r, out double theta)
 {
     r     = ExMath.Hypot(x, y);
     theta = Math.Atan2(y, x);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Transforms Cartesian coordinates to cylindrical.
 /// </summary>
 /// <param name="x">A real number representing the x-coordinate.</param>
 /// <param name="y">A real number representing the y-coordinate.</param>
 /// <param name="z">A real number representing the z-coordinate.</param>
 /// <param name="r">Output parameter, the real number representing the radial distance.</param>
 /// <param name="theta">Output parameter, the real number representing the azimuthal angle.</param>
 public static void CartesianToCylindrical(double x, double y, double z, out double r, out double theta)
 {
     r     = ExMath.Hypot(x, y);
     theta = Math.Atan2(y, x);
 }
Ejemplo n.º 26
0
        public void Start(GameSystem gameSys)
        {
            MenuText.Visible  = false;
            MenuText.TEXT_OBJ = true;
            MenuText.Text     = "You have lost\r\nPress 'R' to play again";
            gameSys.AddObject(MenuText);
            //MAIN GAME CODE GOES UNDER HERE
            int GameXSize = 50;
            int GameYSize = 50;

            Object Player = new Object("PHead", new Vector2(1, 1), new Vector2(0, 0), 1, Color.Green);
            Object APPLE  = new Object("APPLE", new Vector2(1, 1), new Vector2(gameSys.Ran.Next((int)ExMath.Round(-(GameXSize * .5f) + 1), (int)ExMath.Round(GameXSize * .5f - 1)), gameSys.Ran.Next((int)ExMath.Round(-(GameYSize * .5f) + 1), (int)ExMath.Round(GameYSize * .5f - 1))), -1, Color.Red);

            gameSys.AddObject(APPLE);
            gameSys.AddObject(Player);
            gameSys.AddObject(new Object("LWall", new Vector2(1, GameYSize), new Vector2(-(GameXSize * .5f), 0), Color.DarkGray));
            gameSys.AddObject(new Object("RWall", new Vector2(1, GameYSize), new Vector2(GameXSize * .5f, 0), Color.DarkGray));
            gameSys.AddObject(new Object("UWall", new Vector2(GameXSize, 1), new Vector2(0, GameYSize * .5f), Color.DarkGray));
            gameSys.AddObject(new Object("DWall", new Vector2(GameXSize, 1), new Vector2(0, -(GameYSize * .5f)), Color.DarkGray));

            Vector2       Dir = new Vector2(0, 0);
            float         TimeBetweenMoves = 100;
            DateTime      NextMove         = DateTime.MinValue;
            Vector2       DirMove          = Dir;
            bool          Alive            = true;
            int           length           = 1;
            List <Object> Body             = new List <Object>();

            while (Alive)
            {
                if (Keyboard.IsKeyPressed(ConsoleKey.W) && Dir != -Vector2.Up)
                {
                    DirMove = Vector2.Up;
                }
                else if (Keyboard.IsKeyPressed(ConsoleKey.S) && Dir != Vector2.Up)
                {
                    DirMove = -Vector2.Up;
                }
                if (Keyboard.IsKeyPressed(ConsoleKey.A) && Dir != Vector2.Right)
                {
                    DirMove = -Vector2.Right;
                }
                else if (Keyboard.IsKeyPressed(ConsoleKey.D) && Dir != -Vector2.Right)
                {
                    DirMove = Vector2.Right;
                }
                if (DateTime.Now > NextMove)
                {
                    Dir      = DirMove;
                    NextMove = DateTime.Now.AddMilliseconds(TimeBetweenMoves);
                    if (length > 1 && length > Body.Count + 1)
                    {
                        Body.Add(new Object("BODY", new Vector2(1, 1), Vector2.Copy(Player.GetPos()), Color.Aqua));
                        gameSys.AddObject(Body[Body.Count - 1]);
                    }
                    if (length > 1)
                    {
                        for (int i = Body.Count - 1; i > 0; i--)
                        {
                            Body[i].RePosition(Body[i - 1].GetPos());
                        }
                        Body[0].RePosition(Player.GetPos());
                    }
                    Player.RePosition(Player.GetPos() + Dir);
                    gameSys.GetCollision(Player);

                    foreach (Object coll in Player.CollidingObjects)
                    {
                        if (coll.NAME.Contains("Wall") || coll.NAME.Contains("BODY"))
                        {
                            Alive = false;
                            return;
                        }
                        if (coll.NAME.Contains("APPLE"))
                        {
                            bool Usable = false;
                            while (!Usable)
                            {
                                APPLE.RePosition(new Vector2(gameSys.Ran.Next((int)ExMath.Round(-(GameXSize * .5f) + 1), (int)ExMath.Round(GameXSize * .5f - 1)), gameSys.Ran.Next((int)ExMath.Round(-(GameYSize * .5f) + 1), (int)ExMath.Round(GameYSize * .5f - 1))));
                                gameSys.GetCollision(APPLE);
                                Usable = true;
                                foreach (Object aColl in APPLE.CollidingObjects)
                                {
                                    if (aColl.NAME.Contains("BODY"))
                                    {
                                        Usable = false; return;
                                    }
                                }
                            }


                            length++;
                        }
                    }
                }
                while (!Alive)
                {
                    MenuText.Visible = true;
                }
                gameSys.RenderScreen();
            }
        }
Ejemplo n.º 27
0
 public int GetPitchDegrees()
 {
     return((int)ExMath.RadiansToDegrees(pitch));
 }
Ejemplo n.º 28
0
 public double GetHeadingDegrees()
 {
     return(ExMath.RadiansToDegrees(this.GetHeading()));
 }