Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //player==============================================================
- package simpleGame;
- public class Player {
- private int locRow, locCol;
- private final int CELL_SIZE=20;
- public Player(int row, int col){
- locRow=row;
- locCol=col;
- }
- public int getCELL_SIZE() {
- return CELL_SIZE;
- }
- public int getLocRow() {
- return locRow;
- }
- public void setLocRow(int locRow) {
- this.locRow = locRow;
- }
- public int getLocCol() {
- return locCol;
- }
- public void setLocCol(int locCol) {
- this.locCol = locCol;
- }
- }
- //MapPanel++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- package simpleGame;
- import javax.swing.*;
- import java.awt.*;
- public class MapPanel extends JPanel {
- private Player p;
- private int PANEL_WIDTH=800, PANEL_HEIGHT=800;
- public MapPanel(Player play){
- p=play;
- setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
- }
- public void paintComponent(Graphics g){
- super.paintComponent(g);
- g.fillRect(p.getLocCol(), p.getLocRow(), p.getCELL_SIZE(),p.getCELL_SIZE());
- }
- }
- //GameFrame=============================================================
- package simpleGame;
- import javax.swing.*;
- public class GameFrame extends JFrame {
- private MapPanel panel;
- public GameFrame(MapPanel p){
- panel=p;
- add(panel);
- this.pack();
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- this.setVisible(true);
- }
- }
- //TestGame============================================================
- package simpleGame;
- public class TestGame {
- public static void main(String[] args) {
- Player p=new Player(0,0);
- MapPanel mp=new MapPanel(p);
- GameFrame frame=new GameFrame(mp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement