I was wondering if anyone had any project ideas i could use :P I'm kind of bored, and can't think of any on my own.
Printable View
I was wondering if anyone had any project ideas i could use :P I'm kind of bored, and can't think of any on my own.
I've always wanted to create my own Java based forums software but that might be a bit of a big project. I'm keen on doing a small game using OpenGL with you if you like. Just as minor as minor can get really, start small.
// Json
Hehe, i found a small project to do: Tetris :D
It's not much yet, but here's what i've got so far:
Main applet program
Board classCode :package applet; import java.applet.Applet; import java.awt.*; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import pieces.Piece; import board.Board; public class Tetris extends Applet implements Runnable, KeyListener { Board board; public void init () { board = new Board(10, 20); /* * test code: uncomment to test painting * * for (int i = 0; i < board.getHeight(); i++) * { * for (int j = (int) (Math.random() * 5); j < board.getWidth(); j += (int) (Math.random() * 3) + 1) * { * board * .addPiece(new Piece(new Color((float) Math.random(), (float) Math.random(), (float) Math * .random())), i, j); * } * } */ } public void paint (Graphics g) { Rectangle properties; double width; double height; // determine if width or height is smaller if (this.getWidth() / board.getWidth() < this.getHeight() / board.getHeight()) { width = this.getWidth(); height = (double) board.getHeight() * this.getWidth() / board.getWidth(); } else { width = (double) board.getWidth() * this.getHeight() / board.getHeight(); height = this.getHeight(); } g.setColor(Color.BLACK); g.drawRect(0, 0, (int) width - 1, (int) height - 1); width--; height--; properties = new Rectangle(1, 1, (int) width, (int) height); board.paint(g, properties); } /** * @param e */ public void keyPressed (KeyEvent e) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_LEFT) { // move left } else if (keyCode == KeyEvent.VK_RIGHT) { // move right if (board.moveCurrPieceRight()) { repaint(); } } else if (keyCode == KeyEvent.VK_SPACE) { // hard drop board.hardDrop(); repaint(); } else if (keyCode == KeyEvent.VK_DOWN) { // soft drop if (board.moveCurrPieceDown()) { repaint(); } } else if (keyCode == KeyEvent.VK_UP) { // rotate CW if (board.rotateCurrPieceCW()) { repaint(); } } } /** * @param e */ public void keyReleased (KeyEvent e) {} /** * @param e */ public void keyTyped (KeyEvent e) {} /** * */ public void run () { // TODO Auto-generated method stub } }
Code :package board; import java.awt.*; import java.util.*; import pieces.Piece; public class Board { Point[] currPieceLoc; Piece currPiece; ArrayList<Piece[]> board; int width; int height; /** * Constructs a board with given width and height * * @param width * @param height */ public Board (int width, int height) { this.width = width; this.height = height; currPieceLoc = new Point[4]; currPieceLoc[0] = new Point(); currPieceLoc[1] = new Point(); currPieceLoc[2] = new Point(); currPieceLoc[3] = new Point(); board = new ArrayList<Piece[]>(); board.ensureCapacity(height); for (int i = 0; i < height; i++) { board.add(new Piece[width]); } } /** * @return board width */ public int getWidth () { return width; } /** * @return board height */ public int getHeight () { return height; } /** * Adds a piece to the board. If out of bounds coords given, nothing is done * * @param piece * @param row * @param col */ public void addPiece (Piece piece, int row, int col) { try { board.get(row)[col] = piece; } catch (ArrayIndexOutOfBoundsException e) { } } /** * Clears a column and adds an empty one to the top * * @param col */ public void clearCol (int col) { board.remove(col); board.add(new Piece[width]); } /** * Paints the board and the current piece being moved * * @param g * @param properties */ public void paint (Graphics g, Rectangle properties) { // paint all items on the board for (int row = 0; row < height; row++) { Piece[] currCol = board.get(board.size() - row - 1); for (int col = 0; col < width; col++) { if (currCol[col] != null) { // something to paint Rectangle props = new Rectangle(properties.x + col * properties.width / width, properties.y + row * properties.height / height, properties.width / width, properties.height / height); currCol[col].paint(props, g); } } } // paint the current piece for (int i = 0; i < currPieceLoc.length; i++) { if (currPieceLoc[i] != null && currPiece != null) { Rectangle props = new Rectangle(properties.x + currPieceLoc[i].x * properties.width / width, properties.y + currPieceLoc[i].y * properties.height / height, properties.width / width, properties.height / height); currPiece.paint(props, g); } } } /** * Determines if a location on the board is empty. * * @param row * @param col * @return True if empty and in-bounds. False otherwise. */ private boolean isLocEmpty (int row, int col) { try { if (board.get(row)[col] != null) { return false; } } catch (ArrayIndexOutOfBoundsException e) { return false; } return true; } /** * Moves the current piece left * * @return true if succeeded */ public boolean moveCurrPieceLeft () { for (int i = 0; i < currPieceLoc.length; i++) { if (currPieceLoc[i] != null) { if (!isLocEmpty(currPieceLoc[i].y, currPieceLoc[i].x - 1)) { return false; } } } for (int i = 0; i < currPieceLoc.length; i++) { if (currPieceLoc[i] != null) { currPieceLoc[i].x--; } } return true; } /** * Moves the current piece right * * @return true if succeeded */ public boolean moveCurrPieceRight () { for (int i = 0; i < currPieceLoc.length; i++) { if (currPieceLoc[i] != null) { if (!isLocEmpty(currPieceLoc[i].y, currPieceLoc[i].x + 1)) { return false; } } } for (int i = 0; i < currPieceLoc.length; i++) { if (currPieceLoc[i] != null) { currPieceLoc[i].x++; } } return true; } /** * Moves the current piece down * * @return true if succeeded */ public boolean moveCurrPieceDown () { for (int i = 0; i < currPieceLoc.length; i++) { if (currPieceLoc[i] != null) { if (!isLocEmpty(currPieceLoc[i].y - 1, currPieceLoc[i].x)) { return false; } } } for (int i = 0; i < currPieceLoc.length; i++) { if (currPieceLoc[i] != null) { currPieceLoc[i].y--; } } return true; } /** * Rotates the current piece CW * * @return true if succeeded */ public boolean rotateCurrPieceCW () { return false; } /** * Rotates the current piece CCW * * @return true if succeeded */ public boolean rotateCurrPieceCCW () { return false; } /** * Hard-drops the current piece. A hard-drop is dropping the current piece all the way to the bottom and locking it. */ public void hardDrop () { // keep moving the piece down until unable to while (moveCurrPieceDown()) { } } }
Piece class
Code :package pieces; import java.awt.*; /** * @author Andrew * */ public class Piece { Color color; public Piece (Color color) { this.color = color; } /** * Paints this piece * * @param x * @param y * @param item */ public void paint (Rectangle properties, Graphics g) { g.setColor(color); g.fill3DRect(properties.x, properties.y, properties.width, properties.height, true); } }
Cool, good stuff :D
// Json
I was wondering if someone would develop the graphics/gui? Right now, I pretty much have place-holder objects. Sound/Music would be nice, too.