USE the program PROCESSING for these sketches Learn to solve

USE the program PROCESSING for these sketches.

Learn to solve problems by designing algorithmic solutions. Use array data structures, functions and complex logical expressions and arithmetic operations such as modulus. Use switch statement to implement the logic of a game. Use pushMatrix and popMatrix of Processing to layer your sketch.

Prelab:

Create a flow chart for the implementation of the 2x2 version of the memory game.

Problem context:

The traveler in the first lab has gotten bored of travelling and wants to rest for a while. You have been assigned the task of building a simple game for this world traveler. Only request from the traveler is to make use of all the images the person (you) have collected during the world travel around the world. We have decided to design the famous “Memory” game. See a sample version of the game at this location: http://www.mathsisfun.com/games/memory/

Problem Statement:

You are required to build 3 versions of the memory game that has nXn tiles where n is even. The tiles have two faces, one is closed and the other has an image. Exactly two tiles of the nXn will have the same image. Initially all the tiles are covered. You goal is to open a pair of tiles one at a time with the aim of finding a matching pair. When you select a tile using the mouse, it flips to its image. After selecting two tiles, if the tiles do not have matching images they will revert back to the closed state. The game ends when all the tiles have been matches and there are no more tiles to flip open. We need some means for scoring the game. We will assume the number of tries to open up all the tiles as the overall score. Lower the score, the better is your “memory”. This means every time you guess wrong the count increases. Your game board will also have START and NEXT buttons and a place to display the score of the player. There are a lot of other possible enhancements, but due to time limitations we will restrict it to a simple version. See figure 1 for a sample layout. The tile of the game can be at the bottom of the sketch. While n can be large, we will limit the maximum size to 6 X 6.

Start by implementing a 2X2 game as a proof of concept; then move on to 4X4 and then to a 6X6 board. Images you have will have to be scaled to fit the tile size. You are required to provide a general solution using variables and parameterized functions wherever appropriate.

Implementation Details:

Here are some the problems to be solved:

Setting up the layout (Eg. 400X 400 for the tiles plus the bottom strip; title can be at the bottom)

Flipping a tile by pressing the mouse.

Remembering whether it is the first tile flip or second tile;

When it is second tile you need to determine if there is a match or not;

You will have to keep track of first selection of tile, and the second selection to determine if there is a match.

Keeping track of the tiles (eg. in arrays) to allow for matching.

A challenging task is that mapping of tile position to the index of the array(s).

Keeping track of score.

Keeping track of the progress of the game and display the score when it ends. It is veryimportant you develop the solution in incremental steps.

Your program should be modular with coherent functions and parameters to customize the functions. You can use println to debug your program. You can use whatever pictures you want. You can use mouse operations such as mouse pressed or mouse released operations.

Suggested program layout:

//Header

// constants for the states above
// other variables: many array representing the data for the game board // you will need a lot of arrays and for/while loops to process them

void setup() {
// square set for the board + the panel for start, next and score }

void draw() {
//probably empty? But it keeps listening to events and loops to redraw }

void mousePressed() {
// very important logic , “switch” or multi-way selection .... }

void initializeBoard(int n) {
// one single function for initializing the board irrespective of the size // because it is parameterized on “n” }

void initializeTurn() { }
void selectTile1() { }
void selectTile2() { }
int mapSelectiontoIndex() { }

void matchTiles() {
// it matches the tiles selected

// if matched , it scores
// It sets MA or NM state }

void closeTiles() { } void displayScore() { }

Solution

import java.awt.*;
import java.applet.*;

public category Tank extends applications programme
purpose target;
   public int x, y, w, h;
   public int maxX=400,maxY=360,minX=0,minY=0;
   public int maxFire;   // the utmost quantity of shots allowed for the tank to fireside promptly
   public int gamma hydroxybutyrateShells;   // The max range of shells allowed to be pink-slipped
   public Boolean isMoving, isAlive, exploded;
   Graphics g;

   Tank()

   public Tank(int xpos, int ypos, Color c, int speed, int newDirection, int maxFire)

   public void move() else break;
       case EAST:   if( (x+tankWidth()+moveBy)>maxX) else break;
case SOUTH: if( (y+tankHeight()+moveBy)>maxY ) else break;
case WEST: if( (x-moveBy<minX) ) else break;
}
   }

   public void turn(int newDirection)

   public void turnAround()

   void explode()

   public void paint(Graphics gr)

       //polygon canon wheels
       int x11[] = ;
       int y11[] = ;

       int x12[] = ;
       int y12[] = ;

       int x13[] = x11;
       int y13[] = ;

       int x14[] = ;
       int y14[] = y12;

       int x1[][] = ;
       int y1[][] = ;

       //roundrect canon compartment
       int x2[] = ;
       int y2[] = ;

       //rect canon case
       int x3[] = ;
       int y3[] = ;
       int x3w[] = ;
       int y3h[] = ;

       //oval canon cap
       int x4[] = ;
       int y4[] = ;

       //canon
       int x5[] = ;
       int y5[] = ;
       int x5w[] = ;
       int y5h[] = ;

       int d = direction - 1;

       //draw wheels
       g.setColor(Color.black);
       g.fillPolygon(x1[d], y1[d] ,8);

       //draw compartment
       g.setColor(color);
       g.fillRoundRect(x2[d],y2[d],25,25,5,5);

       //draw canon
       g.setColor(Color.black);
       g.fillRect(x5[d],y5[d],x5w[d],y5h[d]);


       //draw canon case
       g.setColor(new Color(47,79,79));
       g.fillRect(x3[d],y3[d],x3w[d],y3h[d]);

       //draw canon cap      
       g.setColor(Color.black);
       g.fillOval(x4[d],y4[d],15,15);

   }

   int tankWidth()direction==3)return 35;
       else {return 40;
   }

   int tankHeight()come 35;
   }

}

USE the program PROCESSING for these sketches. Learn to solve problems by designing algorithmic solutions. Use array data structures, functions and complex logi
USE the program PROCESSING for these sketches. Learn to solve problems by designing algorithmic solutions. Use array data structures, functions and complex logi
USE the program PROCESSING for these sketches. Learn to solve problems by designing algorithmic solutions. Use array data structures, functions and complex logi
USE the program PROCESSING for these sketches. Learn to solve problems by designing algorithmic solutions. Use array data structures, functions and complex logi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site