All pastes #182292 Raw Edit

Someone

public text v1 · immutable
#182292 ·published 2006-09-25 22:06 UTC
rendered paste body
//******************************************************************
// =====================================
// Now pretty much everything is done programatically, rather than
// with hard code.  This should lead to a smaller filesize ;-)
// Also, we don't need any string classes (Bah, strings).
//******************************************************************

#include <iostream>

using namespace std; 

const char DARK        = (char)219;      // Define the Dark char
const char LIGHT       = (char)177;      // Define the Light char
const int WIDTH        = 7;              // Define how many squares wide
const int HEIGHT       = 7;              // Define how many square high
const int SQUARE_SIZE  = 8;              // size of each Square (in chars)
const int SCALER       = 3;              // number of lines less than chars wide

void PrintRow(int);                      
void DrawChessboard();                  // prototypes for functions
void DrawHorizontalBorder();

int main ()
{           
  DrawChessboard();         // make a call to the DrawChessboard function,
  system("PAUSE");          // then pause (so we can see the output).
  return 0;                 // exit.  
}      

void DrawChessboard() {
     int i;                              // initialise a counter
     
     DrawHorizontalBorder();             // draw a horizontal border
     for (i=1;i<=HEIGHT;i++) {
           PrintRow(i%2);                // Print as many rows as HEIGHT 
        }                                // tell us to.
     DrawHorizontalBorder();             // Draw another border to finish
}    
 
                                   // |----------------------------------------|
void PrintRow (int offset) {       // |PrintRow accepts an integer to alternate|
                                   // |the starting colour of each line.       |
     int i;                        // |initialise a few counters for nested    |
     int j;                        // |loops                                   |
     int k;                        // |----------------------------------------|
     char alternator[2];           // and an array to alternate black and white
     
     alternator[0] = DARK;         // populate the array
     alternator[1] = LIGHT;    
            
     for (j=0;j<=(SQUARE_SIZE-SCALER);j++) {// this loop handles the creation 
      cout << (char)186 << ' ';             // of each line in the row
      for (i=offset;i<(WIDTH+offset);i++) { // This loop deals with creating 
                                            // each row.
                                            // Add the offset to start on the 
                                            // appropriate colour.  
           for (k=0;k<=SQUARE_SIZE;k++) {   // this loop will make each square 
               cout << alternator[i%2];     // in each line. i%2 will oscilate  
              }                             // between 0 and 1 counting up in i.         
      }                                     // thus giving us alternating 
      cout << ' ' << (char)186 << endl;     // colours. finish the border.
     }
}
 
void DrawHorizontalBorder() {
     int i;                              //initialise a counter
     
     cout << ' ';           
     for (i=0;i<=((WIDTH+1)*SQUARE_SIZE);i++) {
             cout << (char)196;                // output a charachter for the 
         }                                     // whole length of the board
         cout << endl;                   // finish with a newline
}