Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.util.Scanner;
import java.io.*;
/**
* Class Crossword : Creates a 2D array of characters read from the input file
*/
public class Crossword
{
private char array[][]; // Tableaux 2D contenant les caractères
private int rows; // Nombres de lignes de array
private int columns; // Nombres de colonnes de array
private int WordCount; // Nombre d'occurences d'un mot
private int PositionX; // Colonne de début du mot
private int PositionY; // Ligne de début du mot
private int EndX; // Colonne de fin du mot
private int EndY; // Ligne de fin du mot
/*** Constructor: Reads each line from File <file> and writes to a new row in the array.
** Updates <rows> and <columns> to height and width of the array. */
public Crossword(File file) throws IOException {
// Code pour calculer la taille du tableau et initialiser les variables d'instance "rows" et "columns"
// Code pour créer le tableau "array"
// Code pour remplir "array" avec les caractères du Fichier "file"
}
/*** Methode Search(String) : Trouver le premier occurence du mot <word> dans le Tableau
*** Si touver, mettre à jour les valeurs (PositionY, PositionX, EndY, EndX)*/
public boolean search(String word) {
// Verifier que le taile du mot "word" est supérieure à zero. Sinon rien à faire.
// Chercher le premier caractère du mot "word" dans le tableau array.
// Si array[i][j] contient ce caractère, alors le mot peut apparaître dans le même ligne,
// ou dans le même colonne. Utiliser les methodes SearchRow() ou searchColumn() selon le cas.
return false; // mot pas trouvé
}
/* Methode Interne SearchRow(int,int, String) : Cherche une ligne du tableaux pour le mot <word> à partir de array[y][x] */
private boolean searchRow(int y, int x, String word) {
// Ecrire code ici ...
return false;
}
/* Methode Interne SearchRow(int,int, String) : Cherche une colonne du tableaux pour le mot <word> à partir de array[y][x] */
private boolean searchColumn(int y, int x, String word) {
// Ecrire code ici ...
return false;
}
/*** Methode pour visualiser le tableau. (Déjà fourni) */
public void display() {
if (rows>0 && columns>0)
CrosswordGUI.display(array);
else
System.out.println("Error: Array is Empty.");
}
/*** Methode pour visualiser le tableau avec le mot en surbrillance. (Déjà fourni) */
public void displayWord() {
if ((PositionX<0) || (PositionX>EndX) || (EndX>=columns)) {
System.out.println("Error: Incorrect x-coordinates for Word");
return;
}
if ((PositionY<0) || (PositionY>EndY) || (EndY>=rows)) {
System.out.println("Error: Incorrect y-coordinates for Word");
return;
}
CrosswordGUI.display(array, PositionY, PositionX, EndY, EndX);
}
}