From eda3aaf14340e6fd1189350c2a8b25dd519a3820 Mon Sep 17 00:00:00 2001 From: Simoes Lukas Date: Mon, 3 Nov 2025 12:30:52 +0100 Subject: [PATCH] . --- DEV3.2/TP05/04_Serpent/Fenetre.class | Bin 0 -> 756 bytes DEV3.2/TP05/04_Serpent/Fenetre.java | 20 ++++++ DEV3.2/TP05/04_Serpent/JGrilleDeJeu.class | Bin 0 -> 1769 bytes DEV3.2/TP05/04_Serpent/JGrilleDeJeu.java | 77 ++++++++++++++++++++++ DEV3.2/TP05/04_Serpent/Main.class | Bin 0 -> 322 bytes DEV3.2/TP05/04_Serpent/Main.java | 6 ++ 6 files changed, 103 insertions(+) create mode 100644 DEV3.2/TP05/04_Serpent/Fenetre.class create mode 100644 DEV3.2/TP05/04_Serpent/Fenetre.java create mode 100644 DEV3.2/TP05/04_Serpent/JGrilleDeJeu.class create mode 100644 DEV3.2/TP05/04_Serpent/JGrilleDeJeu.java create mode 100644 DEV3.2/TP05/04_Serpent/Main.class create mode 100644 DEV3.2/TP05/04_Serpent/Main.java diff --git a/DEV3.2/TP05/04_Serpent/Fenetre.class b/DEV3.2/TP05/04_Serpent/Fenetre.class new file mode 100644 index 0000000000000000000000000000000000000000..bc7ffcd7f146ba2d60ee102080df8b4f27dc44cb GIT binary patch literal 756 zcmX^0Z`VEs1_pBm6D|f821zakK?W%hAv z=3&ra(BxszV$ft{5CVx-=ogn~=B4XM;eFg(Y1|Bc> zqRgC}RF_n*)KZWshCB>L491KM>`>P+GO!n?mIP;3r7|+GYIu5r{L5XOTH=$RoLG{X zpU21`QJh-hlA4xSnp5JOlV6 coordSnake = new ArrayDeque<>(); + for (int i = 0; i != 5; i++) { + coordSnake.addLast(new Point(i+5, 5)); + } + this.add(new JGrilleDeJeu(coordSnake)); + + } + +} \ No newline at end of file diff --git a/DEV3.2/TP05/04_Serpent/JGrilleDeJeu.class b/DEV3.2/TP05/04_Serpent/JGrilleDeJeu.class new file mode 100644 index 0000000000000000000000000000000000000000..27f642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Ra$VO;*d3mi4o zi0}(z5M^LsP+?$YP-Ea>P-hTf&|pwv&}PtL&|xrP&}B$q&}T?zFkr}HFk&cVFlH!W zFlDG_uwbZVuw-asuwt0NV9hX{!G>Wjg9XC^1|5cF4B8B97@WXiD#gJ0he3&*LH`c} cBjX coordSnake; + + public JGrilleDeJeu(ArrayDeque coordSnake) { + this.grille = new char[TAILLE_GRILLE][TAILLE_GRILLE]; + this.coordSnake = coordSnake; + + for (int i = 0; i != TAILLE_GRILLE; i++) { + for (int j = 0; j != TAILLE_GRILLE; j++) { + this.grille[i][j] = 'g'; + } + } + + for (Point point : coordSnake) { + this.grille[point.x][point.y] = 'o'; + } + + Random r = new Random(); + int coordXPomme = Math.abs(r.nextInt() % TAILLE_GRILLE); + int coordYPomme = Math.abs(r.nextInt() % TAILLE_GRILLE); + + this.grille[coordXPomme][coordYPomme] = 'r'; + + Timer timer = new Timer(); + + while (true) { + timer.wait(1000L); + this.avancerSnake(); + } + } + + @Override + public void paintComponent(Graphics pinceau) { + Graphics secondPinceau = pinceau.create(); + + if (this.isOpaque()) { + secondPinceau.setColor(this.getBackground()); + secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight()); + } + + for (int i = 0; i != TAILLE_GRILLE; i++) { + for (int j = 0; j != TAILLE_GRILLE; j++) { + switch (grille[i][j]) { + case 'g': + secondPinceau.setColor(Color.GREEN); + break; + case 'r': + secondPinceau.setColor(Color.RED); + break; + case 'o': + secondPinceau.setColor(Color.ORANGE); + } + + secondPinceau.fillRect( + this.getWidth()/TAILLE_GRILLE*i, + this.getHeight()/TAILLE_GRILLE*j, + this.getWidth()/TAILLE_GRILLE, + this.getHeight()/TAILLE_GRILLE + ); + } + } + } + + public void avancerSnake() { + this.coordSnake.removeFirst(); + this.coordSnake.addLast(new Point(this.coordSnake.getLast().x+1, this.coordSnake.getLast().y)); + } +} \ No newline at end of file diff --git a/DEV3.2/TP05/04_Serpent/Main.class b/DEV3.2/TP05/04_Serpent/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..04767172ca9acd6808f50405523f567f17342f41 GIT binary patch literal 322 zcmX^0Z`VEs1_pBmF)ju+27Y!10WJn627VAB$j%_d&LGUlz-E(~msw)R$iS?j8OF%K z;+&t7%E-X)lbM(5SDKrYS`?C)l#|NHz>=Gona9W=rV;Ivl~|UjpOcuEt{+@dl$n=q z4bsRJoL^d$oa&YdQq1X_n3<;sQpdx<&cMOQ!0wisms(Pk%EKVSAj-(V0+MHB5CExw znB3vA#xXE5a56A3$TBc8FfuSO zuxf2*VBE;Sz`)4B#lXP81{MS<;b!20D%E3PVqjumVBp)$z!bTif!Rl!Wg7zvLJuDU bGXnzyGXn<$3j;3$D+40~F9QPu69XRrAlEgc literal 0 HcmV?d00001 diff --git a/DEV3.2/TP05/04_Serpent/Main.java b/DEV3.2/TP05/04_Serpent/Main.java new file mode 100644 index 0000000..2768c3d --- /dev/null +++ b/DEV3.2/TP05/04_Serpent/Main.java @@ -0,0 +1,6 @@ +public class Main { + public static void main(String[] args) { + Fenetre fenetre = new Fenetre(); + fenetre.setVisible(true); + } +} \ No newline at end of file