Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineTauvelENSEA committed Apr 24, 2023
0 parents commit aa1948f
Show file tree
Hide file tree
Showing 24 changed files with 392 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Project exclude paths
/out/
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/description.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/project-template.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions data/level1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
RRRRRRRRRRRRRRRRRRRRRRRRR
R T TT R
R H TTTTTT TTTTR
R T T ttR
R tR
RRRRRRRRRRRRRRRRRRRRRRRRR
11 changes: 11 additions & 0 deletions javaBienException.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
159 changes: 159 additions & 0 deletions src/draft.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package javaBien;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Locale;

public class Maze {
private final int width;
private final int height;
private char mazeArray[][];

public Maze(int width, int height, String filePath) {
this.width = width;
this.height = height;
this.mazeArray = new char[height][width];
try {
BufferedReader br = new BufferedReader(new FileReader(filePath));
for (int i=0;i<height;i++)
{String line = br.readLine();
mazeArray[i]=line.toUpperCase(Locale.ROOT).toCharArray();
}
} catch (Exception e) {
e.printStackTrace();
}

}

public void displayInConsole(){
for (char[] line : mazeArray){
for (char c : line){
System.out.print(c);
}
System.out.println("");
}

}
}


package javaBien;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Locale;
import java.util.Random;

public class Maze extends JPanel {
private final int width;
private final int height;
private char mazeArray[][];
private BufferedImage[] grass;
private BufferedImage[] rock;
private BufferedImage[] tree;
private BufferedImage trap;

public Maze(int width, int height, String filePath) {
super();
this.width = width;
this.height = height;
this.mazeArray = new char[height][width];
try {
BufferedReader br = new BufferedReader(new FileReader(filePath));
for (int i=0;i<height;i++)
{String line = br.readLine();
mazeArray[i]=line.toUpperCase(Locale.ROOT).toCharArray();
}

grass = new BufferedImage[4];
tree = new BufferedImage[4];
rock = new BufferedImage[2];

for (int i=0;i<grass.length;i++){
grass[i] = ImageIO.read(new File("./tiles/grass"+i+".png"));
tree[i] = ImageIO.read(new File("./tiles/tree"+i+".png"));
}
for (int i=0;i<rock.length;i++){
rock[i] = ImageIO.read(new File("./tiles/rock"+i+".png"));
}
trap = ImageIO.read(new File("./tiles/trap.png"));

} catch (Exception e) {
e.printStackTrace();
}

}
/* rock = new ImageIcon[2];
for (int i=0;i<rock.length;i++){
rock[i]=new ImageIcon("./tiles/rock"+i+".png");
}
trap = new ImageIcon("./tiles/trap.png");*/


public void displayInConsole(){
for (char[] line : mazeArray){
for (char c : line){
System.out.print(c);
}
System.out.println("");
}
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Random random= new Random();
int x = 0;
int y = 0;
for (char[] line : mazeArray){
for (char c : line){
switch(c){
case ' ' :
g.drawImage(grass[random.nextInt(4)],x,y,null);
break;
case 'T' :
g.drawImage(tree[random.nextInt(4)],x,y,null);
break;
case 'H' :
g.drawImage(trap,x,y,null);
break;
case 'R' :
g.drawImage(rock[random.nextInt(2)],x,y,null);
break;
}
x+=64;
}
y+=64;
x=0;
}
}
}


package javaBien;

import javax.swing.*;
import java.awt.*;

public class GraphicalMain extends JFrame {
Maze level;

public GraphicalMain(Maze level) throws HeadlessException {
super("Java bien");
this.level = level;
this.setSize(64*25,64*6);
this.add(level);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}

public static void main(String[] args){
Maze level1 = new Maze(25,6,"./data/level1.txt");
GraphicalMain graphicalMain = new GraphicalMain(level1);
}
}
14 changes: 14 additions & 0 deletions src/javaBien/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package javaBien;

public class Main {

public static void main(String[] args) {
Maze level1 = null;
try {
level1 = new Maze(25,6,"./data/level1.txt");
} catch (Exception e) {
e.printStackTrace();
}
level1.displayInConsole();
}
}
Loading

0 comments on commit aa1948f

Please sign in to comment.