-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathescacsLenaEfren.java
More file actions
127 lines (109 loc) · 4.14 KB
/
Copy pathescacsLenaEfren.java
File metadata and controls
127 lines (109 loc) · 4.14 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package taulerescac;
import java.util.Scanner;
import Teclat.*;
import static java.lang.Byte.SIZE;
public class Tauler {
public static void main(String[] args) {
Scanner Teclat = new Scanner(System.in);
int files, columnes;
char BUIT = '_';
// Demanar les dimensions del tauler
System.out.print("Introduceix les files del tauler (entre 5 i 9): ");
files = Teclat.nextInt();
while (files < 5 || files > 9) {
System.out.print("Les files han de ser entre 5 i 9. Torna a introduir-les: ");
files = Teclat.nextInt();
}
System.out.print("Introduceix les columnes del tauler (entre 5 i 9): ");
columnes = Teclat.nextInt();
while (columnes < 5 || columnes > 9) {
System.out.print("Les columnes han de ser entre 5 i 9. Torna a introduir-les: ");
columnes = Teclat.nextInt();
}
// Inicialitzar el tauler
char[][] tauler = new char[files][columnes];
for (int i = 0; i < files; i++) {
for (int j = 0; j < columnes; j++) {
tauler[i][j] = BUIT;
}
}
// Bucle principal
int opcio;
do {
// Mostrar el tauler
System.out.println();
System.out.print(" ");
for (int i = 0; i < columnes; i++) {
System.out.print(i + " ");
}
System.out.println();
for (int i = 0; i < files; i++) {
System.out.print(i + " |");
for (int j = 0; j < columnes; j++) {
System.out.print(tauler[i][j] + "|");
}
System.out.println();
}
// Mostrar el menú
System.out.println();
System.out.println("1- Posar una peça");
System.out.println("2- Mostrar els moviments d'una peça");
System.out.println("3- Esborrar moviments");
System.out.println("4- Esborrar tauler");
System.out.println("5- Eixir");
//Preguntar número d'opció
System.out.print("Introduceix una opció: ");
opcio = Teclat.nextInt();
} // Executar l'opció
while (opcio != 5);
if (opcio == 1) {
System.out.print("Tipus de peça (Torre, Alfil, Dama, Rei o Cavall): ");
String peça = Teclat.next();
System.out.print("Coordenadas (fila columna): ");
int row = Teclat.nextInt();
int col = Teclat.nextInt();
char peçaChar;
switch (peça) {
case "Torre":
peçaChar = 'R';
break;
case "Alfil":
peçaChar = 'B';
break;
case "Dama":
peçaChar = 'Q';
break;
case "Rei":
peçaChar = 'K';
break;
case "Cavall":
peçaChar = 'N';
break;
default:
peçaChar = ' ';
}
tauler[row][col] = peçaChar;
System.out.println("Peça posada en (" + row + ", " + col + ")");
if (opcio == 2)
MenejarPeça();
private static void MenejarPeça() {
String[][] tauler = null;
int col = 0;
int row = 0;
String peça = tauler[row][col];
}
// Moviments possibles de la peça.
System.out.println("Moviments possibles de la peça " + peça + " a les coordenades (" + row + ", " + col + ")");
if (opcio == 3) {
EsborrarMoviments();
static void EsborrarMoviments() {
int moviments = 0;
System.out.println("S'han esborrat " + moviments + " moviments");
}
if (opcio == 4){
EsborrarTauler();
}
static void EsborrarTauler() {
char[][] tauler = new char[SIZE][SIZE];
}
}