Exemple #1
0
        /// <summary>
        /// converts an R2 point in screen space to a Z2 point in R-G (hex) space
        /// </summary>
        /// <param name="screenPt"></param>
        /// <returns></returns>
        Point ScreenToHex(Vector2 screenPt)
        {
            screenPt /= HexSideLen; //normalize so all side lengths are 1

            Point rgPos = new Point();

            //transform screenPt into 3 different bases
            Vector2 Vrg, Vgb, Vbr;

            Vector2.Transform(ref screenPt, ref Mrg, out Vrg); //change to R-G basis
            Vector2.Transform(ref screenPt, ref Mgb, out Vgb); //G-B basis
            Vector2.Transform(ref screenPt, ref Mbr, out Vbr); //B-R basis
            Point Prg = Vrg.Floor();
            Point Pgb = Vgb.Floor();
            Point Pbr = Vbr.Floor();

            if ((Prg.X + Prg.Y) % 3 == 0)
            {
                rgPos = Prg;
            }
            else if ((Pgb.X + Pgb.Y) % 3 == 0)
            {
                rgPos.X = -Pgb.Y;
                rgPos.Y = Pgb.X - Pgb.Y;
            }
            else if ((Pbr.X + Pbr.Y) % 3 == 0)
            {
                rgPos.X = -Pbr.X + Pbr.Y;
                rgPos.Y = -Pbr.X;
            }
            else
            {
                //might be on an intersection point
                //throw new Exception("spanish inquisition");
                rgPos = Prg; //default to Prg
            }

            return(rgPos);
        }
Exemple #2
0
 private static void FillStorage(int count, Storage storage)
 {
     for (int i = 0; i < count; i++)
     {
         Random rnd = new Random();
         int    rand;
         rand = rnd.Next(0, 3);
         Vbr core = new Vbr(rnd);
         if (rand == 0)
         {
             storage.AddItem(new Circle(core));
         }
         else if (rand == 1)
         {
             storage.AddItem(new Triangle(core));
         }
         else
         {
             storage.AddItem(new Square(core));
         }
         Thread.Sleep(20);
     }
     //return storage;
 }
Exemple #3
0
        private static void ChooseAction(int count, Storage storage)
        {
            Random rnd = new Random();

            for (int i = 0; i < count; i++)
            {
                int rand;
                Vbr core = new Vbr(rnd);
                rand = rnd.Next(0, 6);
                if (rand == 0) //Добавление элемента
                {
                    int buf = rnd.Next(0, 2);
                    if (buf == 0)
                    {
                        storage.AddItem(new Circle(core));
                    }
                    else if (buf == 1)
                    {
                        storage.AddItem(new Triangle(core));
                    }
                    else
                    {
                        storage.AddItem(new Square(core));
                    }
                    Console.WriteLine("Успешно добавлен элемент");
                }
                else if (rand == 1)
                {
                    if (storage.GetMaxIndex() != 0)
                    {
                        storage.DeleteItem(rnd.Next(1, storage.GetMaxIndex()));
                        Console.WriteLine("Успешно удален элемент по индексу");
                    }
                }
                else if (rand == 2)
                {
                    if (storage.GetMaxIndex() != 0)
                    {
                        storage.DeleteItem();
                        Console.WriteLine("Успешно удален последний элемент");
                    }
                }
                else if (rand == 3)
                {
                    Console.WriteLine("Элементов в хранилище - {0}", storage.GetMaxIndex());
                }
                else if (rand == 4)
                {
                    if (storage.GetMaxIndex() != 0)
                    {
                        storage.GetItem().Display();
                    }
                }
                else
                {
                    if (storage.GetMaxIndex() != 0)
                    {
                        storage.GetItem(rnd.Next(1, storage.GetMaxIndex())).Display();
                    }
                }
                Thread.Sleep(20);
            }
        }