Jump to content

Tabuleiro Jogo C++


Pedro Lima
 Share

Recommended Posts

void CrypticaBoard::DrawBoard(void)
{
 cout << endl;
 cout << "       1   2   3   4   5   6   7 \n" << endl;
    for(int row = 0; row < m_nRows; row++){
           cout << "    ||---+---+---+---+---+---+---||\n";
  printf ("  %d |",row+1); // cout?
  for(int col = 0; col < 7; col++){
   cout << "|";
            printf(" %c ", m_arrBoard[row][col]);
    }
    for(int col = 7; col < 8; col++){
   cout << "|";
    }
    cout << "|";
        cout << "\n";
}
//SetConsoleTextAttribute(console, y+150);
cout << "    ||---+---+---+---+---+---+---||\n\n";
//SetConsoleTextAttribute(console, 7);

}
Link to comment
Share on other sites

#include <iostream>
using namespace std;

int main(void) {
 int cols = 5, rows = 5;

 cout << endl;
 cout.fill(' ');
 cout.width(1);

 cout << "    ";
 for(int col = 0; col < cols; ++col)
   cout << " " << col << "  ";
 cout << endl;

 cout << "   +";
 for(int col = 0; col < cols; ++col)
   cout << "---+";
 cout << endl;

 for (int row = 0; row < rows; ++row) {
   cout << " " << row << " |";
   for(int col = 0; col < cols; ++col)
     cout << " " << (char) ('a' + col*row) << " |";
   cout << endl;

   cout << "   +";
   for(int col = 0; col < cols; ++col)
     cout << "---+";
   cout << endl;
 }

 return 0;
}
IRC : sim, é algo que ainda existe >> #p@p
Link to comment
Share on other sites

a implementação depende sempre dos dados que tens, mas o mais fácil de trabalhar seria implementar o que o Java faz com o interface Serializable.

cria uma classe puramente abstracta (por exemplo Serializable) que obriga a criação de duas funções:

- write_to_file

- read_from_file

depois, a cada objecto que pretendes guardar faz derivar dessa classe

o próximo passo depende se a quantidade de objectos a serem guardados é estática ou irá variar

IRC : sim, é algo que ainda existe >> #p@p
Link to comment
Share on other sites

CrypticaBoard:: CrypticaBoard(void)
: m_arrBoard(NULL), m_nColumns(7), m_nRows(5), m_nColors(4) //, m_nRemaining(0), m_nColors(4)
{
m_arrChars[0] = 'b';


SetupBoard();
}

void CrypticaBoard::SetupBoard(void)
{
 int i;
//  Create the board if needed
 if(m_arrBoard == NULL) CreateBoard();
 //  Randomly set each square to a color
 //srand(time(NULL));
 for(int row = 0; row <1 ; row++)
   for(int col = 0; col <1; col++)
     //m_arrBoard[row][col] = (rand() % m_nColors) ;
     m_arrBoard[row][col] =  m_arrChars[0];

 //  Set the number of spaces remaining
 //m_nRemaining = m_nRows * m_nColumns;
 //m_arrBoard[row][col] = 0;
}

estamos a tentar pôr as peças no tabuleiro a partir disto, mas as peças não aparecem no tabuleiro, só aparecem nas coordenadas x=1, y=1

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.