Map - import java.awt.*; import java.awt.event.*; import...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Map implements ActionListener{ // Window for game with graphics and buttons. public JFrame frame= new JFrame("J*Man!!!"); // The GUI window // The board of the game. Class JManPanel is an "inner class", defined below. private JManPanel board; // Buttons on the GUI private JButton bUp= new JButton("Up"); private JButton bDown= new JButton("Down"); private JButton bLeft= new JButton("Left"); private JButton bRight= new JButton("Right"); private JButton bnewGame= new JButton("New Game"); // Box to contain the direction buttons private Box buttonBox= new Box(BoxLayout.X_AXIS); // The box to contain buttonBox and the instructions Box instructBox= new Box(BoxLayout.Y_AXIS); private int height= 20; // height of the map in tiles. private int width= 20; // width of the map in tiles. private int tileWidth= 16; // width of a tile in pixels. private int tileHeight= 16; // height of a tile in pixels. private Piece[][] grid; //grid of Pieces that makes up the game. private JMan jMan; //the J*Man piece in this map. /** Start a game 20x20 game wih 10 walkers, 10 pillars, and 20 blocks. */ public static void main(String[] pars) { Map m= new Map(); } /** Constructor: a default 20 x 20 game with 10 walkers, 10 pillars, and 20 blocks placed randomly throughout the game grid. */ public Map(){ this(20, 20, 20, 10, 10); } /** Constructor: a game with an h x w grid with bl blocks, wa walkers, and pi pillars. J#Man is at position (0, 0), and all other pieces are placed randomly. Precondition: number of pieces specified is <= h*w. */ public Map(int h, int w, int bl, int wa, int pi){ this.height= h; this.width= w; // Set the preferred dimensions of the buttons Dimension buttondim= new Dimension(width*tileWidth/4,27); bUp.setPreferredSize(buttondim); bDown.setPreferredSize(buttondim); bLeft.setPreferredSize(buttondim); bRight.setPreferredSize(buttondim); bnewGame.setPreferredSize(new Dimension(width*tileWidth/2,27));
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
// Add the direction buttons to buttonBox and set the buttonBox alignment buttonBox.add(bUp); buttonBox.add(bDown); buttonBox.add(bLeft); buttonBox.add(bRight); buttonBox.setAlignmentX(0); // Register this as an action listener for all buttons. bUp.addActionListener(this);
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 02/24/2010.

Page1 / 6

Map - import java.awt.*; import java.awt.event.*; import...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online