-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReglas.java
More file actions
177 lines (155 loc) · 5.43 KB
/
Reglas.java
File metadata and controls
177 lines (155 loc) · 5.43 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* 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 ahorcadoBC;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Vicky
*/
public class Reglas {
private String palabra;
private char[] tablero;
private String[] arrayPalabras;
private List<String[]> listaPalabras;
private int turno;
private boolean fin;
private int aciertos, fallos;
private boolean gana;
private boolean pierde;
private char letra;
private boolean toca = false;
public Reglas() {
arrayPalabras = new String[]{"reingenieria", "cubeta", "tunelizacion", "protocolo",
"puertos", "conexion", "broadcasting", "direccion", "internet", "router", "switch", "wifi", "estandar",
"socket", "transporte", "enlace", "capas", "arquitectura", "cliente", "servidor", "proxy", "firewall", "redes",
"LAN", "WAN", "MAN", "hub", "concentrador", "datagrama", "puente", "fibra", "TCP", "UDP", "mascara", "gateway",
"servidor", "DNS", "cliente", "conmutacion", "circuito", "satelite", "coaxial", "microondas", "señal", "ingrarrojos",
"token", "anillo", "bus", "control", "flujo", "congestion", "enrutamiento", "aplicacion", "correo", "peertopeer",
"reingenieria", "cubeta", "tunelizacion", "protocolo", "puertos", "conexion", "broadcasting", "direccion", "internet",
"router", "switch", "wifi", "estandar", "socket", "transporte", "enlace", "capas", "arquitectura", "cliente", "servidor",
"proxy", "firewall", "redes", "LAN", "WAN", "MAN", "hub", "concentrador", "datagrama", "puente", "fibra", "TCP", "UDP",
"mascara", "gateway", "servidor", "DNS", "cliente", "conmutacion", "circuito", "satelite", "coaxial", "microondas",
"infrarrojos", "token", "anillo", "bus", "control", "flujo", "congestion", "enrutamiento", "aplicacion", "correo", "peertopeer"};
listaPalabras = new ArrayList<String[]>();
listaPalabras.add(arrayPalabras);
Collections.shuffle(listaPalabras);
this.palabra = listaPalabras.get(0)[0];
System.out.println(palabra);
this.tablero = new char[palabra.length()];
this.turno = 1;
this.fin = false;
this.aciertos = 0;
this.fallos = 0;
this.gana = false;
this.pierde = false;
}
public String getPalabra() {
return palabra;
}
public char[] getTablero() {
return tablero;
}
public int getTurno() {
return turno;
}
public void setTurno(int turno) {
this.turno = turno;
}
public boolean isFin() {
return fin;
}
public void setFin(boolean fin) {
this.fin = fin;
}
public int getAciertos() {
return aciertos;
}
public void setAciertos(int aciertos) {
this.aciertos = aciertos;
}
public int getFallos() {
return fallos;
}
public void setFallos(int fallos) {
this.fallos = fallos;
}
public char getLetra() {
return letra;
}
public void setLetra(char letra) {
this.letra = letra;
}
public boolean isToca() {
return toca;
}
public void setToca(boolean toca) {
this.toca = toca;
}
public synchronized void compruebaJugadaSynchronized(int id, char letra) {
boolean acertada = false;
while (turno != id) {
try {
if(fin){
break;
}
System.out.println("Duerme hilo " + id);
wait();
System.out.println("Despierta hilo " + id);
} catch (InterruptedException ex) {
Logger.getLogger(Reglas.class.getName()).log(Level.SEVERE, null, ex);
}
}
while (!toca) {
for (int i = 0; i < palabra.length(); i++) {
if (letra == palabra.charAt(i)) {
aciertos++;
acertada = true;
}
}
if (!acertada) {
fallos++;
}
turno++;
if (turno > 3) {
turno = 1;
}
toca = true;
notifyAll();
//System.out.println("Despierta hilo " + Thread.currentThread().getName());
System.out.println("Sale comprueba hilo " + id);
//System.out.println("Entra el hilo " + id);
}
}
public char[] completaTablero(char letra) {
for (int i = 0; i < palabra.length(); i++) {
if (palabra.charAt(i) == letra) {
tablero[i] = letra;
} else {
if (tablero[i] != '_' || tablero[i] != ' ') {
} else {
tablero[i] = '_';
}
}
}
return tablero;
}
public boolean compruebaGana() {
if (aciertos == palabra.length()) {
gana = true;
}
return gana;
}
public boolean compruebaPierde() {
if (fallos == 6) {
pierde = true;
}
return pierde;
}
}