private boolean verifCarte(int x, int y) { if (f.getCarte().getTerrain(x, y).getSame().getType() != "Mer" && f.getCarte().getTerrain(x, y).getSame().getModif() != "Montagne") { return true; } return false; }
public PanelColor(int id, Fenetre f, DisplayColor dc, Button backButton, int w, int h) { this.estConstructeurBis = true; this.bgColor = dc.getBackground(); this.dc = dc; this.setBounds(0, 0, w, h); this.lastButton = backButton; this.setBackground(this.bgColor); this.add(colorB); this.add(colorG); this.add(colorR); System.out.println(this.lastButton); this.colorB.setColor("" + this.lastButton.getColor().getBlue()); this.colorR.setColor("" + this.lastButton.getColor().getRed()); this.colorG.setColor("" + this.lastButton.getColor().getGreen()); this.colorChoice.setBackground(lastButton.getColor()); this.next.setId(lastButton.getId()); choseColor.addMouseListener(this); this.add(choseColor); // this.add(this.numColor); this.frame = f; this.setSize(new Dimension(w, h)); this.setLayout(null); this.addMouseListener(this); // carreColor.setMaximumSize(new Dimension(200, 200)); this.add(carreColor); validColor(colorR.getColor(), colorG.getColor(), colorB.getColor()); this.add(colorChoice); this.next.addMouseListener(this); this.add(next); neededGrey = maxGrey / (frame.getNmbColor()); frame.setNeededGrey(neededGrey); }
public PanelColor(Fenetre f, String name, int nbColor, Color c, int w, int h) { this.bgColor = c; choseColor.addMouseListener(this); this.add(choseColor); this.nmbColor = nbColor - 1; this.numColor.setText(this.numColor.getText() + this.nmbColor + " couleur(s)"); this.add(this.numColor); this.frame = f; this.setBackground(this.bgColor); this.setSize(new Dimension(w, h)); this.setName(name); this.setLayout(null); this.addMouseListener(this); // carreColor.setMaximumSize(new Dimension(200, 200)); this.add(carreColor); System.out.println(this.carreColor.getBackground()); this.add(colorR); validColor(colorR.getColor(), colorG.getColor(), colorB.getColor()); this.add(colorChoice); this.next.addMouseListener(this); this.add(next); this.add(colorB); this.add(colorG); neededGrey = maxGrey / (frame.getNmbColor()); frame.setNeededGrey(neededGrey); frame.map.put(frame.getGreyIndicator(), this); }
public Color setGrey(int r, int g, int b) { int greyLv = (int) (0.299 * r + 0.587 * g + 0.114 * b); while (frame.getGreyIndicator() > (greyLv + 8) || frame.getGreyIndicator() < (greyLv - 8)) { if (greyLv < frame.getGreyIndicator()) { if (r != 255) { r = r + 1; } if (g != 255) { g = g + 1; } if (b != 255) { b = b + 1; } } if (greyLv > frame.getGreyIndicator()) { if (r != 0) { r = r - 1; } if (g != 0) { g = g - 1; } if (b != 0) { b = b - 1; } } greyLv = (int) (0.299 * r + 0.587 * g + 0.114 * b); } return new Color(r, g, b); }
@Override public void mouseClicked(MouseEvent e) { Point p = new Point(Paint.pxtoHex(e.getX(), e.getY())); if (verifPresence(p.x, p.y) == 1) { panelPere.getListDeplacement().clear(); panelPere.repaint(); for (Troupes z : getListUnit()) { if (z.getCo().getX() == p.x && z.getCo().getY() == p.y) { this.SelectionTemp = z; panelPere.afficherDeplacement(z); panelPere.repaint(); } } } else if (verifPresence(p.x, p.y) == 2) { afficherOptionVille(); } else if ((verifPresence(p.x, p.y) == 0) && SelectionTemp != null) { for (Zone z : panelPere.getListDeplacement()) { if (z.getX() == p.x && z.getY() == p.y) { for (Troupes t : getListUnit()) { if (t.getCo().getX() == SelectionTemp.getCo().getX() && t.getCo().getY() == SelectionTemp.getCo().getY()) { t.getCo().setX(p.x); t.getCo().setY(p.y); repaint(); } } } } panelPere.getListDeplacement().clear(); panelPere.repaint(); SelectionTemp = null; } else if ((verifPresence(p.x, p.y) == 0) && SelectionTemp == null) { panelPere.getListDeplacement().clear(); panelPere.repaint(); if (verifCarte(p.x, p.y)) { addUnit(p.x, p.y); } } if (!(e.getX() < 30 || e.getY() < 30 || e.getX() >= f.getWidth() || e.getY() >= f.getHeight())) { Image img; try { img = ImageIO.read(new File("./ressources/images/unit/SelectorYellow.png")); Zone z = new Zone(p.x, p.y, img); panelPere.setSelect(z); } catch (IOException e1) { e1.printStackTrace(); } panelPere.repaint(); } }
@Override public void actionPerformed(ActionEvent arg0) { try { Integer tmp = new Integer(fenetre.getText().getText()); modele.setEntier(tmp); } catch (IntegerOutOfRangeException e) { System.out.println(e.getMessage()); } }
public void mouseReleased(MouseEvent e) { Boutons b = (Boutons) e.getSource(); if (b.getActionCommand().equals("jouer")) { b.setNom("jouer"); maFenetre.repaint(); } else if (b.getActionCommand().equals("ctrl")) { b.setNom("ctrl"); maFenetre.repaint(); } else if (b.getActionCommand().equals("quit")) { b.setNom("quit"); maFenetre.repaint(); } else if (b.getActionCommand().equals("back")) { b.setNom("back"); maFenetre.repaint(); } else { b.setNom("rejouer"); maFenetre.repaint(); } }
public static void main(String[] args) throws IOException { // Cleaning old files File h = new File("../../init.txt"); if (h.exists()) h.delete(); h = new File("../../in.txt"); if (h.exists()) h.delete(); isOk = false; fin = false; while (true) { // Wait the c++ program while (!isOk) { h = new File("../../init.txt"); if (h.exists()) { BufferedReader lecteurAvecBuffer = null; try { lecteurAvecBuffer = new BufferedReader(new FileReader("../../init.txt")); } catch (FileNotFoundException exc) { System.out.println("Error"); } isOk = true; // Choose single or bi-objective String s = lecteurAvecBuffer.readLine(); // System.out.println(s); if (Integer.parseInt(s) == 1) isSingle = true; else isSingle = false; lecteurAvecBuffer.close(); h.delete(); } } // Creating window f = new Fenetre(); h = new File("../../out.txt"); if (!h.exists()) h.createNewFile(); while (!fin) { // Waiting the next points File g = new File("../../in.txt"); if (g.exists()) { BufferedReader lecteurAvecBuffer = null; try { lecteurAvecBuffer = new BufferedReader(new FileReader("../../in.txt")); } catch (FileNotFoundException exc) { System.out.println("Error"); } // Reading the points if (isSingle) { int x = Integer.parseInt(lecteurAvecBuffer.readLine()); float y = Float.parseFloat(lecteurAvecBuffer.readLine()); listeX.addElement(x); listeY.addElement(y); // Update the window f.setContentPane(graph = new Graph(x, y)); } else { int n = Integer.parseInt(lecteurAvecBuffer.readLine()); for (int i = 0; i < n; ++i) { listeXX.addElement(Float.parseFloat(lecteurAvecBuffer.readLine())); listeY.addElement(Float.parseFloat(lecteurAvecBuffer.readLine())); Graph.det = true; } // Update the window f.setContentPane(graph = new Graph(listeXX, listeY)); n = Integer.parseInt(lecteurAvecBuffer.readLine()); det = true; for (int i = 0; i < n; ++i) { float f1 = Float.parseFloat(lecteurAvecBuffer.readLine()); if (det) { listeXP.removeAllElements(); } listeXP.addElement(f1); float f2 = Float.parseFloat(lecteurAvecBuffer.readLine()); if (det) { listeYP.removeAllElements(); det = false; } listeYP.addElement(f2); } } lecteurAvecBuffer.close(); File destination = new File("../../out.txt"); g.renameTo(destination); } g = new File("../../stop.txt"); if (g.exists()) { fin = true; g.delete(); } } fin = false; h = new File("../../init.txt"); if (h.exists()) h.delete(); h = new File("../../in.txt"); if (h.exists()) h.delete(); isOk = false; } }
public static void main(String[] args) { System.out.println("Si vous voulez jouer en graphique, tapez 1, sinon 0."); Scanner lecture = new Scanner(System.in); graphique = lecture.nextInt(); if (graphique == 0) { System.out.println("Avec combien de carrés voulez-vous jouer?"); Scanner scan = new Scanner(System.in); int nbcarres = scan.nextInt(); if (nbcarres == 4) { c = 3; l = 3; } if (nbcarres == 9) { c = 4; l = 4; } if (nbcarres == 16) { c = 5; l = 5; } if (nbcarres == 25) { c = 6; l = 6; } // Choix du type de jeu Scanner scn = new Scanner(System.in); System.out.println("Voulez-vous jouer contre un humain(0), ou un ordinateur(1)?"); typeJeu = scn.nextInt(); // Affichage du plateau de jeu TabManager tab1 = new TabManager(c, l); System.out.println(); tab1.initTab(); System.out.println(); System.out.println(); System.out.println(); while (true) { Test1.joueur = 1; System.out.println("Joueur A, horizontale(h) ou verticale(v)?"); Scanner dir = new Scanner(System.in); String str = dir.nextLine(); System.out.println("ligne: "); int coox = dir.nextInt(); System.out.println("colonne: "); int cooy = dir.nextInt(); if (str.charAt(0) == 'h') { TabManager.horizontale[coox - 1][cooy - 1] = 1; } if (str.charAt(0) == 'v') { TabManager.verticale[coox - 1][cooy - 1] = 1; } tab1.updateTab(); checkWin(TabManager.horizontale, TabManager.verticale); System.out.println("Points A: " + Test1.pointsA); System.out.println("Points B: " + Test1.pointsB); System.out.println("__________________________________________________"); System.out.println(); if (checkEnd(TabManager.horizontale, TabManager.verticale) == true) { System.out.println("La partie est finie!"); break; } if (typeJeu == 0) { Test1.joueur = 2; System.out.println("Joueur B, horizontale(h) ou verticale(v)?"); Scanner dire = new Scanner(System.in); String strg = dire.nextLine(); System.out.println("ligne: "); coox = dire.nextInt(); System.out.println("colonne: "); cooy = dire.nextInt(); if (strg.charAt(0) == 'h') { TabManager.horizontale[coox - 1][cooy - 1] = 1; } if (strg.charAt(0) == 'v') { TabManager.verticale[coox - 1][cooy - 1] = 1; } tab1.updateTab(); checkWin(TabManager.horizontale, TabManager.verticale); System.out.println("Points A: " + Test1.pointsA); System.out.println("Points B: " + Test1.pointsB); System.out.println("__________________________________________________"); if (checkEnd(TabManager.horizontale, TabManager.verticale) == true) { System.out.println("La partie est finie!"); break; } } if (typeJeu == 1) { Test1.joueur = 2; IA(); tab1.updateTab(); checkWin(TabManager.horizontale, TabManager.verticale); System.out.println("Points A: " + Test1.pointsA); System.out.println("Points B: " + Test1.pointsB); System.out.println("__________________________________________________"); if (checkEnd(TabManager.horizontale, TabManager.verticale) == true) { System.out.println("La partie est finie!"); break; } } } } if (graphique == 1) { Fenetre fen = new Fenetre(); while (Fenetre.b == false) { System.out.println(""); } TabManager tabg = new TabManager(c, l); StdDraw.setXscale(0, 40 + (Test1.c - 1) * 40); StdDraw.setYscale(0, 40 + (Test1.c - 1) * 40); fen.affichageGrille(TabManager.horizontale, TabManager.verticale); while (!(checkEnd(TabManager.horizontale, TabManager.verticale))) { Test1.joueur = 1; System.out.println("Joueur A"); System.out.println(Test1.b); while (Test1.b == false) { clicSouris(); } System.out.println("J1"); checkWin(TabManager.horizontale, TabManager.verticale); fen.affichageGrille(TabManager.horizontale, TabManager.verticale); Test1.b = false; if (Test1.typeJeu == 0) { Test1.joueur = 2; System.out.println("Joueur B"); while (Test1.b == false) { clicSouris(); } System.out.println("J2"); checkWin(TabManager.horizontale, TabManager.verticale); fen.affichageGrille(TabManager.horizontale, TabManager.verticale); Test1.b = false; } else { Test1.joueur = 2; IA(); System.out.println("TOP"); checkWin(TabManager.horizontale, TabManager.verticale); fen.affichageGrille(TabManager.horizontale, TabManager.verticale); Test1.b = false; } } StdDraw.clear(); StdDraw.text(50, 80, "La partie est finie!"); if (Test1.pointsA > Test1.pointsB) { StdDraw.text(50, 70, "Le joueur A remporte la partie!"); } if (Test1.pointsA < Test1.pointsB) { StdDraw.text(50, 70, "Le joueur B remporte la partie!"); } if (Test1.pointsA == Test1.pointsB) { StdDraw.text(50, 70, "Match Nul!"); } } }
@Override public void mouseClicked(MouseEvent arg0) { Button b; if (arg0.getSource() instanceof Button) { b = (Button) arg0.getSource(); int red = this.stringToInt(this.colorR.getText()); int green = this.stringToInt(this.colorG.getText()); int blue = this.stringToInt(this.colorB.getText()); if (arg0.getSource() == next) { if (this.nmbColor != 0) { this.frame.getDC().addColor(new Color(red, green, blue)); b.setColor(this.colorChoice.getBackground()); this.frame.setContentPane( new PanelColor( this.frame, "menuColorChoice", this.nmbColor, this.bgColor, this.getWidth(), this.getHeight())); } else { if (estConstructeurBis == true) { System.out.println("id ===== " + b.getId()); dc.getButtonList().get(b.getId()).setBackground(new Color(red, green, blue)); dc.getButtonList().get(b.getId()).setColor(new Color(red, green, blue)); // dc.getButtonList().set(b.getId(), b); dc.repaint(); // this.frame.getDC().updatePanel(); this.frame.setContentPane(dc); dc.repaint(); this.frame.revalidate(); estConstructeurBis = false; } else { this.frame .getDC() .addColor( new Color( this.stringToInt(this.colorR.getText()), this.stringToInt(this.colorG.getText()), this.stringToInt(this.colorB.getText()))); b.setColor(this.colorChoice.getBackground()); this.frame.getDC().updatePanel(); this.frame.setContentPane(this.frame.getDC()); } } frame.setGreyIndicator(neededGrey); this.frame.revalidate(); } else if (arg0.getSource() == choseColor) { PrecisePanel p = new PrecisePanel( this.frame, this, this.getBackground(), 0, 0, this.getWidth(), this.getHeight()); this.frame.setContentPane(p); this.frame.revalidate(); } else { System.out.println(colorR.getText() + " " + colorG.getText() + " " + colorB.getText()); this.colorR.setColor(colorR.getText()); this.colorG.setColor(colorG.getText()); this.colorB.setColor(colorB.getText()); validColor(colorR.getColor(), colorG.getColor(), colorB.getColor()); this.colorR.setText("" + colorR.getColor()); this.colorG.setText("" + colorG.getColor()); this.colorB.setText("" + colorB.getColor()); this.repaint(); } } }