Advertisement
Guest User

Untitled

a guest
May 28th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. // BattleShip_001.cpp: define el punto de entrada de la aplicación de consola.
  2. //
  3. #include <stdafx.h>
  4. #include <iostream>
  5. #include <ctime>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. const int lineas = 30;
  11. const int columnas = 50;
  12. const int CantAleatoria = 30;
  13.  
  14. char matriz[lineas][columnas];
  15.  
  16. void ValorInicial() {
  17.     for (int i = 0; i < lineas; i++) {
  18.         for (int x = 0; x < columnas; x++) {
  19.             matriz[i][x] = '-';
  20.         }
  21.     }
  22. }
  23.  
  24. void AgregarX() {
  25.     for (int i = 0; i < CantAleatoria; i++) {
  26.  
  27.         bool bExist = false;
  28.         do {
  29.             //El menos 1 es para que no se asigne en las 50 o 30(maximas) ya que esas no se muestran
  30.             int x = 0 + (rand() % ((lineas - 1)));
  31.             int y = 0 + (rand() % ((columnas - 1)));
  32.  
  33.             if (matriz[x][y] == 'X') {
  34.                 bExist = true;
  35.             }
  36.             else {
  37.                 //Descomentar para ver coordenadas random
  38.                 //cout << x << '|' << y << '|' << ' ';
  39.                 bExist = false;
  40.                 matriz[x][y] = 'X';
  41.             }
  42.         } while (bExist);
  43.     }
  44.     //Descomentar para ver coordenadas random
  45.     //cout << endl;
  46. }
  47.  
  48. void Mostrar() {
  49.     for (int i = 0; i < lineas; i++) {
  50.         for (int x = 0; x < columnas; x++) {
  51.             cout << matriz[i][x] << " ";
  52.         }
  53.         cout << endl;
  54.     }
  55. }
  56.  
  57. int main()
  58. {
  59.     ValorInicial();
  60.     AgregarX();
  61.     Mostrar();
  62.     system("pause");
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement