Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2012-05-21 05:16:11


JAVA CODING - Implementing a methods for a game

import acm.program.*;
import java.awt.Color;
import java.util.Iterator;
import java.util.Random;
import java.util.List;
public class LAB1
	final static int BLOCKWIDTH = 50;
	final static int BLOCKHEIGHT = 10;
	final static int NBLOCKS = 10;
	final static int BLOCKROWS = 5;
	final static int ROWZERO = 50;
	final static int ROWSEPARATION = (5*BLOCKHEIGHT);
	final static int WIDTH = (BLOCKWIDTH*NBLOCKS);
	final static int HEIGHT = 600;
	public static java.util.List<> createPlayfield()
		Random r = new Random();
		List<GRect> l = null;
		int x = 0;
		Color c = new Color(r.nextInt(256));
		for (int i = 0; i < BLOCKROWS; i++)
			for(int j = 0; j < NBLOCKS; j++)
				j = j * BLOCKWIDTH;
	public static void addBrick(java.util.List<> l, int x, int y, int width, int height, java.awt.Color c)
	public static createBrick(int x, int y, int width, int height, java.awt.Color c)
		GRect s = new GRect(x,y,WIDTH,HEIGHT);
		return s;
	public static intersect( o,java.util.List<> l)
		GRectangle r = o.getBounds();
		for(GRect e : l)
				return e;
		return null;

Problem I have is the createPlayfield() method, I have no idea on what to do, this is the description..

createPlayfield is a static method that returns a List of GRects. Each GRect is coloured randmoly and is
of size BLOCKWIDTH x BLOCKHEIGHT. The blocks are placed in a grid BLOCKROWS height x
NBLOCKS. The i'th row of blocks has its upper edge aligned with row i * ROWSEPARATION +
ROWZERO. The j'th column of blocks has its left edge aligned with j * BLOCKWIDTH. You may
find it useful to implement this method using the addBrick method below.

API's : The Class.

I really have no Idea what to do, can anyone break down the steps on what to do? I know that for i'th and j'th blocks i need a nested for loop but I don't know how to make the block return the GRects and also have a problem with where to place the GRect constructor (as in the for loop for it to be repeated or anywhere else), thanks for any suggestions.

I would really like to get help on this, I've tryed a lot to fix this for the past couple of days, the following playfield method makes no sense, still trying to figure out what to do.

#2 2012-05-21 07:37:42

Registered: 2012-05-21
Posts: 2

Re: JAVA CODING - Implementing a methods for a game

Is this the right section that I should be posting, or should it be somewhere else..?


#3 2012-05-21 07:48:06

From: Bumpkinland
Registered: 2009-04-12
Posts: 94,008

Re: JAVA CODING - Implementing a methods for a game

Hi geforce;

Welcome to the forum. Yes, you are in the right section.

In mathematics, you don't understand things. You just get used to them.

I agree with you regarding the satisfaction and importance of actually computing some numbers. I can't tell you how often I see time and money wasted because someone didn't bother to run the numbers.


#4 2012-05-21 08:02:40

Registered: 2012-05-21
Posts: 2

Re: JAVA CODING - Implementing a methods for a game

Alright, just making sure.


Board footer

Powered by FluxBB