Thắc mắc 1 đoạn trong code game tetris java

Hi chào mọi người, em đang tìm hiểu về cách làm game tetris trên java và có tham khảo được một bài mẫu trên mạng. Nhưng em chưa hiểu lắm ở đoạn này:

private void setX(int index, int x) { coords[index][0] = x; }
    private void setY(int index, int y) { coords[index][1] = y; }
    public int x(int index) { return coords[index][0]; }
    public int y(int index) { return coords[index][1]; }

dẫn tới việc em không hiểu luôn đoạn dịch trái này ~

public Shape rotateLeft() {
         
        if (pieceShape == Tetrominoes.SquareShape)
            return this;
 
        Shape result = new Shape();
        result.pieceShape = pieceShape;
 
        for (int i = 0; i < 4; ++i) {
             
            result.setX(i, y(i));
            result.setY(i, -x(i));
        }
         
        return result;
    }

Bro nào có thể giải thích hộ em với.
Và bouns thêm 1 câu hỏi nữa là: Em muốn khi kết thúc game sẽ hiển thị bảng nhập tên player và show bảng điểm ở sql lên , thì cách thức làm như thế nào ạ.
Em biết là diễn đàn hạn chế hỏi bài nhưng mà em không biết hỏi ở đâu nữa ạ ~ Cảm ơn mọi người !

Đoạn này liên quan đến các đoạn code khác nx, nên là bạn phải post đầy đủ lên thì mọi người mới hiểu dc

import java.util.Random;
 
public class Shape {
 
    protected enum Tetrominoes { NoShape, ZShape, SShape, LineShape, 
               TShape, SquareShape, LShape, MirroredLShape };
 
    private Tetrominoes pieceShape;
    private int coords[][];
    private int[][][] coordsTable;
 
 
    public Shape() {
 
        coords = new int[4][2];
        setShape(Tetrominoes.NoShape);
    }
 
    public void setShape(Tetrominoes shape) {
 
         coordsTable = new int[][][] {
            { { 0, 0 },   { 0, 0 },   { 0, 0 },   { 0, 0 } },
            { { 0,-1 },   { 0, 0 },   {-1, 0 },   {-1, 1 } },
            { { 0,-1 },   { 0, 0 },   { 1, 0 },   { 1, 1 } },
            { { 0,-1 },   { 0, 0 },   { 0, 1 },   { 0, 2 } },
            { {-1, 0 },   { 0, 0 },   { 1, 0 },   { 0, 1 } },
            { { 0, 0 },   { 1, 0 },   { 0, 1 },   { 1, 1 } },
            { {-1,-1 },   { 0,-1 },   { 0, 0 },   { 0, 1 } },
            { { 1,-1 },   { 0,-1 },   { 0, 0 },   { 0, 1 } }
        };
 
        for (int i = 0; i < 4 ; i++) {
             
            for (int j = 0; j < 2; ++j) {
                 
                coords[i][j] = coordsTable[shape.ordinal()][i][j];
            }
        }
         
        pieceShape = shape;
    }
 
    private void setX(int index, int x) { coords[index][0] = x; }
    private void setY(int index, int y) { coords[index][1] = y; }
    public int x(int index) { return coords[index][0]; }
    public int y(int index) { return coords[index][1]; }
    public Tetrominoes getShape()  { return pieceShape; }
 
    public void setRandomShape() {
         
        Random r = new Random();
        int x = Math.abs(r.nextInt()) % 7 + 1;
        Tetrominoes[] values = Tetrominoes.values(); 
        setShape(values[x]);
    }
 
    public int minX() {
         
      int m = coords[0][0];
       
      for (int i=0; i < 4; i++) {
           
          m = Math.min(m, coords[i][0]);
      }
       
      return m;
    }
 
 
    public int minY() {
         
      int m = coords[0][1];
       
      for (int i=0; i < 4; i++) {
           
          m = Math.min(m, coords[i][1]);
      }
       
      return m;
    }
 
    public Shape rotateLeft() {
         
        if (pieceShape == Tetrominoes.SquareShape)
            return this;
 
        Shape result = new Shape();
        result.pieceShape = pieceShape;
 
        for (int i = 0; i < 4; ++i) {
             
            result.setX(i, y(i));
            result.setY(i, -x(i));
        }
         
        return result;
    }
 
    public Shape rotateRight() {
         
        if (pieceShape == Tetrominoes.SquareShape)
            return this;
 
        Shape result = new Shape();
        result.pieceShape = pieceShape;
 
        for (int i = 0; i < 4; ++i) {
 
            result.setX(i, -y(i));
            result.setY(i, x(i));
        }
         
        return result;
    }
}

file Shape.java, file này lưu thông tin về các khối gạch ạ

Mình chưa đọc full code nhưng đoạn code đầu post đại ý nó là nếu cái shape của cái object hiện tại là hình vuông, thì sẽ return thẳng cái object đó luôn, vì hình vuông xoay kiểu gì cũng là hình vuông
Nếu ko phải mình sẽ thực hiện ở dưới là tạo 1 cái object shape mới, set pieceShape của cái shape mới giống với cái object hiện tại rồi set lại X và Y của cái shape mới trong cái for loop, còn cụ thể set như nào thì bạn xem code của 2 hàm setX và setY

Em hiểu ý bác , nhưng mà đoạn set X, set Y em cũng chưa hiểu lắm nên mới dẫn tới ko hiểu đoạn đó đấy bác. Giải thích hộ em với T_T ~

ví dụ cho quay hình chữ T, sau khi chạy qua đoạn code xoay trái. Trong đồ họa máy tính thì trục y sẽ lộn ngược lại.

Em thông suốt được rồi, cảm ơn bác T_T em đi hỏi mấy chỗ luôn mà tới giờ mới hiểu. Cảm ơn rất nhiều luôn aj~

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?