Beispiel #1
0
 public void InsertWall(Wall wall)
 {
     foreach (Wall w in walls)
     {
         if (wall.Equals(w))
         {
             return;
         }
     }
     walls.Add(wall);
 }
Beispiel #2
0
        private bool isPointOnLine(Point p, Wall w)
        {
            int dxp = p.X - w.Start.X;
            int dyp = p.Y - w.Start.Y;

            int dxe = w.End.X - w.Start.X;
            int dye = w.End.Y - w.Start.Y;

            int cross = dxp * dye - dyp * dxe;

            return cross == 0;
        }
Beispiel #3
0
        public void IsPointOnLine_StartingEdge_Vertical_Test()
        {
            GameLogicSvc target = new GameLogicSvc();

            Wall w = new Wall() { Start = new Point() { X = 50, Y = 0 }, End = new Point() { X = 50, Y = 50 } };
            Point p = new Point() { X = 50, Y = 0 };

            bool isOnLine = target.isPointOnLine(p, w);

            Assert.AreEqual(true, isOnLine);
        }
Beispiel #4
0
        private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
        {
            System.Windows.Point p = Mouse.GetPosition(rootCanvas);
            if (IsDebug && e.ChangedButton == MouseButton.Left)
            {

                int x;
                int y;
                Calc_x_y(p, out x, out y);

                if (wall == null)
                {
                    wall = new Wall();
                    wall.Start = new FHVGame.Shared.Models.Game.Point() { X = x, Y = y };

                    // Add visual Start-Point
                    startPoint = DrawEllipse(x, y, 5, Color.FromRgb(255, 0, 0));
                }
                else
                {
                    wall.End = new FHVGame.Shared.Models.Game.Point() { X = x, Y = y };

                    // Add wal to data
                    //Level.Lvl.Walls.Add(wall);
                    ViewModel.CurrentLevel.Lvl.Walls.Add(wall);

                    // Add wall tu UI
                    DrawWall(ViewModel.CurrentLevel.Lvl.Walls.Count - 1);

                    // Remove start-point
                    rootCanvas.Children.Remove(startPoint);

                    wall = null;
                }
            }
            else if (IsDebug && e.ChangedButton == MouseButton.Right)
            {
                Calc_x_y(p, out deleteX, out deleteY);
            }
        }
Beispiel #5
0
        public void IsPointOnLine_None_Vertical_Small_Test()
        {
            GameLogicSvc target = new GameLogicSvc();

            Wall w = new Wall() { Start = new Point() { X = 50, Y = 25 }, End = new Point() { X = 50, Y = 24 } };
            Point p = new Point() { X = 50, Y = 23 };

            bool isOnLine = target.isPointOnLine(p, w);

            Assert.AreEqual(false, isOnLine);
        }
Beispiel #6
0
        public void IsPointOnLine_StartingEdge_Horizontal_Test()
        {
            GameLogicSvc target = new GameLogicSvc();

            Wall w = new Wall() { Start = new Point() { X = 0, Y = 25 }, End = new Point() { X = 100, Y = 25 } };
            Point p = new Point() { X = 0, Y = 25 };

            bool isOnLine = target.isPointOnLine(p, w);

            Assert.AreEqual(true, isOnLine);
        }
Beispiel #7
0
        public void IsBetweenStartAndEnd_Valid_Vertical_Test()
        {
            GameLogicSvc target = new GameLogicSvc();

            Wall w = new Wall() { Start = new Point() { X = 10, Y = 10 }, End = new Point() { X = 10, Y = 20 } };
            Point p = new Point() { X = 10, Y = 10 };

            bool result = target.isBetweenStartAndEnd(p, w);

            Assert.AreEqual(true, result);
        }
Beispiel #8
0
        public void IsBetweenStartAndEnd_Invalid_Horizontal_Test()
        {
            GameLogicSvc target = new GameLogicSvc();

            Wall w = new Wall() { Start = new Point() { X = 10, Y = 10 }, End = new Point() { X = 20, Y = 10 } };
            Point p = new Point() { X = 9, Y = 10 };

            bool result = target.isBetweenStartAndEnd(p, w);

            Assert.AreEqual(false, result);
        }
Beispiel #9
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     var data = new Wall { Start = new FHVGame.Shared.Models.Game.Point(), End = new FHVGame.Shared.Models.Game.Point() };
     //gridWalls.Items.Add(data);
     ((IList)gridWalls.ItemsSource).Add(data);
 }
Beispiel #10
0
        internal bool isPointOnLine(Point p, Wall w)
        {
            int dxp = p.X - w.Start.X;
            int dyp = p.Y - w.Start.Y;

            int dxe = w.End.X - w.Start.X;
            int dye = w.End.Y - w.Start.Y;

            int cross = dxp * dye - dyp * dxe;

            if (cross != 0)
            {
                return false;
            }

            return isBetweenStartAndEnd(p, w);
        }
Beispiel #11
0
        internal bool isBetweenStartAndEnd(Point p, Wall w)
        {
            // check if p is greater than w.Start and smaller than w.End
            bool greaterStartSmallerEnd = p.X >= w.Start.X && p.Y >= w.Start.Y && p.X <= w.End.X && p.Y <= w.End.Y;
            // check if p is greater than w.End and smaller than w.Start
            bool greaterEndSmallerStart = p.X <= w.Start.X && p.Y <= w.Start.Y && p.X >= w.End.X && p.Y >= w.End.Y;

            return greaterEndSmallerStart || greaterStartSmallerEnd;
        }