Advertisement
Guest User

Untitled

a guest
May 25th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. //Xadrez
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. enum pecaXadrez {
  7.     peao = 1,
  8.     rei = 2,
  9.     rainha = 3,
  10.     bispo = 4,
  11.     cavalo = 5,
  12.     torre = 6
  13. };
  14.  
  15. class posicao {
  16.     public:
  17.         int x, y;
  18.         int peca;
  19.         posicao() {
  20.             x = 0.0f;
  21.             y = 0.0f;
  22.             peca = 0;
  23.         }
  24.         posicao(int a, int b, int nPeca) {
  25.             x = a;
  26.             y = b;
  27.             peca = nPeca;
  28.         }
  29.         posicao(int a, int b) {
  30.             x = a;
  31.             y = b;
  32.             peca = 0;
  33.         }
  34. };
  35.  
  36. const int tamanhoTabuleiro = 4;
  37.  
  38. void Render(posicao tabuleiro[]) {
  39.     int cont = 0, linha = 0;
  40.     for (int x = 0; x < tamanhoTabuleiro; ++x) {
  41.         for (int y = 0; y < tamanhoTabuleiro; ++y) {
  42.             ++cont;
  43.             cout << "[" << tabuleiro[cont].peca << "]";
  44.             ++linha;
  45.             if (linha > tamanhoTabuleiro-1) {cout << "\n"; linha = 0;}
  46.            
  47.         }
  48.     }
  49. }
  50.  
  51. void CriarTabuleiro(posicao tabuleiro[]) {
  52.     int cont = 0;
  53.     for (int x = 0; x < tamanhoTabuleiro; ++x) {
  54.         for (int y = 0; y < tamanhoTabuleiro; ++y) {
  55.             ++cont;
  56.             tabuleiro[cont] = posicao(x, y, 0);
  57.            
  58.         }
  59.     }
  60. }
  61.  
  62. int main() {
  63.     posicao tabuleiro[tamanhoTabuleiro*tamanhoTabuleiro];
  64.     CriarTabuleiro(tabuleiro);
  65.     Render(tabuleiro);
  66.     cout << "Teste\n";
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement