Witam
Piszę program na zaliczenie z javy ( gra sieciowa w statki ) i po kompilacji program się uruchamia i działa ale wyskakuje taki błąd :
Note: C:\Users\tomasz.zajac\Desktop\Statki\src\statki_jd\statekmatrix.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
W momencie kiedy puszczę kompilację na zasadzie javac dana klasa - deprecation wyskakuje coś takiego :
<image>www.graanpol.home.pl/error.jpg</image>
natomiast kod tej klasy wygląda tak :
package statki_jd;
import java.util.ArrayList;
public class statekmatrix {
public class Ship {
private ArrayList blocks;
private ArrayList brokenBlocks;
private int size;
private boolean sank;
public Ship() {
blocks = new ArrayList();
brokenBlocks = new ArrayList();
size = 0;
sank = false;
}
public void addBlock(polozenie coords) {
blocks.add(coords);
size++;
}
public polozenie[] getCoords() {
polozenie[] c = new polozenie[blocks.size()];
for(int i=0; i<c.length;i++) {
c[i] = (polozenie) blocks.get(i);
}
return c;
}
public boolean addBrokenBlock(polozenie coords) {
System.out.println("Adding.." +sank);
for(int i=0; i< blocks.size(); i++) {
if(coords.equals((polozenie) blocks.get(i))) {
brokenBlocks.add(coords);
if(brokenBlocks.size() == blocks.size()) {
sank = true;
}
System.out.println("SANK?:" +sank);
return sank;
}
}
return false;
}
public int getSize()
{
return this.size;
}
}
public class ShipList extends java.util.Vector
{
public Ship get(int index) {
return (Ship) super.get(index);
}
}
public char[][] map;
public ShipList ships;
public final int MATRIX_HEIGHT = 10, MATRIX_WIDTH = 10;
public static final char BLANK = '0', MISS = '-', HIT = '+', SANK = '1', SHIP = 'S';
public statekmatrix() {
map = new char[MATRIX_HEIGHT][MATRIX_WIDTH];
fillMap(statekmatrix.BLANK);
countShips();
}
public void fillMap(char sign) {
for(int x=0; x< MATRIX_WIDTH; x++)
for(int y=0; y< MATRIX_HEIGHT; y++) {
map[x][y] = sign;
}
}
public void switchShip(int x, int y) {
if(map[x][y] == statekmatrix.SHIP) {
map[x][y] = statekmatrix.BLANK;
} else {
map[x][y] = statekmatrix.SHIP;
}
}
public int getNumberOfShips(int size) {
int count = 0;
countShips();
for(int i=0; i < ships.size(); i++) {
if(ships.get(i).getSize() == size) {
count++;
}
}
return count;
}
public void countShips()
{
ships = new ShipList();
for(int x=0; x < MATRIX_WIDTH; x++)
for(int y=0; y < MATRIX_HEIGHT; y++) {
if(map[x][y] == statekmatrix.SHIP) {
Ship ship = new Ship();
addBlockAndNeighbours(ship, new polozenie(x,y));
ships.add(ship);
}
}
for(int x=0; x < MATRIX_WIDTH; x++)
for(int y=0; y < MATRIX_HEIGHT; y++)
if(map[x][y] == statekmatrix.SANK)
map[x][y] = statekmatrix.SHIP;
}
private void addBlockAndNeighbours(Ship ship, polozenie coords)
{
if(coords == null)
return;
int x = coords.x;
int y = coords.y;
if(x >= 0 && x < MATRIX_WIDTH && y >= 0 && y < MATRIX_HEIGHT) {
if(map[x][y] == statekmatrix.SHIP) {
map[x][y] = statekmatrix.SANK;
ship.addBlock(new polozenie(x,y));
addBlockAndNeighbours(ship, new polozenie(x-1,y));
addBlockAndNeighbours(ship, new polozenie(x+1,y));
addBlockAndNeighbours(ship, new polozenie(x,y-1));
addBlockAndNeighbours(ship, new polozenie(x,y+1));
}
}
}
public boolean maxSizeRestricted()
{
for(int i=0; i<ships.size(); i++)
{
if(ships.get(i).size > 4) {
return false;
}
}
return true;
}
public Ship findShip(polozenie coords) {
System.out.println("findShip: " + coords.x + "," + coords.y);
Ship s;
for(int i=0; i<ships.size(); i++) {
s = ships.get(i);
for(int j=0; j<s.blocks.size(); j++) {
polozenie c = (polozenie) s.blocks.get(j);
System.out.println("Search: " + c.x + "," + c.y);
if(coords.equals((polozenie) s.blocks.get(j))) {
return s;
}
}
}
return null;
}
public char shotTry(polozenie coords) {
Ship s;
s = findShip(coords);
if(s != null) {
if(s.addBrokenBlock(coords)) {
return statekmatrix.SANK;
} else {
return statekmatrix.HIT;
}
} else {
return statekmatrix.MISS;
}
}
public int countRemainingShips()
{
int count=0;
for(int i=0;i<ships.size(); i++) {
if(!ships.get(i).sank) {
count++;
}
}
return count;
}
}
Proszę pomóżcie co powinienem zmienić lub dodać żeby było dobrze ?
Pozdrawiam.