luluco250

Shitty chess basis

May 25th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. //Xadrez
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. enum pecaXadrez {
  7.     nada,
  8.     peao,
  9.     rei,
  10.     rainha,
  11.     bispo,
  12.     cavalo,
  13.     torre
  14. };
  15.  
  16. class posicao {
  17.     public:
  18.         int x = 0, y = 0;
  19.         pecaXadrez peca = nada;
  20.         bool branco = false;
  21.        
  22.         posicao(){}
  23.        
  24.         posicao(int a, int b, pecaXadrez nPeca, bool eBranco) {
  25.             x = a;
  26.             y = b;
  27.             peca = nPeca;
  28.             branco = eBranco;
  29.         }
  30.        
  31.         posicao(int a, int b) {
  32.             x = a;
  33.             y = b;
  34.         }
  35. };
  36.  
  37. void CriarTabuleiro(posicao tabuleiro[]) {
  38.     int cont = 0;
  39.     for (int x = 0; x < 8; ++x) {
  40.         for (int y = 0; y < 8; ++y) {
  41.             ++cont;
  42.             tabuleiro[cont] = posicao(x, y);
  43.            
  44.         }
  45.     }
  46. }
  47.  
  48. void PreencherTabuleiro(posicao tabuleiro[]) {
  49.     tabuleiro[0].peca = torre;
  50.     tabuleiro[1].peca = cavalo;
  51.     tabuleiro[2].peca = bispo;
  52.     tabuleiro[3].peca = rainha;
  53.     tabuleiro[4].peca = rei;
  54.     tabuleiro[5].peca = bispo;
  55.     tabuleiro[6].peca = cavalo;
  56.     tabuleiro[7].peca = torre;
  57.     for (int i = 8; i < 16; ++i) tabuleiro[i].peca = peao;
  58.     for (int i = 48; i < 56; ++i) { tabuleiro[i].peca = peao; tabuleiro[i].branco = true; }
  59.     tabuleiro[56].peca = torre; tabuleiro[56].branco = true;
  60.     tabuleiro[57].peca = cavalo; tabuleiro[57].branco = true;
  61.     tabuleiro[58].peca = bispo; tabuleiro[58].branco = true;
  62.     tabuleiro[59].peca = rainha; tabuleiro[59].branco = true;
  63.     tabuleiro[60].peca = rei; tabuleiro[60].branco = true;
  64.     tabuleiro[61].peca = bispo; tabuleiro[61].branco = true;
  65.     tabuleiro[62].peca = cavalo; tabuleiro[62].branco = true;
  66.     tabuleiro[63].peca = torre; tabuleiro[63].branco = true;
  67. }
  68.  
  69. void Render(posicao tabuleiro[]) {
  70.     int cont = 0, linha = 0;
  71.     for (int x = 0; x < 8; ++x) {
  72.         for (int y = 0; y < 8; ++y) {
  73.             cout << "[" << tabuleiro[cont].peca << "]";
  74.             ++cont;
  75.             ++linha;
  76.             if (linha > 7) {cout << "\n"; linha = 0;}
  77.            
  78.         }
  79.     }
  80. }
  81.  
  82. int main() {
  83.     posicao tabuleiro[64];
  84.     CriarTabuleiro(tabuleiro);
  85.     PreencherTabuleiro(tabuleiro);
  86.     Render(tabuleiro);
  87.     cout << "Teste\n";
  88.     return 0;
  89. }
Add Comment
Please, Sign In to add comment