Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. //player==============================================================
  2.  
  3. package simpleGame;
  4.  
  5. public class Player {
  6.     private int locRow, locCol;
  7.     private final int CELL_SIZE=20;
  8.  
  9.     public Player(int row, int col){
  10.         locRow=row;
  11.         locCol=col;
  12.     }
  13.  
  14.     public int getCELL_SIZE() {
  15.         return CELL_SIZE;
  16.     }
  17.  
  18.     public int getLocRow() {
  19.         return locRow;
  20.     }
  21.  
  22.     public void setLocRow(int locRow) {
  23.         this.locRow = locRow;
  24.     }
  25.  
  26.     public int getLocCol() {
  27.         return locCol;
  28.     }
  29.  
  30.     public void setLocCol(int locCol) {
  31.         this.locCol = locCol;
  32.     }
  33. }
  34.  
  35. //MapPanel++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  36. package simpleGame;
  37.  
  38. import javax.swing.*;
  39. import java.awt.*;
  40.  
  41. public class MapPanel extends JPanel {
  42.     private Player p;
  43.     private int PANEL_WIDTH=800, PANEL_HEIGHT=800;
  44.  
  45.  
  46.     public MapPanel(Player play){
  47.         p=play;
  48.         setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
  49.     }
  50.  
  51.     public void paintComponent(Graphics g){
  52.         super.paintComponent(g);
  53.         g.fillRect(p.getLocCol(), p.getLocRow(), p.getCELL_SIZE(),p.getCELL_SIZE());
  54.     }
  55.  
  56. }
  57.  
  58. //GameFrame=============================================================
  59. package simpleGame;
  60.  
  61. import javax.swing.*;
  62.  
  63. public class GameFrame extends JFrame {
  64.     private MapPanel panel;
  65.  
  66.     public GameFrame(MapPanel p){
  67.         panel=p;
  68.         add(panel);
  69.  
  70.         this.pack();
  71.         this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  72.         this.setVisible(true);
  73.     }
  74.  
  75. }
  76. //TestGame============================================================
  77. package simpleGame;
  78.  
  79. public class TestGame {
  80.  
  81.     public static void main(String[] args) {
  82.         Player p=new Player(0,0);
  83.         MapPanel mp=new MapPanel(p);
  84.         GameFrame frame=new GameFrame(mp);
  85.     }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement