public void CanCreateFromPositionAndSize()
        {
            var pos    = new Position2d(1, 2);
            var size   = new Size2d(3, 4);
            var anchor = Anchor2d.Center;

            var rect = new Rect2d(pos, size);

            DolphAssert.EqualF(pos.X, rect.X);
            DolphAssert.EqualF(pos.Y, rect.Y);
            DolphAssert.EqualF(size.Width, rect.Width);
            DolphAssert.EqualF(size.Height, rect.Height);

            rect = new Rect2d(pos, size, anchor);
            DolphAssert.EqualF(pos.X, rect.X);
            DolphAssert.EqualF(pos.Y, rect.Y);
            DolphAssert.EqualF(size.Width, rect.Width);
            DolphAssert.EqualF(size.Height, rect.Height);
            Assert.Equal(anchor, rect.Origin.Anchor);

            rect = new Rect2d(pos, size, new Origin2d(anchor));
            DolphAssert.EqualF(pos.X, rect.X);
            DolphAssert.EqualF(pos.Y, rect.Y);
            DolphAssert.EqualF(size.Width, rect.Width);
            DolphAssert.EqualF(size.Height, rect.Height);
            Assert.Equal(anchor, rect.Origin.Anchor);
        }
 public void PutCheese(Position2d position, GameObject button)
 {
     if (position.x == mousePosition.x && position.y == mousePosition.y) {
         Mouse.showUnreachable ();
     } else if (position.x != mousePosition.x && position.y != mousePosition.y) {
         Mouse.showUnreachable ();
     } else {
         Position2d newPos = new Position2d (mousePosition.x, mousePosition.y);
         Position2d positionChange = new Position2d (0, 0);
         if (mousePosition.x < position.x) {
             positionChange.x = 1;
         } else if (mousePosition.x > position.x) {
             positionChange.x = -1;
         } else if (mousePosition.y < position.y) {
             positionChange.y = 1;
         } else {
             positionChange.y = -1;
         }
         do {
             newPos.AddLocal (positionChange);
         } while(!Landscape [newPos.x, newPos.y].Equals (GT.WAL) && !(newPos.x == position.x && newPos.y == position.y));
         if ((newPos.x == position.x && newPos.y == position.y)) {
             Mouse.targetPosition = IntToFloat (newPos);
             mousePosition = newPos;
             this.ActivateButtons (false);
             PutCheese (button);
             RemainingCheese--;
             cheeseTextField.text = "" + RemainingCheese;
         } else {
             Mouse.showUnreachable ();
         }
     }
 }
 public Vector3 Move(DirectionEnum direction)
 {
     Position2d newPos = new Position2d (playerPosition.x, playerPosition.y);
     Position2d positionChange = new Position2d (0, 0);
     switch (direction) {
     case DirectionEnum.NORTH:
         positionChange.x = -1;
         break;
     case DirectionEnum.EAST:
         positionChange.y = 1;
         break;
     case DirectionEnum.SOUTH:
         positionChange.x = 1;
         break;
     case DirectionEnum.WEST:
         positionChange.y = -1;
         break;
     default:
         throw new System.ArgumentOutOfRangeException ();
     }
     do {
         newPos.AddLocal (positionChange);
     } while (posInBounds (newPos)
              && Landscape [newPos.x, newPos.y].Equals (GT.__I));
     if (!posInBounds (newPos) || Landscape [newPos.x, newPos.y].Equals (GT.WAL)) {
         newPos.AddLocal (positionChange.negateLocal ());
     }
     playerPosition = newPos;
     return IntToFloat (newPos);
 }
        public SpriteSheet(string name, Size2d size, Position2d origin, int columns, int rows, int columnPadding, int rowPadding)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException($"{nameof(SpriteSheet)} name is required.");
            }

            this.Name = name;
            var frames = new List <Rect2d>(columns * rows);

            for (var r = 0; r < rows; r++)
            {
                for (var c = 0; c < columns; c++)
                {
                    float x = origin.X + (c * size.Width) + (c * columnPadding);
                    float y = origin.Y + (r * size.Height) + (r * rowPadding);
                    frames.Add(new Rect2d(x, y, size.Width, size.Height));
                }
            }

            if (frames.Count == 0)
            {
                throw new InvalidOperationException($"Cannot create a {nameof(SpriteSheet)} with no frames.");
            }

            this.Frames = frames;
        }
        public void CanConvertToVector()
        {
            var pos = new Position2d(1, 2);
            var vec = pos.ToVector();

            DolphAssert.EqualF(pos.X, vec.X);
            DolphAssert.EqualF(pos.Y, vec.Y);
        }
        public void TestNegative(float x1, float y1, float x2, float y2)
        {
            var pos = new Position2d(x1, y1);

            pos = -pos;

            DolphAssert.EqualF(x2, pos.X);
            DolphAssert.EqualF(y2, pos.Y);
        }
        public void CanShiftPosition(float x1, float y1, float x2, float y2, float x3, float y3)
        {
            var pos = new Position2d(x1, y1);

            pos.Shift(x2, y2);

            DolphAssert.EqualF(x3, pos.X);
            DolphAssert.EqualF(y3, pos.Y);
        }
        public void CanMoveToPosition()
        {
            var pos = new Position2d(1, 2);

            pos.MoveTo(3, 4);

            DolphAssert.EqualF(3, pos.X);
            DolphAssert.EqualF(4, pos.Y);
        }
        public void TestHashCode()
        {
            var pos1 = new Position2d(1, 2);
            var pos2 = new Position2d(1, 2);

            Assert.Equal(pos1.GetHashCode(), pos2.GetHashCode());

            pos2.Shift(1, 1);

            Assert.NotEqual(pos1.GetHashCode(), pos2.GetHashCode());
        }
 public Vector3 getStartPosition()
 {
     for (int i = 0; i < Landscape.GetLength (0); i++) {
         for (int j = 0; j < Landscape.GetLength (1); j++) {
             if (Landscape [i, j].Equals (GT.SRT)) {
                 Position2d pos = new Position2d (i, j);
                 mousePosition = pos;
                 return IntToFloat (pos);
             }
         }
     }
     throw new ArgumentException ("no Start defined");
 }
        public void TestSubtract(float x1, float y1, float x2, float y2, float x3, float y3)
        {
            var pos = new Position2d(x1, y1);

            pos -= new Position2d(x2, y2);

            DolphAssert.EqualF(x3, pos.X);
            DolphAssert.EqualF(y3, pos.Y);

            pos  = new Position2d(x1, y1);
            pos -= new Vector2d(x2, y2);

            DolphAssert.EqualF(x3, pos.X);
            DolphAssert.EqualF(y3, pos.Y);
        }
        public void TestEquality(float x, float y)
        {
            var pos1 = new Position2d(x, y);
            var pos2 = new Position2d(x, y);

            Assert.True(pos1 == pos2);
            Assert.True(pos1.Equals(pos2));

            pos1.X += Constants.FloatTolerance / 10;

            Assert.True(pos1 == pos2);
            Assert.True(pos1.Equals(pos2));

            pos1.X += Constants.FloatTolerance * 10;

            Assert.False(pos1 == pos2);
            Assert.False(pos1.Equals(pos2));
        }
 public void click(Position2d position)
 {
     PlayClickSound ();
     switchLight (position);
     Position2d up = new Position2d (position.x - 1, position.y);
     switchIfPresent (up);
     Position2d down = new Position2d (position.x + 1, position.y);
     switchIfPresent (down);
     Position2d left = new Position2d (position.x, position.y - 1);
     switchIfPresent (left);
     Position2d right = new Position2d (position.x, position.y + 1);
     switchIfPresent (right);
     bool on = true;
     foreach (GameObject light in lights) {
         if (!IsOn (light)) {
             on = false;
             break;
         }
     }
     if (on) {
         won = true;
         OnWin ();
     }
 }
Exemple #14
0
 public static Vector2 ToVector2(this Position2d position)
 {
     return(new Vector2(position.X, position.Y));
 }
Exemple #15
0
 public void SetButtonsActive(bool b)
 {
     if (b) {
         Position2d up = new Position2d (playerPosition.x - 1, playerPosition.y);
         if (posInBounds (up) && !Landscape [up.x, up.y].Equals (GT.WAL)) {
             NorthButton.SetActive (true);
         }
         Position2d down = new Position2d (playerPosition.x + 1, playerPosition.y);
         if (posInBounds (down) && !Landscape [down.x, down.y].Equals (GT.WAL)) {
             SouthButton.SetActive (true);
         }
         Position2d left = new Position2d (playerPosition.x, playerPosition.y - 1);
         if (posInBounds (left) && !Landscape [left.x, left.y].Equals (GT.WAL)) {
             WestButton.SetActive (true);
         }
         Position2d right = new Position2d (playerPosition.x, playerPosition.y + 1);
         if (posInBounds (right) && !Landscape [right.x, right.y].Equals (GT.WAL)) {
             EastButton.SetActive (true);
         }
     } else {
         NorthButton.SetActive (false);
         SouthButton.SetActive (false);
         WestButton.SetActive (false);
         EastButton.SetActive (false);
     }
 }
 void switchIfPresent(Position2d up)
 {
     if (boundsCheck (up)) {
         switchLight (up);
     }
 }
 void switchLight(Position2d position)
 {
     if (won) {
         return;
     }
     Light l = lights [position.x, position.y].GetComponent<Light> ();
     l.On = !l.On;
     lights [position.x, position.y].GetComponent<SpriteRenderer> ().color = l.On ? Color.yellow : Color.gray;
 }
 bool boundsCheck(Position2d pos)
 {
     return pos.x >= 0 && pos.y >= 0 && pos.x < lights.GetLength (0) && pos.y < lights.GetLength (1);
 }
 public SpriteSheet(string name, Size2d size, Position2d origin, int columns, int rows)
     : this(name, size, origin, columns, rows, 0, 0)
 {
 }
 public void AddLocal(Position2d add)
 {
     this.x += add.x;
     this.y += add.y;
 }
 static Vector3 IntToFloat(Position2d pos)
 {
     return IntToFloat (pos.x, pos.y);
 }
Exemple #22
0
 bool posInBounds(Position2d newPos)
 {
     return newPos.x >= 0 && newPos.y >= 0 && newPos.x < Landscape.GetLength (0) && newPos.y < Landscape.GetLength (1);
 }
Exemple #23
0
 /// <summary>
 /// Creates an entity and places it at the provided position.
 /// </summary>
 public Entity(Position2d position)
 {
     this.Space = new Rect2d(position, Size2d.Zero);
 }
Exemple #24
0
 public static Point ToPoint(this Position2d position)
 {
     return(new Point((int)position.X, (int)position.Y));
 }