Saint Louis University |
Computer Science P125
|
Dept. of Math & Computer Science |
Please see the general programming webpage for details about the programming environment for this course, guidelines for programming style, and details on electronic submission of assignments.
For this assignment, you must work individually in regard to the design and implementation of your project.
Please make sure you adhere to the policies on academic integrity in this regard.
Your goal is to use the EzWindows graphics package to create an initial checkerboard configuration such as the following:
In terms of the end result, you must do the following:
You are creating a square window, with the precise size left as a design choice.
You are creating an 8x8 grid, with alternating red and black squares, as shown above with red in the top-left corner.
You will also be adding 12 white and 12 blue checkers, in the configuration as shown in the above figure. In particular, all checkers reside on black squares, with white in the top three rows, blue in the bottom three rows and no checkers in the middle two rows.
Equally important in this assignment is your technique. Given that the end result is fixed, it would be possible for someone to write code which technically works by individually drawing each of the 64 squares and each of the 24 circles. But you will not receive full credit for such an approach.
Our true goal in this assignment is to have you gain additional practice using nested control structures and user-defined function in order to minimize redundancy in your coding efforts. Therefore to receive full credit, one must use the following techniques:
There should be only one line of your program which creates a CircleShape object.
One possible design is that you create only a single such circle to use for the entire program. You might then use that circle to repeatedly draw multiple checkers, using the SetColor and SetPosition methods to alter the settings along the way, recalling the Draw method for each individual checker.
Another possible design approach would be to place the code to create and draw a checker within a newly defined function. Again, the checkers will vary in terms of color and placement, so you will need to choose your function design so that the relevant information is passed to this function via a list of parameters.
In similar spirit, you must consolidate your efforts for constructing objects for the squares.
For describing the larger logic of your program, you must rely on the obvious patterns to simplify the process. Namely, you must rely on the use of loops and conditionals to the end. That is, even if you've written a consolidated routine to add a single square to the board, you cannot then make 64 explicit calls to such a routine.
We are providing the following three files for your use. You may either download from a browser or copy them directly to your current directory on turing with the command:
cp -Rp ~goldwasser/csp125/programs/checkers .
There are three files:
checkers.cpp
To get you going, we have set up this file so that it includes
access to a variety of shapes from the EzWindow library.
What's missing is your code for reading and displaying the data!
Makefile
You should simply type make at
the command prompt and then your program will be compiled.
Either syntax errors will be displayed, or else the compilation
will be successful and an executable named checkers will
be created which you can run.
checkers.cpp
This is the source code file.
Again, we also ask for you to estimate the amount of time you spent on the assignment, and to let us know of any difficulties you had or other issues you wish to discuss.
The assignment is worth 10 points.
Obviously, one important consideration will be whether your program generated the desired image. Yet reaching that level of success does not necessarily guarantee full credit on the assignment. A portion of the grade will be based upon the programming techniques which you demonstrate.
For the required portion of the assignment, we did not make any requirements about the overall size of the board. For extra credit, we want you to write your program in a way that scales your picture to a desired window size.
Specifically, when executing your program, you should first prompt the user asking for the desired width of the window, measured in centimeters or fraction thereof. Since the board is presumed to be square, you need not explicitly ask for the height of the board. Once you have received that input, create such a window and draw the checkerboard accordingly.