Pièces échiquier [Fermé]

Signaler
Messages postés
16
Date d'inscription
jeudi 19 mai 2016
Statut
Membre
Dernière intervention
28 novembre 2016
-
je souhaiterais ajouter les Pieces du jeu d'echec sur mon tableau mais j'y arrive pas.J'ai aussi l'impression d'avoir repeté beaucoup de codes inutiles. voici mon code en entier.
x doit representer les colonnes, y les lignes, piece= LA PIECE et plaer si c le joueur 1 ou 2

public void drawPiece(int x, int y, int piece, int player) {


quelqu'un aurait il une idee? VOICI MON CODE COMPLET:

import java.awt.Color;

import acm.graphics.GLabel;
import acm.graphics.GRect;
import acm.program.GraphicsProgram;

public class MethodicalChessboard extends GraphicsProgram {

public static final int CELL_SIZE = 52;
    public static final int CHESS_FIELDS = 8;
    public static final int BOARD_EXTENT = CELL_SIZE * CHESS_FIELDS;
    public static final int BOARD_OFFSET = 50;

// Space for the board descriptions.
    public static final int DESCRIPTION_OFFSET = 5;
    public static final int OVERALL_OFFSET = BOARD_OFFSET + DESCRIPTION_OFFSET;

public void run() {
  setSize(OVERALL_OFFSET * 2 + BOARD_EXTENT, 
                OVERALL_OFFSET * 2 + BOARD_EXTENT);

for(int i = 0; i < CHESS_FIELDS; i++) {
            for(int j = 0; j < CHESS_FIELDS; j++) {
             Color BoardPieceColor = BoardPieceColor(i, CHESS_FIELDS);
             drawSquare(i,CHESS_FIELDS,BoardPieceColor);
            }
        }
 }

public void drawChessboard(){


for(int i = 0; i < CHESS_FIELDS; i++) {
                        for(int j = 0; j < CHESS_FIELDS; j++) {




// Calculate the position for the left description.
                GLabel leftNumber = new GLabel("" + (8 - i));
                leftNumber.setLocation(BOARD_OFFSET - leftNumber.getWidth() , 
                        OVERALL_OFFSET + CELL_SIZE * i + CELL_SIZE / 2 + leftNumber.getHeight() / 2);
                add(leftNumber);

// Calculate the position for the right description.            
                GLabel rightNumber = new GLabel("" + (8 - i));
                rightNumber.setLocation(OVERALL_OFFSET + BOARD_EXTENT + DESCRIPTION_OFFSET, 
                        OVERALL_OFFSET + CELL_SIZE * i + CELL_SIZE / 2 + leftNumber.getHeight() / 2);
                add(rightNumber);

// Calculate the position for the top description.
                GLabel topLetter = new GLabel("" + (char) ('A' + i));
                topLetter.setLocation(OVERALL_OFFSET + CELL_SIZE * i + CELL_SIZE / 2 - topLetter.getWidth() / 2, 
                        BOARD_OFFSET);
                add(topLetter);

// Calculate the position for the bottom description.
                GLabel bottomLetter = new GLabel("" + (char) ('A' + i));
                bottomLetter.setLocation(OVERALL_OFFSET + CELL_SIZE * i + CELL_SIZE / 2 - topLetter.getWidth() / 2, 
                        BOARD_OFFSET + BOARD_EXTENT + DESCRIPTION_OFFSET + bottomLetter.getHeight());
                add(bottomLetter);
              }
             }
}





public void drawSquare(int x, int y, Color color) {
 for(int i = 0; i < CHESS_FIELDS; i++) {
        for(int j = 0; j < CHESS_FIELDS; j++) {    

if ( (i + j) % 2 == 1 ) {
        GRect boardPiece = new GRect(OVERALL_OFFSET + j * CELL_SIZE,
                OVERALL_OFFSET + i * CELL_SIZE,
                CELL_SIZE, 
                CELL_SIZE);
        boardPiece.setColor(Color.LIGHT_GRAY);
        boardPiece.setFillColor(Color.LIGHT_GRAY);
        boardPiece.setFilled(true);
        add(boardPiece);

}
        }
 }
 }

public void drawPiece(int x, int y, int piece, int player) {
    for(int i = 0; i < CHESS_FIELDS; i++) {
           for(int j = 0; j < CHESS_FIELDS; j++) {    

if ( (i + j) % 2 == 1 ) {
    GRect boardPiece = new GRect(OVERALL_OFFSET + j * CELL_SIZE,
                  OVERALL_OFFSET + i * CELL_SIZE,
                  CELL_SIZE, 
                  CELL_SIZE);
          boardPiece.setColor(Color.BLACK);
          boardPiece.setFillColor(Color.LIGHT_GRAY);
          boardPiece.setFilled(true);
          add(boardPiece);

GLabel glabel = new GLabel("\u265C ", 400, 130);
   glabel.setFont("SansSerif-36");
   glabel.setColor(Color.RED);
   add(glabel);

GLabel glabel1 = new GLabel("\u265E ", 170, 130);
   add(glabel1);

GLabel glabel2 = new GLabel("\u265D ", 220, 130);
   add(glabel2);

GLabel glabel3 = new GLabel("\u265B ", 270, 130);
   add(glabel3);

GLabel glabel4 = new GLabel("\u265A ", 320, 130);
   add(glabel4);

GLabel glabel5 = new GLabel("\u265D ", 370, 130);
   add(glabel5);

GLabel glabel6 = new GLabel("\u265E ", 420, 130);
   add(glabel6);

GLabel glabel7 = new GLabel("\u265C ", 470, 130);
   add(glabel7);

GLabel glabel8 = new GLabel("\u265F ", 120, 180);
   add(glabel8);

GLabel glabel9 = new GLabel("\u265F ", 170, 180);
   add(glabel9);

GLabel glabel10 = new GLabel("\u265F ", 220, 180);
   add(glabel10);

GLabel glabel11 = new GLabel("\u265F ", 270, 180);
   add(glabel11);

GLabel glabel12 = new GLabel("\u265F ", 320, 180);
   add(glabel12);

GLabel glabel13 = new GLabel("\u265F ", 370, 180);
   add(glabel13);

GLabel glabel14 = new GLabel("\u265F ", 420, 180);
   add(glabel14);

GLabel glabel15 = new GLabel("\u265F ", 470, 180);
   add(glabel15);

// White
   GLabel glabel16 = new GLabel("\u2656 ", 120, 480);
   add(glabel16);

GLabel glabel17 = new GLabel("\u2658 ", 170, 480);
   add(glabel17);

GLabel glabel18 = new GLabel("\u2657 ", 220, 480);
   add(glabel18);

GLabel glabel19 = new GLabel("\u2655 ", 270, 480);
   add(glabel19);

GLabel glabel20 = new GLabel("\u2654 ", 320, 480);
   add(glabel20);

GLabel glabel21 = new GLabel("\u2657 ", 370, 480);
   add(glabel21);

GLabel glabel22 = new GLabel("\u2658 ", 420, 480);
   add(glabel22);

GLabel glabel23 = new GLabel("\u2656 ", 470, 480);
   add(glabel23);

GLabel glabel24 = new GLabel("\u2659 ", 120, 430);
   add(glabel24);

GLabel glabel25 = new GLabel("\u2659 ", 170, 430);
   add(glabel25);

GLabel glabel26 = new GLabel("\u2659 ", 220, 430);
   add(glabel26);

GLabel glabel27 = new GLabel("\u2659 ", 270, 430);
   add(glabel27);

GLabel glabel28 = new GLabel("\u2659 ", 320, 430);
   add(glabel28);

GLabel glabel29 = new GLabel("\u2659 ", 370, 430);
   add(glabel29);

GLabel glabel30 = new GLabel("\u2659 ", 420, 430);
   add(glabel30);

GLabel glabel31 = new GLabel("\u2659 ", 470, 430);
   add(glabel31);
    }

}
    }
  }



private Color BoardPieceColor(int i, int chessFields) {
  // TODO Auto-generated method stub
  return null;
 }





}