Assignment 8

Due Friday March 22, 2013 at 3pm.

Submit a single zip file to cuLearn with all of your answers (1 file for the written part and 1 folder for each Processing sketch).


Part 1: Write your answer in plain English. Put all of your answers in one single text file (.txt) or a single PDF file (.pdf). Your work will not be graded if it is submitted in another format..
  1. You are playing a card game (with a standard deck of cards) in which you are initially given 13 random cards. You want to organize the cards in increasing order of the rank of the cards. (Ace comes first, then 2, then 3, ..., king last.)

    Drescribe the process of you go about moving the cards in your hand to accomplish this.

  2. You want to write a function

    void pixelate(int x, int y, int size){...}
    
    The purpose of the function is to look at the sizeXsize block of pixels centred at the (x,y) coordinates given as input and change the colour of each of these pixels with the average colour of all the pixels in this block. The input size will always be an odd positive integer (so that having a sizeXsize block centred about (x,y) always makes sense).

    For example, calling pixelate(width/2,height/2,3) will change the pixel colours for the 9 pixels in the 3X3 block of pixels centred at the centre of the screen. And, calling pixelate(width/2, height/2, width) will change all pixels on the screen to be the average colour of all the pixels on the screen initially (assuming width == height, and width is an odd number).

    Write pseudocode for this function using the get() and set() for this.

    Write a second pseudocode for this function using the pixels array.

  3. Create a Pet class. Give your class at least 3 attributes/fields and define a constructor for it that has at least one input parameter.


Part 2: Write a Processing sketch as an answer for each of the following questions or tasks, unless otherwise stated.

Note: For each question, add the processing folder with your sketch to your ZIP file, not just your sketch (.pde file). Label each folder/sketch as Question4, Question5, etc. Do not put a space between "Question" and the number.


Note: For all of your sketches, the output window should have width and height at least 300 (but do not make them extremely large).

Note: For this and the remaining assignments, it is expected that you WILL use setup() and draw() unless specifically asked not to.

Main programming problem

Complete the memory/concentration game from Assignment 7 with the following modifications:
  1. Add a button to the side panel to remove "matched" cards. When a player turns over two cards that are a match, they should not simply disappear (as they would have in A7). The cards should remain face up on the playing field until this remove matched cards button is pressed. Pressing this button at any other time should do nothing.
  2. Add a button to the side panel to "cheat" in the game. Pressing this button (at any time in the game) should reveal the face side of every card on the playing field. Pressing the button again, turns all the cards face down (that were face down the first time the button was pressed). If any cards were face up when the button is first pressed, they will remain face up when the rest are turned face down. This button should toggle between a cheat state (all cards face up) and regular state (most cards face down) and can be pressed as many times during a game as the players wish.

Extensions and bonus remain the same as A7.