Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. package dkeep.gui;
  2.  
  3. import javax.swing.*;
  4. import java.awt.BorderLayout;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.awt.Color;
  8. import java.awt.Graphics;
  9.  
  10. public class MapCreator extends JPanel {
  11. private char activeChar;
  12. private boolean hasSaved;
  13. private JFrame frame = new JFrame();
  14. private String title;
  15. private int width, height;
  16. private JButton btnOgre, btnKey, btnHero, btnWall, btnFloor, btnSave;
  17. private JButton btnDoor;
  18. private EditorMap map;
  19. private Game game;
  20. private JPanel panel;
  21.  
  22. public MapCreator(String string, int i, int j) {
  23. map = new EditorMap(2,2);
  24. activeChar = 'H';
  25. title = string;
  26. width = i;
  27. height = j;
  28. frame = new JFrame(title);
  29. frame.setContentPane(this);
  30. frame.setSize(582, 423);
  31. frame.setVisible(true);
  32. frame.setResizable(false);
  33. frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  34. frame.setLocationRelativeTo(null);
  35. hasSaved = false;
  36. setLayout(null);
  37. game = new Game("Editor", 200, 200);
  38. init();
  39. game.gameLogic.changeCurrentMap(map);
  40. }
  41.  
  42. public void init() {
  43. btnOgre = new JButton("Ogre");
  44. btnOgre.addActionListener(new ActionListener() {
  45. public void actionPerformed(ActionEvent arg0) {
  46. activeChar = 'O';
  47. }
  48. });
  49. btnOgre.setBounds(10, 20, 100, 30);
  50. frame.getContentPane().add(btnOgre, BorderLayout.WEST);
  51.  
  52. btnKey = new JButton("Key");
  53. btnKey.setBounds(10, 70, 100, 30);
  54. btnKey.addActionListener(new ActionListener() {
  55. public void actionPerformed(ActionEvent arg0) {
  56. activeChar = 'k';
  57. }
  58. });
  59. frame.getContentPane().add(btnKey, BorderLayout.WEST);
  60.  
  61. btnHero = new JButton("Hero");
  62. btnHero.setBounds(10, 120, 100, 30);
  63. btnHero.addActionListener(new ActionListener() {
  64. public void actionPerformed(ActionEvent arg0) {
  65. activeChar = 'H';
  66.  
  67. }
  68. });
  69. frame.getContentPane().add(btnHero, BorderLayout.WEST);
  70.  
  71. btnWall = new JButton("Wall");
  72. btnWall.setBounds(10, 170, 100, 30);
  73. btnWall.addActionListener(new ActionListener() {
  74. public void actionPerformed(ActionEvent arg0) {
  75. activeChar = 'X';
  76. }
  77. });
  78. frame.getContentPane().add(btnWall, BorderLayout.WEST);
  79.  
  80. btnFloor = new JButton("Floor");
  81. btnFloor.setBounds(10, 220, 100, 30);
  82. btnFloor.addActionListener(new ActionListener() {
  83. public void actionPerformed(ActionEvent arg0) {
  84. activeChar = ' ';
  85. }
  86. });
  87. frame.getContentPane().add(btnFloor, BorderLayout.WEST);
  88.  
  89.  
  90. btnDoor = new JButton("Door");
  91. btnDoor.addActionListener(new ActionListener() {
  92. public void actionPerformed(ActionEvent arg0) {
  93. activeChar = 'I';
  94. }
  95. });
  96. btnDoor.setBounds(10, 270, 100, 30);
  97. add(btnDoor);
  98.  
  99. btnSave = new JButton("Save Changes");
  100. btnSave.setBounds(195, 360, 181, 23);
  101. btnSave.addActionListener(new ActionListener() {
  102. public void actionPerformed(ActionEvent arg0) {
  103. hasSaved = true;
  104. }
  105. });
  106. add(btnSave);
  107.  
  108. panel = new JPanel();
  109. panel.setBackground(Color.WHITE);
  110. panel.setBounds(181, 33, 344, 259);
  111. panel.setVisible(true);
  112. frame.add(panel);
  113. panel.repaint();
  114.  
  115.  
  116. }
  117.  
  118.  
  119.  
  120. @Override
  121. public void paintComponent(Graphics g) {
  122.  
  123. super.paintComponent(g);
  124. game.drawStructures(g);
  125. g.drawImage(game.hero, game.gameLogic.hero.getY() * 49 , game.gameLogic.hero.getX() * 49 - 49, 64, 90, null);
  126.  
  127. if(game.gameLogic.currentMap.getName() == "GuardMap"){
  128. g.drawImage(game.guard, game.gameLogic.guard.getY() * 49, game.gameLogic.guard.getX() * 49 - 49, 64, 90, null);
  129. }
  130. else {
  131. for(int i = 0; i < game.gameLogic.ogres.size(); i++){
  132. g.drawImage(Assets.club, game.gameLogic.ogres.get(i).getClubY()* 50, game.gameLogic.ogres.get(i).getClubX()* 50, 50, 50, null);
  133. g.drawImage(game.ogresSprite[i], game.gameLogic.ogres.get(i).getY()* 49, game.gameLogic.ogres.get(i).getX()* 49 - 40, 54, 80, null);
  134. }
  135. }
  136.  
  137. }
  138.  
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement