Skip to content

Commit

Permalink
It works
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger Miret committed Jun 3, 2015
1 parent 65c3839 commit cdc2db8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/battleship/Bateau.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ public class Bateau extends Outils implements BateauInterface {
protected boolean[] status; //1 flottant, 0 touché
protected boolean coule;
protected int[] tailles;
protected int degats;

public Bateau(int taille) {
this.taille = taille;
this.status = new boolean[taille];
for (int i = 0; i < status.length; i++) {
status[i] = true;
}
this.degats=0;
}

public Bateau(int ta, boolean auto) {
Expand All @@ -42,11 +44,13 @@ public Bateau(int ta, boolean auto) {
tailles[9] = 3;
tailles[10] = 4;

this.taille = tailles[ta];
this.status = new boolean[tailles[ta]];
int tailleAvant = tailles[ta];
this.taille = tailleAvant;
this.status = new boolean[tailleAvant];
for (int i = 0; i < status.length; i++) {
status[i] = true;
}
this.degats=0;
}


Expand Down Expand Up @@ -153,6 +157,7 @@ public boolean tir(int x, int y) {
// }
if(isBateau(x, y)){
tir = true;
this.degats++;
if(horizontal) {
status[x-this.x]= false;
} else {
Expand Down
1 change: 0 additions & 1 deletion src/battleship/Battleship.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ && isNumber(tailleSelected.substring(position + 1))) {
* On regarde si le tir est valide et on tire
*/
if (target.isTirValid(x, y)) {
bell();
if (target.bonTir(x, y)) {
goodShot = true;
clear();
Expand Down
5 changes: 1 addition & 4 deletions src/battleship/Outils.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static String getAffiche(Plateau plat, Plateau plato) {
base += ANSI_YELLOW + " X" + ANSI_RESET + " "; //SUNK
break;
case 5:
base += ANSI_PURPLE + " 5" + ANSI_RESET + " "; //SUNK
base += ANSI_PURPLE + " S" + ANSI_RESET + " "; //SUNK
break;
default:
base += " ▓ ";
Expand All @@ -186,9 +186,6 @@ public static String getAffiche(Plateau plat, Plateau plato) {
case 4:
base += ANSI_YELLOW + " x" + ANSI_RESET + " ";
break;
case 5:
base += ANSI_PURPLE + " 5" + ANSI_RESET + " ";
break;
default:
base += ANSI_BLUE + " · " + ANSI_RESET;
break;
Expand Down
9 changes: 6 additions & 3 deletions src/battleship/Plateau.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package battleship;

import java.util.Arrays;
import java.util.HashMap;

/**
Expand Down Expand Up @@ -255,17 +256,19 @@ public boolean bonTir(int x, int y) {

if (this.plateau[y][x] == 5) {

boolean touche = true;
boolean coule = false;


this.plateau[y][x] = 3;

for (String entry : flota.keySet()) {
Bateau bat = flota.get(entry);
boolean touche = false;
boolean coule = false;

touche = bat.tir(x, y);
coule = bat.isCoule();
if (coule) {

if (touche && coule) {
if (bat.isHorizontal()) {
for (int i = bat.getX(); i < (bat.getX() + bat.getTaille()); i++) {
this.plateau[bat.getY()][i] = 4;
Expand Down
14 changes: 14 additions & 0 deletions src/battleship/Prova.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package battleship;

/**
*
* @author Roger
*/
public class Prova {
Bateau bat = new Bateau(0, true);
}

0 comments on commit cdc2db8

Please sign in to comment.