Assignment 7

Due Friday March 15, 2013 at 3pm.

Only submit questions 1, 2 and 3 for this assignment on the due date. The programming question will be modified and submitted on Assignment 8.

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 have an image currently on the screen and all of the pixel color values are in the array pixels. Write pseudocode that changes all the red pixels to blue.

  2. Write a function called getColor() that inputs two decimal numbers (float type), which are x and y coordinates, and outputs the color that a square should be drawn at that position corresponding to this picture.

    Your function will be used in the following draw() function:

    void draw(){
       x = random(width);
       y = random(height);
       fill( getColor(x,y) );
       ellipse(x,y,30,30);
    }
    
  3. Suppose you are writing software to keep track of information for students at some university. Describe the data that you would need to store for a given student. Describe at least three functions that would be useful to work with this data.

    For example, one such useful function might be "computeGPA" which computes the grade point average of that student. Do not use this example.


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

Do not submit this part of the assignmnet with A7

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

Write a sketch that implements the game of memory (also called concentration). You can find more about the game at this link.

The rules for our game are as follows:

  1. The game consists of 54 playing cards. The standard 13 cards for each suit (hearts, spades, diamonds, clubs) and two joker cards. There will be one red and one black joker.

    Note: You can replace red/black with white/black, or any two colours(or grayscales) that have sufficient contrast so that we can easily see that they are different.

  2. All cards are placed face down on the screen. The cards should not overlap.
  3. There two players in the game. The players take turns until the game is over. A "turn" for a player is as follows:

  4. The game ends when all cards have been won.

Your program (Processing sketch) should implement this game. Use the following as a guide (you will be marked based on these specifications and on the game working properly):

  1. The output window should consist of the playing field (where the cards will be displayed) and a sidebar. The sidebar will consists of the following:
  2. Only two cards may be face up at any given time of the game.

  3. A player turns over a card by pressing the mouse over that card. (A player turns over two unmatched cards by pressing the "turn over" button mentioned above)

  4. When a card is turned face up, it need to display the rank, suit and colour of the card in some visual way.

  5. The back of each card should be some image loaded with the loadImage() function. It can be the image of a typical player card backing. Or it can be anything that you want (as long as it is not inappropriate). All cards, when faced down should display this image. Be sure to submit this image inside your folder! Do not submit a HUGE picture.

  6. At the start of each game, the cards should be "shuffled". That is, the placement of the cards should be random each time you start a game.

Bonus extensions to the memory game

You can receive bonus marks for implementing one (or both) of the following extensions to the game.
  1. Allow each player to ask for up to three hints during a single game. During a player's turn, when exactly one card is face up, if the player pressed the 'h' key, then they have asked or a hint. When a hint is asked for, your program should show the player a matching card (that is currently face down) for the one card that is currently face up. You decide what "show" means (but it should be obvious when we play your game). The hint ends when that player selects their net card. (Pressing 'h' before they select their second card does nothing). If a player asks for a hint after been given their three hints for the game, an appropriate message should be displayed.
  2. Allow more than 2 players to play the game. When starting a game, a message should be displayed asking how many players for this game. Using key entry, you specify how many players for the game. Everything should scale to the number of current players in the game.

If you implement either one or both of these extensions, you must include a .txt or .pdf file that lists which extensions you implemented. If you do not include this file, the markers will not test your extensions (and you will then receive no marks for them)

Extra Bonus

Add an extra "feature" to the game. It should involve something that is non-trivial to implement. (For example, changing the background colour of the playing field will not warrant any bonus marks.) Be creative.

If you add an extra feature, submit a .txt or .pdf file that explains what your feature is. If you do not submit this extra file, the marker will not test and assess your feature.