/********************************************************************************************
Step4.cpp
	Jim Millard
	for CO311/Spring 2000

   Simple program that displays a 4x4 Blue/Red checkerboard
   Uses the ezwin API
********************************************************************************************/
#include <iostream>
#include <string>
using namespace std;

#include "ezwin.h"
#include "rect.h"

void DrawCheckerboard(SimpleWindow& W);  //required prototype

int ApiMain()
   {
   //create the primary window
   SimpleWindow W("Exercise 3.22, Step 4");
   W.Open();

   DrawCheckerboard(W);

   //wait for input prior to quitting
   char ch;
   cout << "Enter a character to continue";
   cin >> ch;

   Terminate();
   return 0;
   }
void DrawCheckerboard(SimpleWindow& W)
   {
   //A stack of useful constants that can later be replaced by function parameters
   const float height=2., //static height of all blocks
               width =2., //static width of all blocks
               xCenter =width/2., //horizontal center of each block
               yCenter =height/2.; //vertical center of each block
   const int BlocksDown =4; //static height of checkerboard
   const color BaseColor = Blue,  //static color of first block
               AltColor  = Red;   //static color of alternate block

   bool doAltColor;  //keeps track of whether we should display in the alternate color
   color currentColor; //the color we're drawing now
   //Draw the rectangles
   int row; //declare here to avoid VC5 scope bug
   //draw even rows
   for(row = 0; row < BlocksDown; row+=2)
       {
       doAltColor = false; //do the base color first

       if (doAltColor)
           currentColor = AltColor;
       else
           currentColor = BaseColor;
       doAltColor = !doAltColor;
       RectangleShape Rx1(W,xCenter,yCenter + height*row,currentColor,width,height);
       Rx1.Draw();

       if (doAltColor)
           currentColor = AltColor;
       else
           currentColor = BaseColor;
       doAltColor = !doAltColor;
       RectangleShape Rx2(W,xCenter + width,yCenter + height*row,currentColor,width,height);
       Rx2.Draw();

       if (doAltColor)
           currentColor = AltColor;
       else
           currentColor = BaseColor;
       doAltColor = !doAltColor;
       RectangleShape Rx3(W,xCenter + width*2,yCenter + height*row,currentColor,width,height);
       Rx3.Draw();

       if (doAltColor)
           currentColor = AltColor;
       else
           currentColor = BaseColor;
       doAltColor = !doAltColor;
       RectangleShape Rx4(W,xCenter + width*3,yCenter + height*row,currentColor,width,height);
       Rx4.Draw();
       }//even row loop

   //draw odd rows
   for(row = 1; row < BlocksDown; row+=2)
       {
       doAltColor = true; //do the alternate color first

       if (doAltColor)
           currentColor = AltColor;
       else
           currentColor = BaseColor;
       doAltColor = !doAltColor;
       RectangleShape Rx1(W,xCenter,yCenter + height*row,currentColor,width,height);
       Rx1.Draw();

       if (doAltColor)
           currentColor = AltColor;
       else
           currentColor = BaseColor;
       doAltColor = !doAltColor;
       RectangleShape Rx2(W,xCenter + width,yCenter + height*row,currentColor,width,height);
       Rx2.Draw();

       if (doAltColor)
           currentColor = AltColor;
       else
           currentColor = BaseColor;
       doAltColor = !doAltColor;
       RectangleShape Rx3(W,xCenter + width*2,yCenter + height*row,currentColor,width,height);
       Rx3.Draw();

       if (doAltColor)
           currentColor = AltColor;
       else
           currentColor = BaseColor;
       doAltColor = !doAltColor;
       RectangleShape Rx4(W,xCenter + width*3,yCenter + height*row,currentColor,width,height);
       Rx4.Draw();
       }//odd row loop

   return;
   }//DrawCheckerboard