-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserpitnte2.cpp
More file actions
90 lines (79 loc) · 2.5 KB
/
Copy pathserpitnte2.cpp
File metadata and controls
90 lines (79 loc) · 2.5 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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
// Inicialización del juego
int num_jugadores;
cout << "Bienvenido al juego de serpientes y escaleras." << endl;
cout << "Por favor, ingrese el número de jugadores (2-4): ";
cin >> num_jugadores;
// Validación del número de jugadores
while (num_jugadores < 2 || num_jugadores > 4) {
cout << "Número de jugadores inválido. Por favor, ingrese un número entre 2 y 4: ";
cin >> num_jugadores;
}
// Inicialización del tablero
const int TAM_TABLERO = 100;
int tablero[TAM_TABLERO];
for (int i = 0; i < TAM_TABLERO; i++) {
tablero[i] = i + 1;
}
tablero[2] = 21;
tablero[4] = 7;
tablero[10] = 25;
tablero[19] = 28;
tablero[26] = 0;
tablero[31] = 14;
tablero[33] = 11;
tablero[37] = 17;
tablero[40] = 43;
tablero[52] = 29;
tablero[57] = 40;
tablero[62] = 22;
tablero[66] = 45;
tablero[71] = 19;
tablero[80] = 99;
tablero[87] = 36;
tablero[93] = 68;
tablero[95] = 24;
tablero[98] = 78;
// Inicialización de los jugadores
const int MAX_JUGADORES = 4;
string nombres_jugadores[MAX_JUGADORES];
int posiciones_jugadores[MAX_JUGADORES];
int turno_actual = 0;
for (int i = 0; i < num_jugadores; i++) {
cout << "Por favor, ingrese el nombre del jugador " << i + 1 << ": ";
cin >> nombres_jugadores[i];
posiciones_jugadores[i] = 0;
}
// Juego principal
bool terminado = false;
while (!terminado) {
// Turno del jugador actual
cout << endl << "Es el turno de " << nombres_jugadores[turno_actual] << "." << endl;
// Tirada de los dados
srand(time(NULL));
int dado1 = rand() % 6 + 1;
int dado2 = rand() % 6 + 1;
cout << "Ha sacado " << dado1 << " y " << dado2 << "." << endl;
// Movimiento del jugador
int nueva_posicion = posiciones_jugadores[turno_actual] + dado1 + dado2;
if (nueva_posicion >= TAM_TABLERO) {
nueva_posicion = TAM_TABLERO - 1;
}
posiciones_jugadores[turno_actual] = tablero[nueva_posicion];
// Verificación de si el jugador ha ganado
if (posiciones_jugadores[turno_actual] == TAM_TABLERO) {
// El jugador ha ganado
cout << endl << nombres_jugadores[turno_actual] << " ha ganado el juego!" << endl;
terminado = true;
} else {
// El jugador no ha ganado, pasar al siguiente turno
turno_actual = (turno_actual + 1) % num_jugadores;
cout << "Su nueva posición es " << posiciones_jugadores[turno_actual] << "." << endl;
}
}
return 0;
}