예제 #1
0
        /// <summary>
        /// Adds a stone to a gameboard
        /// </summary>
        private void InsertRockImage(System.Windows.Input.MouseButtonEventArgs e)
        {
            if (MouseInTableArea(e, dragImage_new))
            {
                int left = (int)e.GetPosition(tablePanel).X - dragImage_mousePos_X;
                int top  = (int)e.GetPosition(tablePanel).Y - dragImage_mousePos_Y;

                // sets handler so that we can manipulate with the object
                dragImage_new.MouseDown += new System.Windows.Input.MouseButtonEventHandler(RockImageOld_MouseDown);
                dragImage_new.MouseUp   += new System.Windows.Input.MouseButtonEventHandler(rockImage_MouseUp);

                // check the type of the object to insert
                A_TableObject object_to_put = null;
                if ((A_TableObject)dragImage_new.DataContext is Graviton)
                {
                    object_to_put = new Graviton();
                    ((Graviton)object_to_put).Name         = "Graviton";
                    ((Graviton)object_to_put).BaseSettings = tableManager.TableDepositor.table.Settings.gravitonSettings;
                }
                if ((A_TableObject)dragImage_new.DataContext is Generator)
                {
                    object_to_put = new Generator();
                    ((Generator)object_to_put).Name         = "Generator";
                    ((Generator)object_to_put).BaseSettings = tableManager.TableDepositor.table.Settings.generatorSettings;
                }
                if ((A_TableObject)dragImage_new.DataContext is Magneton)
                {
                    object_to_put = new Magneton();
                    ((Magneton)object_to_put).Name         = "Magneton";
                    ((Magneton)object_to_put).BaseSettings = tableManager.TableDepositor.table.Settings.magnetonSettings;
                }
                if ((A_TableObject)dragImage_new.DataContext is BlackHole)
                {
                    object_to_put = new BlackHole();
                    ((BlackHole)object_to_put).Name         = "BlackHole";
                    ((BlackHole)object_to_put).BaseSettings = tableManager.TableDepositor.table.Settings.blackHoleSettings;
                }

                // sets position
                object_to_put.Position = PointHelper.TransformPointToEuc(new FPoint(left * CommonAttribService.ACTUAL_TABLE_SIZE_MULTIPLIER + dragImage_new.Width / 2,
                                                                                    top * CommonAttribService.ACTUAL_TABLE_SIZE_MULTIPLIER + dragImage_new.Height / 2), CommonAttribService.ACTUAL_TABLE_WIDTH,
                                                                         CommonAttribService.ACTUAL_TABLE_HEIGHT);

                dragImage_new.DataContext = object_to_put;
                // add it into a system
                tableManager.InsertObject(object_to_put);
                rockImages.Add(dragImage_new);
            }
            else
            {
                // icon is beyond the border of the game table -> delete it
                if (tablePanel.mainGrid.Children.Contains(dragImage_new))
                {
                    tablePanel.mainGrid.Children.Remove(dragImage_new);
                }
            }
            dragImage_new = null;
        }
예제 #2
0
 /// <summary>
 /// Removes an existing object from the system
 /// </summary>
 public void RemoveObject(A_TableObject obj)
 {
     if (obj is Particle && tableDepositor.particles.Contains(obj))
     {
         tableDepositor.particles.Remove((Particle)obj);
     }
     if (obj is Graviton && tableDepositor.gravitons.Contains(obj))
     {
         tableDepositor.gravitons.Remove((Graviton)obj);
     }
     if (obj is Generator && tableDepositor.generators.Contains(obj))
     {
         tableDepositor.generators.Remove((Generator)obj);
     }
     if (obj is Magneton && tableDepositor.magnetons.Contains(obj))
     {
         tableDepositor.magnetons.Remove((Magneton)obj);
     }
     if (obj is BlackHole && tableDepositor.blackHoles.Contains(obj))
     {
         tableDepositor.blackHoles.Remove((BlackHole)obj);
     }
 }
예제 #3
0
 /// <summary>
 /// Inserts a new object into the system
 /// </summary>
 /// <param name="obj"></param>
 public void InsertObject(A_TableObject obj)
 {
     if (obj is Particle)
     {
         tableDepositor.particles.Add((Particle)obj);                 // this will likely not happen
     }
     if (obj is Graviton)
     {
         tableDepositor.gravitons.Add((Graviton)obj);
     }
     if (obj is Generator)
     {
         tableDepositor.generators.Add((Generator)obj);
     }
     if (obj is Magneton)
     {
         tableDepositor.magnetons.Add((Magneton)obj);
     }
     if (obj is BlackHole)
     {
         tableDepositor.blackHoles.Add((BlackHole)obj);
     }
 }