예제 #1
0
파일: Map2d.cs 프로젝트: Lucasvo1/FHVGame
 public void InsertWall(Wall wall)
 {
     foreach (Wall w in walls)
     {
         if (wall.Equals(w))
         {
             return;
         }
     }
     walls.Add(wall);
 }
예제 #2
0
파일: Map2d.cs 프로젝트: Lucasvo1/FHVGame
        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;
        }
예제 #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);
        }
예제 #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);
            }
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
 }
예제 #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);
        }
예제 #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;
        }