Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // BattleShip_001.cpp: define el punto de entrada de la aplicación de consola.
- //
- #include <stdafx.h>
- #include <iostream>
- #include <ctime>
- #include <string>
- using namespace std;
- const int lineas = 30;
- const int columnas = 50;
- const int CantAleatoria = 30;
- char matriz[lineas][columnas];
- void ValorInicial() {
- for (int i = 0; i < lineas; i++) {
- for (int x = 0; x < columnas; x++) {
- matriz[i][x] = '-';
- }
- }
- }
- void AgregarX() {
- for (int i = 0; i < CantAleatoria; i++) {
- bool bExist = false;
- do {
- //El menos 1 es para que no se asigne en las 50 o 30(maximas) ya que esas no se muestran
- int x = 0 + (rand() % ((lineas - 1)));
- int y = 0 + (rand() % ((columnas - 1)));
- if (matriz[x][y] == 'X') {
- bExist = true;
- }
- else {
- //Descomentar para ver coordenadas random
- //cout << x << '|' << y << '|' << ' ';
- bExist = false;
- matriz[x][y] = 'X';
- }
- } while (bExist);
- }
- //Descomentar para ver coordenadas random
- //cout << endl;
- }
- void Mostrar() {
- for (int i = 0; i < lineas; i++) {
- for (int x = 0; x < columnas; x++) {
- cout << matriz[i][x] << " ";
- }
- cout << endl;
- }
- }
- int main()
- {
- ValorInicial();
- AgregarX();
- Mostrar();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement