/********************************************************************************************
Step3.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 3");
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
//Draw the rectangles
int row; //declare here to avoid VC5 scope bug
//draw even rows
for(row = 0; row < BlocksDown; row+=2)
{
RectangleShape Rx1(W,xCenter, yCenter + height*row,BaseColor,width,height);
Rx1.Draw();
RectangleShape Rx2(W,xCenter + width, yCenter + height*row,AltColor,width,height);
Rx2.Draw();
RectangleShape Rx3(W,xCenter + width*2., yCenter + height*row,BaseColor,width,height);
Rx3.Draw();
RectangleShape Rx4(W,xCenter + width*3., yCenter + height*row,AltColor,width,height);
Rx4.Draw();
}//even row loop
//draw odd rows
for(row = 1; row < BlocksDown; row+=2)
{
RectangleShape Rx1(W,xCenter, yCenter + height*row,AltColor,width,height);
Rx1.Draw();
RectangleShape Rx2(W,xCenter + width, yCenter + height*row,BaseColor,width,height);
Rx2.Draw();
RectangleShape Rx3(W,xCenter + width*2., yCenter + height*row,AltColor,width,height);
Rx3.Draw();
RectangleShape Rx4(W,xCenter + width*3., yCenter + height*row,BaseColor,width,height);
Rx4.Draw();
}//odd row loop
return;
}//DrawCheckerboard