The Last Airbender - Aang

acmilan

Rabu, 02 Juni 2010

PEMBUATAN APLIKASI GAME CATUR

Catur merupakan sebuah permainan yang sudah tidak asing lagi bagi kita semua. Kita sudah mengetahui bagaimana cara bermain catur. Permainan catur pada masa sekarang ini tidak hanya dapat kita mainkan dengan menggunakan papan catur, melainkan juga kita dapat memainkannya dengan menggunakan komputer. Namun banyak dari kita sekarang tidak mengetahui bagaimana permainan catur itu dibuat pada komputer. Catur pada komputer dibuat dengan menggunakan coding (bahasa pemrograman).


Berikut saya jelaskan bagaimana coding (bahasa Pemrograman) yang digunakan untuk menjelaskan bagaimana “bidak-bidak” catur bisa bergerak atau bahkan untuk “memakan” lawannya. Dalam hal ini saya menggunakan bahasa pemrograman Java.

Soldier (pion)
package MainFrame.ChessFrame.players.Pieces;
import java.awt.Color;
import java.awt.Image;
import java.awt.Point;
import java.io.IOException;
public class Solider {
    /** Creates a new instance of Solider */
    private int  X,Y;
    private Point pixelPoint=new Point();
    private int pixelX,pixelY;
    private boolean havelife=true;
    private boolean movedbefore=false;
    private pieceIcon PieceIcon;
    private Point p=new Point();
    private Point old=new Point();
    private boolean myseen=false;
    public Solider(String NameIcon,int startX,int startY) {
        PieceIcon=new pieceIcon(NameIcon);
        X=startX;
        Y=startY;
        p.x=X;
        p.y=Y;
    }
    public Image returnPieceImage() {
        return PieceIcon.returnPieceIcon();
    }
    public boolean returnLife() {
        return  havelife ;
    }
    public int  returnX() {
        return X;
    }
    public void setPoint(Point newPoint) {
        old.x=p.x;
        old.y=p.y;
        X=p.x=newPoint.x;
        Y=p.y=newPoint.y;
        p.x=X;
        p.y=Y;
        movedbefore=true;
        myseen=false;
    }
    public Point returnOld() {
        return old;
    }
    public void setX(int newX) {
        X=newX;
        p.x=X;
    }
    public void setY(int newY) {
        Y=newY;
        p.y=Y;
    }
    public void setPixels(int newpixelX,int newpixelY) {
        pixelPoint.x=newpixelX;
        pixelPoint.y=newpixelY;
    }
    public int getPixelX() {
        return pixelX;
    }
    public int getPixelY() {
        return pixelY;
    }
    public Point getpixelPoint() {
        return  pixelPoint;
    }
    public int  returnY() {
        return Y;
    }
    public Point returnPostion() {
        return (Point)p.clone();
    }
    public boolean Inthispostion(int x,int y) {
        if(p.x==x&&p.y==y)
            return true;
        return false;
    }
    public boolean Canmove(int x, int y,String typeColor ) {
        if((typeColor.equals("black"))) {
            if((((y-1==Y)&&(x==(X)))) /*&&!Check_Solider_Sees(x,y)*/) {
            return true;
            } else if((((y-2==Y)&&(x==(X))))&&!movedbefore ) {
                return true;
            } else if((y-1==Y&&x+1==(X)||(y-1==Y&&x-1==(X)))&&myseen ) {
                return true;
            }
            else  return false;
        }
        else if (typeColor=="white") {
            if(((y+1==Y)&&(x==(X))) /*&&!Check_Solider_Sees(x,y)*/) {
                return true;
            } else if((((y+2==Y)&&(x==(X)))) &&!movedbefore) {
                return true;
            } else if((y+1==Y&&x+1==(X)||(y+1==Y&&x-1==(X)))&& myseen  ) {
                return true;
            }
            else
                return false;
        }
        return false;
    }
    public boolean PieceInMYway(int x, int y,Point othersPostion ,String typeColor ) {
        if(Y-y==2||Y-y==-2) {
            if((typeColor.equals("black"))) {
                if((((y-1==othersPostion.y)&&(x==(othersPostion.x))))&&!movedbefore ) {
                    return true;
                } else  return false;
            }
            else  if (typeColor.equals("white")) {
               
                if(((y+1==othersPostion.y)&&(x==(othersPostion.x)) &&!movedbefore)) {
                    return true;
                } else
                    return false;
            }
        }
       
        return false;
    }
    public void toOld(Point Old) {
        p.x=Old.x;
        p.y=Old.y; 
    }
    public void setMYseen(boolean newBoolean) {
        myseen=newBoolean;
    }
    public boolean returnMyseen() {
        return myseen;
    }
    public boolean setSeenbychecking(Point newP,String Color) {
        myseen=false;
        if((Color.equals("black"))) {
            if((newP.y-1==Y&&newP.x+1==(X)||(newP.y-1==Y&&newP.x-1==(X)))) {
             myseen=true;
                return true;
            } else return false;
        } else if(Color.equals("white")) {
            if((newP.y+1==Y&&newP.x+1==(X)||(newP.y+1==Y&&newP.x-1==(X)))) {
                myseen=true;
                return true;
            } else return false;
        }
        return false;
    }
    public Point GeneratePossible_Moves() {
        return new Point();
    }
    public String Tell_me() {
        return "Soldier= ("+p.x+','+p.y+")";
    }
}
logika si soldier disini sama juga untuk meload gambar terbaru posisi pion dan untuk melakukan cara pion memakan lawannya diama bila pion memakan jalannya bisa mengarah ke diagonal kiri atau kanan.



Castel  (Benteng)
package MainFrame.ChessFrame.players.Pieces;
 import java.awt.Image;
import java.awt.Point;
import java.io.IOException;
 public class Castle {
    private int  X,Y;
    private int pixelX,pixelY;
    private Point pixelPoint=new Point();
    private boolean havelife=true;
    private pieceIcon PieceIcon;
    private Point p=new Point();
    private Point old=new Point();
    public Castle(String NameIcon,int  startX,int startY) {
        PieceIcon=new pieceIcon(NameIcon);
        X=startX;
        Y=startY;
        p.x=X;
        p.y=Y;
    }
    public Image returnPieceImage() {
        return PieceIcon.returnPieceIcon();
    }
    public int  returnX() {
        X=p.x;
        return X;
    }
    public void setPixels(int newpixelX,int newpixelY) {
        pixelPoint.x=newpixelX;
        pixelPoint.y=newpixelY;
    }
    public int getPixelX() {
        return pixelX;
    }
    public int getPixelY() {
        return pixelY;
    }
    public Point getpixelPoint() {
        return  pixelPoint;
    }
    public int  returnY() {
        Y=p.y;
        return Y;
    }
    public void toOld(Point Old) {
        p.x=Old.x;
        p.y=Old.y;
    }
    public void setPoint(Point newPoint) {
        old.x=p.x;
        old.y=p.y;
        X=p.x=newPoint.x;
        Y=p.y=newPoint.y;
    }
    public void setX(int newX) {
        X=newX;
        p.x=newX;
    }
    public void setY(int newY) {
        Y=newY;
        p.y=newY;
    }
    public Point returnOld() {
        return old;
    }
    public Point returnPostion() {
        return (Point)p.clone();
    }
    public boolean returnLife() {
        return  havelife ;
    }
    public boolean Inthispostion(int x,int y) {
        if(p.x==x&&p.y==y)
            return true;
        return false;
    }
    public boolean Canmove(int x, int y) {
        if(((y==Y)&&(x>(X)||(x<(X))))) {
            return true;
        } else if((((y>Y)||(y
            return true;
        } else {
            return false;
        }
    }
    public boolean PieceInMYway(int x, int y,Point othersPostion) {
        int j=y;
        int i=x;
        if(((y==Y)&&(x>(X)||(x<(X))))) {
            if((X
                while( (i!=X+1)) {
                i--;
                if(((othersPostion.y)==j)&&((othersPostion.x==i)))//there Same Color piece
                {
                    return true;
                }
                }
            else  if((X>i)) {
                while( (i!=X-1)) {
                    i++;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i))) {
                        return true;
                    }
                }
            }
        } else if((((y>Y)||(y
            if((Y
                while((j!=Y+1)) {
                    j--;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i))) {
                        return true;
                    }
                }
            } else  if((Y>j)) {
                while((j!=Y-1)) {
                    j++;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i))) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    public boolean checkKing(int x, int y,Point othersPostion) {
        int j=y;
        int i=x;
        if(((y==Y)&&(x>(X)||(x<(X))))) {
            if((X
                while( (i!=X )) {
                i--;
                if(((othersPostion.y)==j)&&((othersPostion.x==i)))//there Same Color piece
                {
                    return true;
                }
                }
            else  if((X>i)) {
                while( (i!=X )) {
                    i++;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i))) {
                        return true;
                    }
                }
            }
        } else if((((y>Y)||(y
            if((Y
                while((j!=Y )) {
                    j--;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i))) {
                        return true;
                    }
                }
            } else  if((Y>j)) {
                while((j!=Y )) {
                    j++;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i))) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    public Point GeneratePossible_Moves() {
        return new Point();
    }
    public String Tell_me() {
        return "Castle= ("+p.x+','+p.y+")";
    }
}
Pada Castel (Benteng) logikanya diatas adalah untuk menggerakkan benteng berjalan lurus ke arah vertikal dan Horizontal. Selain itu koding di atas bertujuan untuk meload gambar ke posisi terbaru.



Horse (kuda)
package MainFrame.ChessFrame.players.Pieces;
 import java.awt.Image;
import java.awt.Point;
import java.io.IOException;
 public class Horse {
    /** Creates a new instance of Horse */
    private int  X,Y;
    private Point pixelPoint=new Point();
    private int pixelX,pixelY;
    private boolean havelife=true;
    private Point old=new Point();
    private pieceIcon PieceIcon;
    private Point p=new Point();
    public Horse(String NameIcon,int startX,int startY) {
        PieceIcon=new pieceIcon(NameIcon);
        X=startX;
        Y=startY;
        p.x=X;
        p.y=Y;
    }
    public Point returnPostion() {
        return (Point)p.clone();
    }
    public Image returnPieceImage() {
        return PieceIcon.returnPieceIcon();
    }
    public int  returnX() {
        return X;
    }
    public void setPoint(Point newPoint) {
        old.x=p.x;
        old.y=p.y;
        X=p.x=newPoint.x;
        Y=p.y=newPoint.y;
    }
    public Point returnOld() {
        return (Point)old.clone();
    }
    public void setPixels(int newpixelX,int newpixelY) {
        pixelPoint.x=newpixelX;
        pixelPoint.y=newpixelY;
    }
    public int getPixelX() {
        return pixelX;
    }
    public int getPixelY() {
        return pixelY;
    }
    public Point getpixelPoint() {
        return  pixelPoint;
    }
    public void setX(int newX) {
        X=newX;
        p.x=X;
    }
    public void setY(int newY) {
        Y=newY;
        p.y=Y;
    }
    public int  returnY() {
        return Y;
    }
    public boolean returnLife() {
        return  havelife ;
    }
    public boolean Inthispostion(int x,int y) {
        if(p.x==x&&p.y==y)
            return true;
        return false;
    }
    public void toOld(Point Old) {
        p.x=Old.x;
        p.y=Old.y;
    }
    public boolean Canmove(int x, int y) {
        if((x+1==X)&&(y+2==Y)||(x+1==X)&&(y-2==Y)||(x-1==X)&&(y+2==Y)||(x-1==X)&&(y-2==Y)||(x+2==X)&&(y+1==Y)
        ||(x+2==X)&&(y-1==Y)||(x-2==X)&&(y+1==Y)||(x-2==X)&&(y-1==Y)) {
            return true;
        } else {
            return false;}
    }
    public Point GeneratePossible_Moves() {
        return new Point();
    }
    public String Tell_me() {
        return "Horse= ("+p.x+','+p.y+")";
    }
}

Disini logika  sikuda merupakan paling unik karena kuda bergerak berbentuk "L".  Sama seperti yang lain di sini juga untuk meload gambar posisi terbatu si kuda.



Elephent (Peluncur atau Rencong)
 package MainFrame.ChessFrame.players.Pieces;
 import java.awt.Image;
import java.awt.Point;
import java.io.IOException;
 public class Elephent
{
    /** Creates a new instance of Elephent */
    private int  X,Y;
    private Point pixelPoint=new Point();
    private int pixelX,pixelY;
    private boolean havelife=true;
    private pieceIcon PieceIcon;
    private Point p=new Point();
    private Point old=new Point();
    public Elephent(String NameIcon,int startX,int startY)
    {
        PieceIcon=new pieceIcon(NameIcon);
        X=startX;
        Y=startY;
        p.x=X;
        p.y=Y;
    }
    public Point returnPostion()
    {
        return (Point)p.clone();
    }
    public Image returnPieceImage()
    {
        return PieceIcon.returnPieceIcon();
    }
    public int  returnX()
    {
        return X;
    }
    public void setPoint(Point newPoint)
    {
        old.x=p.x;
        old.y=p.y;
        p.x=newPoint.x;
        p.y=newPoint.y;
        X=p.x;
        Y=p.y;
    }
    public void setX(int newX)
    {
        X=newX;
        p.x=newX;
    }
    public Point returnOld()
    {
        return old;
    }
    public void setPixels(int newpixelX,int newpixelY)
    {
        pixelPoint.x=newpixelX;
        pixelPoint.y=newpixelY;
    }
    public int getPixelX()
    {
        return pixelX;
    }
    public void toOld(Point Old)
    {
        p.x=Old.x;
        p.y=Old.y;
    }
    public int getPixelY()
    {
        return pixelY;
    }
    public Point getpixelPoint()
    {
        return  pixelPoint;
    }
    public void setY(int newY)
    {
        Y=newY;
        p.y=Y;
    }
    public int  returnY()
    {
        return Y;
    }
    public boolean returnLife()
    {
        return  havelife ;
    }
    public boolean Inthispostion(int x,int y)
    {
        if(p.x==x&&p.y==y)
            return true;
        return false;
    }
    public boolean Canmove(int x, int y)
    {
        int j=y;
        int i=x;
        if((x-y)==(X-Y))
        {
            return true;
        }
        //////////////////////////////////////////////////////////////////////////////////////////
        else if((x+y)==(X+Y))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public boolean PieceInMYway(int x, int y,Point othersPostion)
    {
        int j=y;
        int i=x;
        if((x-y)==(X-Y))
        {
            if(x>X&&y>Y)
            {
                while((j!=Y+1)&&(i!=X+1))
                {
                    j--;i--;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
            else if(x
                while((j!=Y-1)&&(i!=X-1))
                {
                j++;i++;
                if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                {
                    return true;
                }
                }
        }
        else if(((x+y))==((X+Y)))
        {
            if((Xj))
            {
                while(((j!=Y-1))&&((i!=X+1)))
                {
                    j++;i--;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
            else  if((X>i)&&(Y
            {
                while((j!=X+1)&&(i!=X-1))
                {
                    j--;i++;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    public boolean checkKing(int x, int y,Point othersPostion)
    {
        int j=y;
        int i=x;
        if((x-y)==(X-Y))
        {
            if(x>X&&y>Y)
            {
                while((j!=Y )&&(i!=X ))
                {
                    j--;i--;
                   
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
            else if(x
                while((j!=Y )&&(i!=X ))
                {
                j++;i++;
                if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                {
                    return true;
                }
                
                }
        }
        else if(((x+y))==((X+Y)))
        {
            if((Xj))
            {
                while(((j!=Y ))&&((i!=X )))
                {
                    j++;i--;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
            else  if((X>i)&&(Y
            {
                while((j!=X )&&(i!=X ))
                {
                    j--;i++;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
   
    public Point GeneratePossible_Moves()
    {
        return new Point();
    }
    public String Tell_me()
    {
        return "Elephent= ("+p.x+','+p.y+")";
    }
}
Disini pada Peluncur digambarkan bagaimana si peluncur bisa berjalan miring dan sama seperti yg lain logika diatas juga berfungsi untuk meload gambar ke posisi terakhir.



Queen (Ratu)
package MainFrame.ChessFrame.players.Pieces;
 import java.awt.Image;
import java.awt.Point;
import java.io.IOException;
 public class Queen
{
    /** Creates a new instance of Queen */
    private int  X,Y;
    private Point pixelPoint=new Point();
    private int pixelX,pixelY;
    private boolean havelife=true;
    private pieceIcon PieceIcon;
    private Point p=new Point();
    private Point old=new Point();
    public Queen(String NameIcon,int startX,int startY)
    {
        PieceIcon=new pieceIcon(NameIcon);
        X=startX;
        Y=startY;
        p.x=X;
        p.y=Y;
    }
    public Image returnPieceImage()
    {
        return PieceIcon.returnPieceIcon();
    }
    public Point returnPostion()
    {
        return (Point)p.clone();
    }
    public int  returnX()
    {
        return X;
    }
    public void setPixels(int newpixelX,int newpixelY)
    {
        pixelPoint.x=newpixelX;
        pixelPoint.y=newpixelY;
    }
    public int getPixelX()
    {
        return pixelX;
    }
    public int getPixelY()
    {
        return pixelY;
    }
    public Point getpixelPoint()
    {
        return  pixelPoint;
    }
    public int  returnY()
    {
        return Y;
    }
    public void setPoint(Point newPoint)
    {
        old.x=p.x;
        old.y=p.y;
        X=p.x=newPoint.x;
        Y=p.y=newPoint.y;
    }
    public void setX(int newX)
    {
        X=newX;
        p.x=X;
    }
    public Point returnOld()
    {
        return old;
    }
    public void setY(int newY)
    {
        Y=newY;
        p.y=Y;
    }
    public void toOld(Point Old)
    {
        p.x=Old.x;
        p.y=Old.y;
    }
    public boolean returnLife()
    {
        return  havelife ;
    }
    public boolean Inthispostion(int x,int y)
    {
        if(p.x==x&&p.y==y)
            return true;
        return false;
    }
    public boolean Canmove(int x, int y)
    {
        if(((y==Y)&&(x>(X)||(x
        {
            return true;
        }
        else if((((y>Y)||(y
        {
            return true;
        }
        else   if((x-y)==(X-Y))
        {
            return true;
        }
        else if((x+y)==(X+Y))
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public boolean PieceInMYway(int x, int y,Point othersPostion)
    {
        int j=y;
        int i=x;
        if(((y==Y)&&(x>(X)||(x<(X)))))
        {
            if((X
                while( (i!=X+1))
                {
                i--;
                if(((othersPostion.y)==j)&&((othersPostion.x==i)))//there Same Color piece
                {
                    return true;
                }
                }
            else  if((X>i))
            {
                while( (i!=X-1))
                {
                    i++;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
        }
        else if((((y>Y)||(y
        {
            if((Y
            {
                while((j!=Y+1))
                {
                    j--;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
            else  if((Y>j))
            {
                while((j!=Y-1))
                {
                    j++;
                   
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
               
            }
        }
        else   if((x-y)==(X-Y))
        {
            if(x>X&&y>Y)
            {
                while((j!=Y+1)&&(i!=X+1))
                {
                    j--;i--;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
            else if(x
                while((j!=Y-1)&&(i!=X-1))
                {
                j++;i++;
                if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                {
                    return true;
                }
                }
        }
        else if((x+y)==(X+Y))
        {
            if((Xj))
            {
                while((j!=Y-1)&&(i!=X+1))
                {
                    j++;i--;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }           
            else     if((X>i)&&(Y
            {
                while((j!=Y+1)&&(i!=X-1))
                {
                    j--;i++;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    public boolean checkKing(int x, int y,Point othersPostion)
    {
        int j=y;
        int i=x;
        if(((y==Y)&&(x>(X)||(x<(X)))))
        {
            if((X
                while( (i!=X ))
                {
                i--;
                if(((othersPostion.y)==j)&&((othersPostion.x==i)))//there Same Color piece
                {
                    return true;
                }
                }
            else  if((X>i))
            {
                while( (i!=X ))
                {
                    i++;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
        }
        else if((((y>Y)||(y
        {
            if((Y
            {
                while((j!=Y ))
                {
                    j--;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
            else  if((Y>j))
            {
                while((j!=Y ))
                {
                    j++;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
        }
        else   if((x-y)==(X-Y))
        {
            if(x>X&&y>Y)
            {
                while((j!=Y )&&(i!=X ))
                {
                    j--;i--;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
            else if(x
                while((j!=Y  )&&(i!=X ))
                {
                j++;i++;
                if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                {
                    return true;
                }
                }
        }
        else if((x+y)==(X+Y))
        {
            if((Xj))
            {
                while((j!=Y )&&(i!=X ))
                {
                    j++;i--;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
            else     if((X>i)&&(Y
            {
                while((j!=Y )&&(i!=X ))
                {
                    j--;i++;
                    if(((othersPostion.y)==j)&&((othersPostion.x==i)))
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    public Point GeneratePossible_Moves()
    {
        return new Point();
    }
    public String Tell_me()
    {
        return "Queen= ("+p.x+','+p.y+")";
    }
}
logik queen disini sama untuk meload gambar dimana queen berada bila di gerakkan. Terdapat metode gerak yang berguna untuk menggerakkan queen yang dimana Queen bisa bergerak ke arah mana saja dan bisa memakan apa saja.



King (Raja)
package MainFrame.ChessFrame.players.Pieces;
import java.awt.Image;
import java.awt.Point;
import java.io.IOException;
 public class king
{
    /** Creates a new instance of king */
    private int  X,Y;
    private Point pixelPoint=new Point();
    private int pixelX,pixelY;
    private boolean havelife=true;
    private pieceIcon PieceIcon;
    private Point old=new Point();
    private Point p=new Point();
    public king(String NameIcon,int startX,int startY)
    {
        PieceIcon=new pieceIcon(NameIcon);
        X=startX;
        Y=startY;
        p.x=X;
        p.y=Y;
    }
    public Image returnPieceImage()
    {
        return PieceIcon.returnPieceIcon();
    }
    public Point returnPostion()
    {
        return  (Point)p.clone();
    }
    public int  returnX()
    {
        X=p.x;
        return X;
    }
    public void setPixels(int newpixelX,int newpixelY)
    {
        pixelPoint.x=newpixelX;
        pixelPoint.y=newpixelY;
    }
    public int getPixelX()
    {
        return pixelX;
    }
    public int getPixelY()
    {
        return pixelY;
    }
    public Point getpixelPoint()
    {
        return  pixelPoint;
    }
    public int  returnY()
    {
        Y=p.y;
        return Y;
    }
    public void setPoint(Point newPoint)
    {
        old.x=p.x;
        old.y=p.y;
        p.x=newPoint.x;
        p.y=newPoint.y;
        X=p.x;
        Y=p.y;
    }
    public void toOld(Point Old)
    {
        p.x=Old.x;
        p.y=Old.y;
    }
    public Point returnOld()
    {
        return old;
    }
    public void setX(int newX)
    {
        X=newX;
        p.x=X;
    }
    public void setY(int newY)
    {
        Y=newY;
        p.y=Y;
    }
    public boolean Inthispostion(int x,int y)
    {
        if(p.x==x&&p.y==y)
            return true;//cant kill the king anymore;
        return false;
    }
    public boolean returnLife()
    {
        return  havelife ;
    }
    public boolean Canmove(int x, int y)
    {
        if(((y==Y)&&(x==(X-1)))||((y==Y-1)&&(x==(X+1)))
        ||((y==Y-1)&&(x==(X-1)))||((y==Y+1)&&(x==(X+1)))
        ||(((y==Y+1)&&x==(X-1)))||((y==Y)&&(x==(X+1)))
        ||((y==Y-1)&&x==((X)))||((y==Y+1)&&(x==(X))))
        {
            return true;
        }
        return false;
    }
    public Point GeneratePossible_Moves()
    {
        return new Point();
    }
    public String Tell_me()
    {
        return "King= ("+p.x+','+p.y+")";
    }
}

Disini letak logika bagaimana jalannya king. logika yang terdapat di sini adalah untuk melakukan pergerakan dan meload gambar king dimana seharusnya king berada dan bila king dalam keadaan check/skak maka bagian yang lain tidak dapat di gerakkan harus menyelamatkan king dahulu.

Begitulah bagaimana cara pergerakan “Bidak-bidak” Catur bergerak. Yang apabila kita ingin membuat caturnya keseluruhan kita tinggal menambahkan beberapa hal lain seperti penambahan frame atau bahkan menggunakan waktu. Tetapi untuk coding pergerakannya bisa menggunakan coding diatas dalam pemrograman Java.


Berikut merupakan contoh program catur setelah di masukkan frame dan ditambahan waktu dan aksesoris lainnya pendukung permainan.


Gambar pada saat aplikasi dijalankan:






Gambar dimana Aplikasi memulai permainan baru dengan dua pemain :






Gambar dimana proses awal permainan catur baru dimainkan :






Gambar pada saat permainan berakhir atau Check Mate :








Selamat mencoba membuat aplikasi permainan anda sendiri dengan menggunakan kreasi-kreasi unik lainnya.


  Rizal Darmawan
  50407739
  3IA07
 

Pengikut gw

kursor