Example #1
0
        public void TestMove()
        {
            GameObject GameObject = new GameObject();
              GameObject.whites = new List<Figure>();
              GameObject.blacks = new List<Figure>();
              King wKing = new King(GameObject, 1, 1, Color.white);
              Bishop wBish = new Bishop(GameObject, 3, 3, Color.white);
              King bKing = new King(GameObject, 7, 7, Color.black);
              Bishop bBish = new Bishop(GameObject, 5, 5, Color.black);
              GameObject.whites.Add(wKing);
              GameObject.blacks.Add(bKing);
              GameObject.blacks.Add(bBish);
              GameObject.whites.Add(wBish);

              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wBish.MoveFields.Count == 6);
              Assert.IsTrue(wBish.CanMoveToPosition(2, 4));
              Assert.IsTrue(wBish.CanMoveToPosition(1, 5));
              Assert.IsTrue(wBish.CanMoveToPosition(2, 2));
              Assert.IsTrue(wBish.CanMoveToPosition(4, 2));
              Assert.IsTrue(wBish.CanMoveToPosition(5, 1));
              Assert.IsTrue(wBish.CanMoveToPosition(4, 4));

              Assert.IsTrue(bBish.MoveFields.Count == 8);
              Assert.IsTrue(bBish.CanMoveToPosition(6, 6));
              Assert.IsTrue(bBish.CanMoveToPosition(6, 4));
              Assert.IsTrue(bBish.CanMoveToPosition(7, 3));
              Assert.IsTrue(bBish.CanMoveToPosition(8, 2));
              Assert.IsTrue(bBish.CanMoveToPosition(4, 4));
              Assert.IsTrue(bBish.CanMoveToPosition(4, 6));
              Assert.IsTrue(bBish.CanMoveToPosition(3, 7));
              Assert.IsTrue(bBish.CanMoveToPosition(2, 8));

              Assert.IsFalse(wBish.Move(2, 4));
              Assert.IsFalse(wBish.Move(1, 5));
              Assert.IsFalse(wBish.Move(4, 2));
              Assert.IsFalse(wBish.Move(5, 1));
              Assert.IsTrue(wBish.Move(2, 2));

              Assert.IsFalse(bBish.Move(6, 4));
              Assert.IsFalse(bBish.Move(7, 3));
              Assert.IsFalse(bBish.Move(8, 2));
              Assert.IsFalse(bBish.Move(4, 6));
              Assert.IsFalse(bBish.Move(3, 7));
              Assert.IsFalse(bBish.Move(2, 8));
              Assert.IsTrue(bBish.Move(4, 4));

              Assert.IsTrue(wBish.Move(4, 4));
              Assert.IsTrue(GameObject.blacks.Count == 1);
        }
Example #2
0
        public void TestTakeAndAttack()
        {
            GameObject GameObject = new GameObject();
              GameObject.whites = new List<Figure>();
              GameObject.blacks = new List<Figure>();
              King wKing = new King(GameObject, 2, 1, Color.white);
              Bishop wBish = new Bishop(GameObject, 3, 3, Color.white);
              King bKing = new King(GameObject, 8, 7, Color.black);
              Bishop bBish = new Bishop(GameObject, 5, 5, Color.black);
              GameObject.whites.Add(wKing);
              GameObject.blacks.Add(bKing);
              GameObject.blacks.Add(bBish);
              GameObject.whites.Add(wBish);

              GameObject.UpdateAllBeatFields();
              Assert.IsTrue(wBish.CanAttackPosition(2, 4));
              Assert.IsTrue(wBish.CanAttackPosition(1, 5));
              Assert.IsTrue(wBish.CanAttackPosition(1, 1));
              Assert.IsTrue(wBish.CanAttackPosition(2, 2));
              Assert.IsTrue(wBish.CanAttackPosition(4, 2));
              Assert.IsTrue(wBish.CanAttackPosition(5, 1));
              Assert.IsTrue(wBish.CanAttackPosition(4, 4));
              Assert.IsTrue(wBish.CanAttackPosition(5, 5));

              Assert.IsTrue(bBish.CanAttackPosition(6, 6));
              Assert.IsTrue(bBish.CanAttackPosition(7, 7));
              Assert.IsTrue(bBish.CanAttackPosition(8, 8));
              Assert.IsTrue(bBish.CanAttackPosition(6, 4));
              Assert.IsTrue(bBish.CanAttackPosition(7, 3));
              Assert.IsTrue(bBish.CanAttackPosition(8, 2));
              Assert.IsTrue(bBish.CanAttackPosition(4, 4));
              Assert.IsTrue(bBish.CanAttackPosition(3, 3));
              Assert.IsTrue(bBish.CanAttackPosition(4, 6));
              Assert.IsTrue(bBish.CanAttackPosition(3, 7));
              Assert.IsTrue(bBish.CanAttackPosition(2, 8));
        }
Example #3
0
        public GameObject()
        {
            for (sbyte i = 1; i <= 8; i++)
              {
            Pawn p1 = new Pawn(this, i, 7, Color.black);
            this.blacks.Add(p1);

            Pawn wp1 = new Pawn(this, i, 2, Color.white);
            this.whites.Add(wp1);
              }

              Bishop b1 = new Bishop(this, 3, 8, Color.black);
              this.blacks.Add(b1);

              Bishop b2 = new Bishop(this, 6, 8, Color.black);
              this.blacks.Add(b2);

              Bishop wb1 = new Bishop(this, 3, 1, Color.white);
              this.whites.Add(wb1);

              Bishop wb2 = new Bishop(this, 6, 1, Color.white);
              this.whites.Add(wb2);

              Rook r1 = new Rook(this, 1, 8, Color.black);
              this.blacks.Add(r1);

              Rook r2 = new Rook(this, 8, 8, Color.black);
              this.blacks.Add(r2);

              Rook wr1 = new Rook(this, 1, 1, Color.white);
              this.whites.Add(wr1);

              Rook wr2 = new Rook(this, 8, 1, Color.white);
              this.whites.Add(wr2);

              Knight kn1 = new Knight(this, 2, 8, Color.black);
              this.blacks.Add(kn1);

              Knight kn2 = new Knight(this, 7, 8, Color.black);
              this.blacks.Add(kn2);

              Knight wkn1 = new Knight(this, 2, 1, Color.white);
              this.whites.Add(wkn1);

              Knight wkn2 = new Knight(this, 7, 1, Color.white);
              this.whites.Add(wkn2);

              var q = new Queen(this, 4, 8, Color.black);
              this.blacks.Add(q);

              var wq = new Queen(this, 4, 1, Color.white);
              this.whites.Add(wq);

              var k = new King(this, 5, 8, Color.black);
              this.blacks.Add(k);

              var wk = new King(this, 5, 1, Color.white);
              this.whites.Add(wk);

              this.UpdateAllBeatFields();
        }
Example #4
0
 public bool Transform(sbyte x, sbyte y, FigureTypes type)
 {
     Figure p = this.GetFigureByXY(x, y);
       if (p.type != FigureTypes.Pawn)
     return false;
       Figure newFigure;
       switch (type)
       {
     case FigureTypes.Knight:
       newFigure = new Knight(this, p.field.x, p.field.y, p.color);
       break;
     case FigureTypes.Bishop:
       newFigure = new Bishop(this, p.field.x, p.field.y, p.color);
       break;
     case FigureTypes.Queen:
       newFigure = new Queen(this, p.field.x, p.field.y, p.color);
       break;
     case FigureTypes.Rook:
       newFigure = new Rook(this, p.field.x, p.field.y, p.color);
       break;
     default:
       return false;
       }
       if (p.color == Color.white)
       {
     this.whites.Remove(p);
     this.whites.Add(newFigure);
       }
       else
       {
     this.blacks.Remove(p);
     this.blacks.Add(newFigure);
       }
       this.UpdateAllBeatFields();
       this.IsGameOvered();
       return true;
 }
Example #5
0
 public bool Transform(FigureTypes figureTypes)
 {
     if ((field.y == 8 && color == Color.white) ||
       (field.y == 1 && color == Color.black))
       {
     Figure newFigure;
     switch (figureTypes)
     {
       case FigureTypes.Bishop:
     newFigure = new Bishop(GameObject, field.x, field.y, color);
     break;
       case FigureTypes.Knight:
     newFigure = new Knight(GameObject, field.x, field.y, color);
     break;
       case FigureTypes.Queen:
     newFigure = new Queen(GameObject, field.x, field.y, color);
     break;
       case FigureTypes.Rook:
     newFigure = new Rook(GameObject, field.x, field.y, color);
     break;
       default:
     return false;
     }
     GameObject.RemoveFigureByXY(field.x, field.y);
     if (color == Color.black)
       GameObject.blacks.Add(newFigure);
     else
       GameObject.whites.Add(newFigure);
     GameObject.UpdateAllBeatFields();
     return true;
       }
       return false;
 }