Пример #1
0
        /// <summary>
        /// Creates a new battleship either manually or authomatically finding ther largest empty slot
        /// </summary>
        /// <param name="random"></param>
        /// <param name="alingment"></param>
        /// <param name="size"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public Battleship CreateBattleship(bool random, Alingment alingment = Alingment.Horizontal, int size = -1, int x = -1, int y = -1)
        {
            Battleship bs;

            if (random)      //if random find the largest Battleship that we can allocate to the board
            {
                if (alingment == Alingment.Horizontal)
                {
                    bs = FindLargestHorizontalShip();
                }
                else
                {
                    bs = FindLargestVerticalShip();
                }
            }
            else
            {
                bs = BuildBattleship(alingment, size, x, y);
            }
            if (bs != null)
            {
                Battleships.Add(bs);
            }
            return(bs);
        }
Пример #2
0
        /// <summary>
        /// Suorittaa kontrollin päivittämisen. Vakiona kuuntelee
        /// eventit ja ankkuroi sen mahdolliseen parenttiin.
        /// </summary>
        /// <param name="gameTime"></param>
        public virtual void Update(GameTime gameTime)
        {
            Effects.AllEffects.ForEach(e => e.Update(gameTime));

            eventDispatchers.ForEach(d =>
            {
                if (d.IsListening)
                {
                    d.ListenOnce();
                }
            });

            if (Parent != null)
            {
                Size.Transform(Parent.Size);
                Position.Relative = Alingment.Calculate(this);
            }
            Position.Transform(Parent);

            updateActions.ForEach(a => a.Invoke(this));
        }
Пример #3
0
        private Battleship BuildBattleship(Alingment alingment, int size, int x, int y)
        {
            var bs = new Battleship();

            if (Squares.Where(s => s.X == x && s.Y == y).FirstOrDefault() == null ||
                Squares.Where(s => (s.X == x + size - 1 && s.Y == y && alingment == Alingment.Horizontal) ||
                              (s.Y == y + size - 1 && s.X == x && alingment == Alingment.Vertical)).FirstOrDefault() == null)
            {
                bs = null;
            }
            else
            {
                if (alingment == Alingment.Horizontal)
                {
                    if (Squares.Any(s => (s.Y == y && (s.X >= x && s.X <= x + size - 1)) && !s.IsEmpty))
                    {
                        bs = null;
                    }
                    else
                    {
                        bs.AddSquares(Squares.Where(s => (s.Y == y && (s.X >= x && s.X <= x + size))));
                    }
                }
                else
                {
                    if (Squares.Any(s => (s.X == x && (s.Y >= y && s.Y <= y + size - 1)) && !s.IsEmpty))
                    {
                        bs = null;
                    }
                    else
                    {
                        bs.AddSquares(Squares.Where(s => (s.X == x && (s.Y >= y && s.Y <= y + size - 1))));
                    }
                }
            }
            return(bs);
        }
Пример #4
0
        public Control()
        {
            // Asettaa vakio alingmentin.
            alingment = new Alingment()
            {
                Horizontal = HorizontalAlingment.None,
                Vertical   = VerticalAlingment.None
            };
            // Asettaa vakio värit.
            colors = new Colors()
            {
                Foreground = Color.Black,
                Background = Color.White
            };
            FocusIndex = Index.Empty;

            size     = ControlSize.Default();
            position = ControlPosition.Default();

            updateActions = new List <Action <Control> >();
            Effects       = new EffectContainer();

            MakeDispatchers();
        }