Skip to content
Snippets Groups Projects
Commit 647ed847 authored by Aaro Askala's avatar Aaro Askala
Browse files

laiva.java

parent 5ca51087
Branches
No related tags found
No related merge requests found
public class Laiva extends laivanUpotus {
protected int pituus;
protected int maara;
public void asetaKuiMontLaivaa(int maara) {
this.maara = maara;
}
public void asetaKuiPitkaLaiva(int pituus) {
this.pituus = pituus;
}
public int annaLaivojenMaara() {
return maara;
}
public int annaLaivanPituus() {
return pituus;
}
public void luoLaiva(String[][] taulukko, int laivanpituus) {
if (Math.random() < 0.5) {
int col = (int) (Math.random() * 5);
int row = (int) (Math.random() * 7);
for (int i = 0; i < laivanpituus; i++) {
taulukko[row][col + i] = "S";
}
} else {
int col = (int) (Math.random() * 7);
int row = (int) (Math.random() * 5);
for (int i = 0; i < laivanpituus; i++) {
taulukko[row + i][col] = "S";
}
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment