Exemplo n.º 1
0
 public BlackPc(Player pl, Vector3 pos)
     : base(pl, pos)
 {
     color = new Vector3(0.2f);
     possMoves = new Vector[] { new Vector(-1, 1), new Vector(1, 1) };
     possAttacks = new Vector[] { new Vector(-2, 2), new Vector(2, 2) };
 }
Exemplo n.º 2
0
 public WhitePc(Player pl, Vector3 pos)
     : base(pl, pos)
 {
     color = new Vector3(1, 1, 0.9f);
     possMoves = new Vector[] { new Vector(-1, -1), new Vector(1, -1) };
     possAttacks = new Vector[] { new Vector(-2, -2), new Vector(2, -2) };
 }
Exemplo n.º 3
0
        public King(Player pl, Vector3 pos)
            : base(pl, pos)
        {
            possAttacks = new Vector[24];
            possMoves = new Vector[28];

            int m = 0;
            int i = 7;
            while (m < 28 && i > 0)
            {
                if (i != 1 && m < 24)
                {
                    possAttacks[m] = new Vector(-i, -i);
                    possAttacks[m + 1] = new Vector(i, i);
                    possAttacks[m + 2] = new Vector(-i, i);
                    possAttacks[m + 3] = new Vector(i, -i);
                }

                possMoves[m] = new Vector(-i, -i);
                possMoves[m + 1] = new Vector(i, i);
                possMoves[m + 2] = new Vector(-i, i);
                possMoves[m + 3] = new Vector(i, -i);

                m = m + 4;
                i--;
            }
        }
Exemplo n.º 4
0
        public Player(PlayerSettings p, int i)
        {
            if (p.name == null)
                name = "Player " + (i + 1);
            else
                name = p.name;

            nameTag = new Text3D(name, Font3D.getFont("arial"), null);

            if (p.avatar == null)
                avatar = Texture2D.FromStream(Program.game.GraphicsDevice, System.IO.File.OpenRead("default.png"));
            else
                avatar = p.avatar;

            cam = new Camera(new Vector3(0.7f, i == 1 ? 0 : MathHelper.Pi, 0), 80, Vector3.Zero, Vector3.Up);
            selection = new Vector(0, i == 1 ? 0 : 7);
            index = i;
        }
Exemplo n.º 5
0
        public void applyAction(Vector src, Vector dest)
        {
            if(isPossAttack(src, dest))
            {
                attackPc(src, dest);

                if (isMultipleAttack(dest))
                    attackAgain = dest;
                else
                    attackAgain = null;
            }
            else if (isPossMove(src, dest))
            {
                fRule();
                movePc(src, dest);
            }
            else
            {
                GamePlay.currPl.dest = null;
                throw new GameplayException("Invalid Action !");
            }
        }
Exemplo n.º 6
0
 public bool validateMove(Piece srcPc, Vector src, Vector possMove)
 {
     return isKingClear(possMove.stepBack(), src);
 }
Exemplo n.º 7
0
 public void validateSrcPc(Vector v)
 {
     Piece temp = tiles[v.x][v.y].p;
     if(temp == null)
         throw new GameplayException("The selected Tile is Empty !");
     if(!temp.isHis(GamePlay.currPl))
         throw new GameplayException("It's not your Piece !");
 }
Exemplo n.º 8
0
 public bool validateAttack(Piece srcPc, Vector src, Vector possAttack)
 {
     Vector tmp = findEnemy(possAttack, src); //Finds the enemy
     if(tmp != null) //If the enemy exists.
         return isKingClear(tmp.stepBack(), src); //Check if the path between enemy and king is clear.
     return false; //Else return false cause there is no enemy !
 }
Exemplo n.º 9
0
 public void validateDestPc(Vector v)
 {
     if (tiles[v.x][v.y].p != null)
         throw new GameplayException("The destination Tile is Occupied !");
 }
Exemplo n.º 10
0
        //Rule number (f) in the .pdf :)
        public void fRule()
        {
            Tile[] delete = new Tile[12]; //12 penalties at maximum.
            int count = 0;

            for(int i = 0; i < 8; i++)
                for(int j = 0; j < 8; j++)
                {
                    Piece tmpPc = tiles[i][j].p;
                    if(tmpPc != null && tmpPc.isHis(GamePlay.currPl))
                    {
                        Vector src = new Vector(i, j);
                        for(int k = 0; k < tmpPc.possAttacks.Length; k++)
                        {
                            Vector dest = Vector.add(src, tmpPc.possAttacks[k]);
                            if(dest.x>=0 && dest.x<=7 && dest.y>=0 && dest.y<=7 && isEmpty(dest)
                                && validateAttack(tmpPc, src, tmpPc.possAttacks[k]))
                                {
                                    delete[count] = tiles[i][j]; //add the tile containing the coward piece in an array.
                                    count++; //increment the number of cowards :D
                                    break; //to avoid penalizing the same piece twice.
                                }
                        }
                    }
                }

            //nullify the coward pieces !
            for(int i = 0; i < count; i++)
                delete[i].p = null;

            if (count != 0)
            {
                fruled = true; //a flag that should be true if at least one piece was penalized.
                attackAgain = null;
            }
        }
Exemplo n.º 11
0
        public void movePc(Vector src, Vector dest)
        {
            tiles[dest.x][dest.y].p = tiles[src.x][src.y].p;
            tiles[src.x][src.y].p = null;

            if (tiles[dest.x][dest.y].p != null)
                tiles[dest.x][dest.y].p.setTarget(dest);

            makeKing(dest);
        }
Exemplo n.º 12
0
        public virtual void getInput()
        {
            int delta = index == 0 ? 1 : -1;

            if (Input.isPressed(Keys.Up))
                selection.y -= delta;
            if (Input.isPressed(Keys.Down))
                selection.y += delta;
            if (Input.isPressed(Keys.Right))
                selection.x += delta;
            if (Input.isPressed(Keys.Left))
                selection.x -= delta;

            if (selection.x > 7)
                selection.x = 7;
            if (selection.x < 0)
                selection.x = 0;
            if (selection.y > 7)
                selection.y = 7;
            if (selection.y < 0)
                selection.y = 0;

            if (Input.isPressed(Keys.Enter))
            {
                if (src == null)
                {
                    GamePlay.board.validateSrcPc(selection);
                    src = selection.clone();
                }
                else
                    if (Vector.isEqual(src, selection))
                        src = null;
                    else
                    {
                        GamePlay.board.validateDestPc(selection);
                        dest = selection.clone();
                    }
            }
        }
Exemplo n.º 13
0
 public static Vector sub(Vector l, Vector m)
 {
     return new Vector(l.x - m.x, l.y - m.y);
 }
Exemplo n.º 14
0
        public bool isMultipleAttack(Vector src)
        {
            Piece srcPc = getPc(src);

            for (int i = 0; i < srcPc.possAttacks.Length; i++)
            {
                Vector dest = Vector.add(src, srcPc.possAttacks[i]);
                if (dest.x >= 0 && dest.x <= 7 && dest.y >= 0 && dest.y <= 7 && isEmpty(dest)
                    && validateAttack(srcPc, src, srcPc.possAttacks[i]))
                    return true;
            }

            return false;
        }
Exemplo n.º 15
0
 public bool isPossAttack(Vector src, Vector dest)
 {
     //do checking for possible attacks here ...
     Piece srcPc = tiles[src.x][src.y].p;
     for(int i = 0; i < srcPc.possAttacks.Length; i++)
         if(Vector.isEqual(Vector.add(src, srcPc.possAttacks[i]), dest))
             return validateAttack(srcPc, src, srcPc.possAttacks[i]);
     return false;
 }
Exemplo n.º 16
0
        //Checks if the path for the King is Clear.
        public bool isKingClear(Vector curr, Vector src)
        {
            if (curr.x == 0 && curr.y == 0) //Reached the attacking King ?
                return true;

            Vector add = Vector.add(curr, src);
            if (!isEmpty(add)) //Is something blocking the way ?
                return false;

            return true && isKingClear(curr.stepBack(), src);
        }
Exemplo n.º 17
0
 public bool isEmpty(Vector v)
 {
     return tiles[v.x][v.y].p == null;
 }
Exemplo n.º 18
0
 public Piece getPc(Vector v)
 {
     return tiles[v.x][v.y].p;
 }
Exemplo n.º 19
0
        public void attackPc(Vector src, Vector dest)
        {
            Vector enemyPos = Vector.add(findEnemy(Vector.sub(dest, src), src), src);
            tiles[enemyPos.x][enemyPos.y].killPc = true;

            movePc(src, dest);

            makeKing(dest);
        }
Exemplo n.º 20
0
 public static bool isEqual(Vector l, Vector m)
 {
     return (l.x == m.x) && (l.y == m.y);
 }
Exemplo n.º 21
0
 public bool isPossMove(Vector src, Vector dest)
 {
     Piece srcPc = tiles[src.x][src.y].p;
     for(int i = 0; i < srcPc.possMoves.Length; i++)
         if(Vector.isEqual(Vector.add(src, srcPc.possMoves[i]), dest))
             return validateMove(srcPc, src, srcPc.possMoves[i]);
     return false;
 }
Exemplo n.º 22
0
        public Vector findEnemy(Vector curr, Vector src)
        {
            if (curr.x == 0 && curr.y == 0) //Reached the attacking King ?
                return null;

            Vector add = Vector.add(curr, src); //it is the actual current position
            if (!isEmpty(add)) //if you found a piece
                if (!getPc(add).isHis(GamePlay.currPl)) //Found the enemy ?
                    return curr;
                else
                    return null; //Your Piece is blocking the way between the dest and enemy (if it existed)

            return findEnemy(curr.stepBack(), src);
        }
Exemplo n.º 23
0
 public void setTarget(Vector v)
 {
     moving = true;
     targetPos = new Vector3(v.x * 5, 0, v.y * 5);
     halfWay = (targetPos - currentPos) / 2f + currentPos;
 }
Exemplo n.º 24
0
        public bool isStuck()
        {
            for (int i = 0; i < 8; i++)
                for (int j = 0; j < 8; j++)
                {
                    Piece tmpPc = tiles[i][j].p;
                    if (tmpPc != null && tmpPc.isHis(GamePlay.currPl))
                    {
                        Vector src = new Vector(i, j);
                        for (int k = 0; k < tmpPc.possMoves.Length; k++)
                        {
                            Vector dest = Vector.add(src, tmpPc.possMoves[k]);
                            if (dest.x >= 0 && dest.x <= 7 && dest.y >= 0 && dest.y <= 7
                                    && tiles[dest.x][dest.y].p == null
                                    && validateMove(tmpPc, src, tmpPc.possMoves[k]))
                                return false;
                        }
                        for (int k = 0; k < tmpPc.possAttacks.Length; k++)
                        {
                            Vector dest = Vector.add(src, tmpPc.possAttacks[k]);
                            if (dest.x >= 0 && dest.x <= 7 && dest.y >= 0 && dest.y <= 7
                                    && tiles[dest.x][dest.y].p == null
                                    && validateAttack(tmpPc, src, tmpPc.possAttacks[k]))
                                return false;
                        }
                    }
                }

            return true;
        }
Exemplo n.º 25
0
 //Check for promotion to King and apply it
 public void makeKing(Vector v)
 {
     if (!isEmpty(v))
         tiles[v.x][v.y].p = getPc(v).promote(v.y);
 }
Exemplo n.º 26
0
 public static Vector add(Vector l, Vector m)
 {
     return new Vector(l.x + m.x, l.y + m.y);
 }