public void deplacerDisques() { int disque = 0; if (prendre_tour == 1) { System.out.println("-- POP Pile 1 --"); disque = stackTower1.head(); stackTower1.pop(); } else if (prendre_tour == 2) { System.out.println("-- POP Pile 2 --"); disque = stackTower2.head(); stackTower2.pop(); } else if (prendre_tour == 3) { System.out.println("-- POP Pile 3 --"); disque = stackTower3.head(); stackTower3.pop(); } else { } if (deposer_tour == 1) { System.out.println("-- PUSH Pile 1 --"); stackTower1.push(disque); } else if (deposer_tour == 2) { System.out.println("-- PUSH Pile 2 --"); stackTower2.push(disque); } else if (deposer_tour == 3) { System.out.println("-- PUSH Pile 3 --"); stackTower3.push(disque); } else { } }
public void finPartie() { if (stackTower3.getNumberOfElements() == 3) { fin = true; this.infos.setText(" BRAVO ! Vous avez gagne "); } }
public boolean deplacementAutorise() { boolean autorise = false; Pile l1 = null; Pile l2 = null; if (prendre_tour == 1) l1 = stackTower1; if (prendre_tour == 2) l1 = stackTower2; if (prendre_tour == 3) l1 = stackTower3; if (deposer_tour == 1) l2 = stackTower1; if (deposer_tour == 2) l2 = stackTower2; if (deposer_tour == 3) l2 = stackTower3; if ((l1.head() < l2.head() && l1.head() != 0) || (!l1.isEmpty() && l2.isEmpty())) { autorise = true; } else { autorise = false; } l1 = null; l2 = null; return autorise; }
public void Test() { System.out.println("----- VERIFICATION TOWER 1 -----"); System.out.println("----- Taille " + stackTower1.getNumberOfElements() + " -----"); System.out.println(stackTower1.toString()); System.out.println("----- VERIFICATION TOWER 2 -----"); System.out.println("----- Taille " + stackTower2.getNumberOfElements() + " -----"); System.out.println(stackTower2.toString()); System.out.println("----- VERIFICATION TOWER 3 -----"); System.out.println("----- Taille " + stackTower3.getNumberOfElements() + " -----"); System.out.println(stackTower3.toString()); }
public void initialiserAttributs() { this.stackTower1 = new Pile(3); this.stackTower2 = new Pile(3); this.stackTower3 = new Pile(3); stackTower1.push(3); stackTower1.push(2); stackTower1.push(1); this.nombre_coups = 0; this.prendre_tour = 0; this.deposer_tour = 0; this.fin = false; this.tower1TopLeft = 50; this.tower2TopLeft = 350; this.tower3TopLeft = 650; fen = new JFrame(); fen.setSize(900, 700); fen.setLocationRelativeTo(null); fen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fen.setResizable(false); pan = new JPanel(); pan.setBackground(Color.white); process = new JLabel("JEU : LES TOURS DE HANOI"); process.setHorizontalAlignment(SwingConstants.CENTER); process.setSize(800, 50); process.setOpaque(true); process.setBackground(new Color(234, 195, 138)); process.setForeground(Color.WHITE); infos = new JLabel("TEST"); infos.setHorizontalAlignment(SwingConstants.CENTER); infos.setSize(400, 50); infos.setOpaque(true); infos.setBackground(Color.RED); infos.setForeground(Color.WHITE); infos_coups = new JLabel("Coups : 0"); infos_coups.setHorizontalAlignment(SwingConstants.CENTER); infos_coups.setSize(100, 50); infos_coups.setOpaque(true); infos_coups.setBackground(Color.RED); infos_coups.setForeground(Color.WHITE); imageTower1 = new JLabel(""); imageTower1.setSize(200, 400); imageTower1.setOpaque(true); imageTower1.setIcon(new ImageIcon("tour.png")); imageTower2 = new JLabel(""); imageTower2.setSize(200, 400); imageTower2.setOpaque(true); imageTower2.setIcon(new ImageIcon("tour.png")); imageTower3 = new JLabel(""); imageTower3.setSize(200, 400); imageTower3.setOpaque(true); imageTower3.setIcon(new ImageIcon("tour.png")); discBig = new JLabel(""); discBig.setSize(160, 40); discBig.setOpaque(true); discBig.setBackground(Color.RED); discMeduim = new JLabel(""); discMeduim.setSize(130, 40); discMeduim.setOpaque(true); discMeduim.setBackground(Color.GREEN); discSmall = new JLabel(""); discSmall.setSize(100, 40); discSmall.setOpaque(true); discSmall.setBackground(Color.BLUE); buttonTower1 = new JButton(" Tour 1"); buttonTower1.setSize(150, 50); buttonTower1.addActionListener(this); buttonTower2 = new JButton(" Tour 2"); buttonTower2.setSize(150, 50); buttonTower2.addActionListener(this); buttonTower3 = new JButton(" Tour 3 "); buttonTower3.setSize(150, 50); buttonTower3.addActionListener(this); this.activerBoutonModePrendre(); }
public void dessinerComposantsDynamiques(Pile stackTower, JLabel labelTower, int xTower) { if (stackTower.getStack()[0] == 3) { discBig.setBounds( xTower + labelTower.getWidth() / 2 - discBig.getWidth() / 2, 350, discBig.getWidth(), discBig.getHeight()); } else if (stackTower.getStack()[0] == 2) { discMeduim.setBounds( xTower + labelTower.getWidth() / 2 - discMeduim.getWidth() / 2, 350, discMeduim.getWidth(), discMeduim.getHeight()); } else if (stackTower.getStack()[0] == 1) { discSmall.setBounds( xTower + labelTower.getWidth() / 2 - discSmall.getWidth() / 2, 350, discSmall.getWidth(), discSmall.getHeight()); } else { // Noting } if (stackTower.getStack()[1] == 3) { discBig.setBounds( xTower + labelTower.getWidth() / 2 - discBig.getWidth() / 2, 275, discBig.getWidth(), discBig.getHeight()); } else if (stackTower.getStack()[1] == 2) { discMeduim.setBounds( xTower + labelTower.getWidth() / 2 - discMeduim.getWidth() / 2, 275, discMeduim.getWidth(), discMeduim.getHeight()); } else if (stackTower.getStack()[1] == 1) { discSmall.setBounds( xTower + labelTower.getWidth() / 2 - discSmall.getWidth() / 2, 275, discSmall.getWidth(), discSmall.getHeight()); } else { // Nothing } if (stackTower.getStack()[2] == 3) { discBig.setBounds( xTower + labelTower.getWidth() / 2 - discBig.getWidth() / 2, 200, discBig.getWidth(), discBig.getHeight()); } else if (stackTower.getStack()[2] == 2) { discMeduim.setBounds( xTower + labelTower.getWidth() / 2 - discMeduim.getWidth() / 2, 200, discMeduim.getWidth(), discMeduim.getHeight()); } else if (stackTower.getStack()[2] == 1) { discSmall.setBounds( xTower + labelTower.getWidth() / 2 - discSmall.getWidth() / 2, 200, discSmall.getWidth(), discSmall.getHeight()); } else { // Nothing } }