Beispiel #1
0
 public void TestVertexPosition()
 {
     Field field1 = new Field(3);
     Assert.AreEqual(field1.VertexPosition(3)[0], 1);
     Assert.AreEqual(field1.VertexPosition(3)[1], 0);
     Assert.AreEqual(field1.VertexPosition(8)[0], 2);
     Assert.AreEqual(field1.VertexPosition(8)[1], 2);
     Assert.AreEqual(field1.VertexPosition(4)[0], 1);
     Assert.AreEqual(field1.VertexPosition(4)[1], 1);
     Assert.AreEqual(field1.VertexPosition(2)[0], 0);
     Assert.AreEqual(field1.VertexPosition(2)[1], 2);
     Field field2 = new Field(5);
     Assert.AreEqual(field2.VertexPosition(17)[0], 3);
     Assert.AreEqual(field2.VertexPosition(17)[1], 2);
     Assert.AreEqual(field2.VertexPosition(5)[0], 1);
     Assert.AreEqual(field2.VertexPosition(5)[1], 0);
     Assert.AreEqual(field2.VertexPosition(9)[0], 1);
     Assert.AreEqual(field2.VertexPosition(9)[1], 4);
     Field field3 = new Field(7);
     Assert.AreEqual(field3.VertexPosition(17)[0], 2);
     Assert.AreEqual(field3.VertexPosition(17)[1], 3);
     Assert.AreEqual(field3.VertexPosition(5)[0], 0);
     Assert.AreEqual(field3.VertexPosition(5)[1], 5);
     Assert.AreEqual(field3.VertexPosition(9)[0], 1);
     Assert.AreEqual(field3.VertexPosition(9)[1], 2);
 }
Beispiel #2
0
 public void TestVertexNumber()
 {
     Field field1 = new Field(3);
     Assert.AreEqual(3, field1.VertexNumber(1, 0));
     Assert.AreEqual(8, field1.VertexNumber(2, 2));
     Field field2 = new Field(5);
     Assert.AreEqual(17, field2.VertexNumber(3, 2));
     Assert.AreEqual(5, field2.VertexNumber(1, 0));
     Assert.AreEqual(9, field2.VertexNumber(1, 4));
     Field field3 = new Field(7);
     Assert.AreEqual(17, field3.VertexNumber(2, 3));
     Assert.AreEqual(5, field3.VertexNumber(0, 5));
     Assert.AreEqual(9, field3.VertexNumber(1, 2));
 }
Beispiel #3
0
 public void TestSetWall()
 {
     Hero player = new Hero(2, 0, 10);
     Hero enemy = new Hero(2, 4, 10);
     Field field1 = new Field(5) { Hero1 = player, Hero2 = enemy };
     Wall wall1 = new Wall(0, 0, Logic.WallStyle.Vertical);
     Assert.AreEqual(true, field1.AddWallTest(0, 0, WallStyle.Vertical));
     Assert.AreEqual(true, field1.AddWallTest(1, 2, WallStyle.Horizontal));
     Assert.AreEqual(false, field1.AddWallTest(1, 1, WallStyle.Horizontal));
     Assert.AreEqual(true, field1.MoveHeroTest(player, 0, 1));
     Assert.AreEqual(false, field1.MoveHeroTest(player, 0, 1));
     Assert.AreEqual(true, field1.AddWallTest(0, 1, WallStyle.Vertical));
     Assert.AreEqual(false, field1.AddWallTest(0, 3, WallStyle.Vertical));
     field1.RemoveWall(0, 1, WallStyle.Vertical);
     Assert.AreEqual(true, field1.AddWallTest(0, 3, WallStyle.Vertical));
     field1.RemoveWall(0, 3, WallStyle.Vertical);
     Assert.AreEqual(true, field1.MoveHeroTest(player, -1, 0));
     Assert.AreEqual(true, field1.MoveHeroTest(player, 0, 1));
     Assert.AreEqual(true, field1.MoveHeroTest(player, 0, 1));
     Assert.AreEqual(true, field1.AddWallTest(1, 0, WallStyle.Horizontal));
     Assert.AreEqual(true, field1.AddWallTest(2, 3, WallStyle.Horizontal));
     Assert.AreEqual(false, field1.AddWallTest(2, 2, WallStyle.Vertical));
 }
Beispiel #4
0
        public void Create(IEngine engine)
        {
            if (engine == null) return;

            Engine = engine;
            Field = Engine.Field;
            Engine.PlayerSetWall += OnSetWall;
            Engine.PlayerMove += UpdatePos;
            Engine.PlayerChanged += UpdatePos;

            grid.Children.Clear();
            grid.ColumnDefinitions.Clear();
            grid.RowDefinitions.Clear();

            int n = Field.Dimension;
            int m = Field.Dimension;
            for (int j = 0; j < m - 1; ++j)
            {
                grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
                grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(16, GridUnitType.Pixel) });
            }
            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
            for (int i = 0; i < n - 1; ++i)
            {
                grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });
                grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(16, GridUnitType.Pixel) });
            }
            grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) });

            for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
            {
                Rectangle r = new Rectangle() { Fill = ((i + j) % 2 == 0) ? Brushes.LightSkyBlue : Brushes.LightSlateGray, Margin = new Thickness(-8) };
                grid.Children.Add(SetSell(r, i, j));
            #if DEBUG
                grid.Children.Add(SetSell(new Label() { Content = (i * n + j).ToString() }, i, j));
            #endif
            }

            for (int i = 0; i < n - 1; ++i)
                for (int j = 0; j < m - 1; ++j)
                {
                    int i0 = i;
                    int j0 = j;
                    Rectangle r = new Rectangle() { Fill = Brushes.Black, Margin = new Thickness(-1) };
                    r.MouseLeftButtonDown += (s, e) => Engine.PostSetWall(i0, j0, WallStyle.Horizontal);
                    r.MouseRightButtonDown += (s, e) => Engine.PostSetWall(i0, j0, WallStyle.Vertical);
                    Grid.SetRow(r, 1 + 2 * i);
                    Grid.SetColumn(r, 1 + 2 * j);
                    grid.Children.Add(r);
                }

            player1 = new Ellipse() { Fill = Brushes.IndianRed, Stroke = Brushes.Black };
            grid.Children.Add(SetSell(player1, Field.Hero1.Y, Field.Hero1.X));

            player2 = new Ellipse() { Fill = Brushes.DarkBlue, Stroke = Brushes.Black };
            grid.Children.Add(SetSell(player2, Field.Hero2.Y, Field.Hero2.X));

            arrowDown = new Rectangle() { Margin = new Thickness(10), Fill = Brushes.Yellow };
            arrowRight = new Rectangle() { Margin = new Thickness(10), Fill = Brushes.Yellow };
            arrowLeft = new Rectangle() { Margin = new Thickness(10), Fill = Brushes.Yellow };
            arrowUp = new Rectangle() { Margin = new Thickness(10), Fill = Brushes.Yellow };

            arrowDown.MouseDown += (s, e) => Engine.PostMove(0, +1);
            arrowUp.MouseDown += (s, e) => Engine.PostMove(0, -1);
            arrowLeft.MouseDown += (s, e) => Engine.PostMove(-1, 0);
            arrowRight.MouseDown += (s, e) => Engine.PostMove(+1, 0);

            UpdatePos(null, null);
        }
Beispiel #5
0
 public AbstractEngine()
 {
     Field = new Field(Constants.FieldSize) { Hero1 = player, Hero2 = enemy };
 }