Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Xadrez
- #include <iostream>
- using namespace std;
- enum pecaXadrez {
- nada,
- peao,
- rei,
- rainha,
- bispo,
- cavalo,
- torre
- };
- class posicao {
- public:
- int x = 0, y = 0;
- pecaXadrez peca = nada;
- bool branco = false;
- posicao(){}
- posicao(int a, int b, pecaXadrez nPeca, bool eBranco) {
- x = a;
- y = b;
- peca = nPeca;
- branco = eBranco;
- }
- posicao(int a, int b) {
- x = a;
- y = b;
- }
- };
- void CriarTabuleiro(posicao tabuleiro[]) {
- int cont = 0;
- for (int x = 0; x < 8; ++x) {
- for (int y = 0; y < 8; ++y) {
- ++cont;
- tabuleiro[cont] = posicao(x, y);
- }
- }
- }
- void PreencherTabuleiro(posicao tabuleiro[]) {
- tabuleiro[0].peca = torre;
- tabuleiro[1].peca = cavalo;
- tabuleiro[2].peca = bispo;
- tabuleiro[3].peca = rainha;
- tabuleiro[4].peca = rei;
- tabuleiro[5].peca = bispo;
- tabuleiro[6].peca = cavalo;
- tabuleiro[7].peca = torre;
- for (int i = 8; i < 16; ++i) tabuleiro[i].peca = peao;
- for (int i = 48; i < 56; ++i) { tabuleiro[i].peca = peao; tabuleiro[i].branco = true; }
- tabuleiro[56].peca = torre; tabuleiro[56].branco = true;
- tabuleiro[57].peca = cavalo; tabuleiro[57].branco = true;
- tabuleiro[58].peca = bispo; tabuleiro[58].branco = true;
- tabuleiro[59].peca = rainha; tabuleiro[59].branco = true;
- tabuleiro[60].peca = rei; tabuleiro[60].branco = true;
- tabuleiro[61].peca = bispo; tabuleiro[61].branco = true;
- tabuleiro[62].peca = cavalo; tabuleiro[62].branco = true;
- tabuleiro[63].peca = torre; tabuleiro[63].branco = true;
- }
- void Render(posicao tabuleiro[]) {
- int cont = 0, linha = 0;
- for (int x = 0; x < 8; ++x) {
- for (int y = 0; y < 8; ++y) {
- cout << "[" << tabuleiro[cont].peca << "]";
- ++cont;
- ++linha;
- if (linha > 7) {cout << "\n"; linha = 0;}
- }
- }
- }
- int main() {
- posicao tabuleiro[64];
- CriarTabuleiro(tabuleiro);
- PreencherTabuleiro(tabuleiro);
- Render(tabuleiro);
- cout << "Teste\n";
- return 0;
- }
Add Comment
Please, Sign In to add comment