示例#1
0
        // Move grains
        public void MoveGrain(BaseGrain grain, int dx, int dy)
        {
            if (activeGrains.ContainsKey(new Vector(dx, dy) + grain.SimPos()))
            {
                Debug.WriteLine("Position blocked");
                return;
            }

            activeGrains.Remove(grain.SimPos());

            grain.SimMove(dx, dy);

            activeGrains.Add(grain.SimPos(), grain);
        }
示例#2
0
        private BaseGrain SimCreateGrain(int x, int y)
        {
            Vector grainPosition = new Vector(x, y);

            if (activeGrains.ContainsKey(grainPosition))
            {
                Debug.WriteLine("Grain already exists at that position");
                return(null);
            }

            // Create grain
            BaseGrain grain = new BaseGrain(x, y, grainScale);

            // Add to canvas
            grain.Draw(simCanvas);

            // Add to dictionary of active grains
            activeGrains.Add(new Vector(x, y), grain);

            return(grain);
        }