src/de/uapcore/sudoku/Field.java

changeset 5
8ddf4af937d7
parent 4
b8588e318001
child 7
2c0a2766461c
equal deleted inserted replaced
4:b8588e318001 5:8ddf4af937d7
60 } 60 }
61 } 61 }
62 62
63 @Override 63 @Override
64 public void paint(Graphics graphics) { 64 public void paint(Graphics graphics) {
65 super.paint(graphics);
66 final int w = getWidth(); 65 final int w = getWidth();
67 final int h = getHeight(); 66 final int h = getHeight();
68 final int cw = w / 9; 67 final int cw = w / 9;
69 final int ch = h / 9; 68 final int ch = h / 9;
70 69
88 } 87 }
89 } 88 }
90 } 89 }
91 90
92 graphics.drawImage(img, 0, 0, this); 91 graphics.drawImage(img, 0, 0, this);
92 super.paintChildren(graphics);
93 } 93 }
94 94
95 public int getCellValue(int x, int y) { 95 public int getCellValue(int x, int y) {
96 return cells[x][y].getValue(); 96 return cells[x][y].getValue();
97 } 97 }
124 for (int y = 0 ; y < 9 ; y++) { 124 for (int y = 0 ; y < 9 ; y++) {
125 cells[x][y].setValue(0); 125 cells[x][y].setValue(0);
126 } 126 }
127 } 127 }
128 } 128 }
129
130 public int[][] getSquare(int x, int y) {
131 if (x < 0 || x > 2 || y < 0 || y > 2) {
132 throw new IllegalArgumentException("Invalid square coordinates");
133 }
134 int[][] square = new int[3][3];
135
136 for (int u = 0 ; u < 3 ; u++) {
137 for (int v = 0 ; v < 3 ; v++) {
138 square[u][v] = getCellValue(3*x+u, 3*y+v);
139 }
140 }
141
142 return square;
143 }
144
145 public int[] getRow(int y) {
146 if (y < 0 || y > 8) {
147 throw new IllegalArgumentException("Invalid row number");
148 }
149 int row[] = new int[9];
150
151 for (int x = 0 ; x < 9 ; x++) {
152 row[x] = getCellValue(x, y);
153 }
154
155 return row;
156 }
157
158 public int[] getColumn(int x) {
159 if (x < 0 || x > 8) {
160 throw new IllegalArgumentException("Invalid column number");
161 }
162 int column[] = new int[9];
163
164 for (int y = 0 ; y < 9 ; y++) {
165 column[y] = getCellValue(x, y);
166 }
167
168 return column;
169 }
129 } 170 }

mercurial