Ajouté un bout de code pour créer une carte

This commit is contained in:
galaxyoyo 2015-01-07 19:27:02 +01:00
parent b31d9db0f0
commit 86bd11fc16
5 changed files with 78 additions and 5 deletions

BIN
img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 975 B

View File

@ -5,8 +5,15 @@ package galaxyoyo.unknown.client.main;
import galaxyoyo.unknown.frame.MainFrame; import galaxyoyo.unknown.frame.MainFrame;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import joptsimple.OptionParser; import joptsimple.OptionParser;
import joptsimple.OptionSet; import joptsimple.OptionSet;
import joptsimple.OptionSpec; import joptsimple.OptionSpec;
@ -123,6 +130,68 @@ public class Main
private static void launchEditMode() private static void launchEditMode()
{ {
System.out.println("Lancement de l'\u00e9diteur de monde ..."); System.out.println("Lancement de l'\u00e9diteur de monde ...");
int baseWidth;
int baseHeight;
int width;
int height;
while (true)
{
try
{
baseWidth = Integer.parseInt(JOptionPane.showInputDialog("Veuillez entrez le nombre de cases longueur de votre carte :")) * 16;
if (baseWidth <= 0)
throw new NumberFormatException();
break;
}
catch (NumberFormatException ex)
{
continue;
}
}
while (true)
{
try
{
baseHeight = Integer.parseInt(JOptionPane.showInputDialog("Veuillez entrez le nombre de cases hauteur de votre carte :")) * 16;
if (baseHeight <= 0)
throw new NumberFormatException();
break;
}
catch (NumberFormatException ex)
{
continue;
}
}
width = baseWidth + ((int) baseWidth / 16) + 1;
height = baseHeight + ((int) baseHeight / 16) + 1;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
g.setColor(Color.black);
g.drawLine(0, 0, width, 0);
g.drawLine(0, 0, 0, height);
for (int x = 17; x <= width; x += 17)
{
g.drawLine(x, 0, x, height);
}
for (int y = 17; y <= height; y += 17)
{
g.drawLine(0, y, width, y);
}
try
{
ImageIO.write(image, "png", new File("img.png"));
}
catch (IOException e)
{
e.printStackTrace();
}
} }
/** /**

View File

@ -3,7 +3,7 @@
*/ */
package galaxyoyo.unknown.frame; package galaxyoyo.unknown.frame;
import galaxyoyo.unknown.frame.listeners.EditMapsListener; import galaxyoyo.unknown.frame.listeners.CreateMapListener;
import java.awt.Dimension; import java.awt.Dimension;
@ -43,7 +43,9 @@ public class MainFrame extends JFrame
private JMenuBar menuBar = new JMenuBar(); private JMenuBar menuBar = new JMenuBar();
private JMenu fichier = new JMenu("Fichier"); private JMenu fichier = new JMenu("Fichier");
private JMenu editer = new JMenu("\u00c9diter"); private JMenu editer = new JMenu("\u00c9diter");
private JMenuItem editMaps = new JMenuItem("Cartes"); private JMenu editMaps = new JMenu("Cartes");
private JMenuItem createMap = new JMenuItem("Cr\u00e9er");
private JMenuItem editMap = new JMenuItem("\u00c9diter");
/** /**
* Constructeur * Constructeur
@ -62,7 +64,9 @@ public class MainFrame extends JFrame
menuBar.add(fichier); menuBar.add(fichier);
editMaps.addActionListener(new EditMapsListener()); createMap.addActionListener(new CreateMapListener());
editMaps.add(createMap);
editMaps.add(editMap);
editer.add(editMaps); editer.add(editMaps);
menuBar.add(editer); menuBar.add(editer);

View File

@ -11,12 +11,12 @@ import java.awt.event.ActionListener;
/** /**
* @author galaxyoyo * @author galaxyoyo
*/ */
public class EditMapsListener implements ActionListener public class CreateMapListener implements ActionListener
{ {
/** /**
* *
*/ */
public EditMapsListener() public CreateMapListener()
{ {
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB