forked from menault/TD3_DEV51_Qualite_Algo
		
	Compare commits
	
		
			3 Commits
		
	
	
		
			2f3a6df740
			...
			Dificulty_
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c70c2b73ad | |||
| d4d8249c8b | |||
| 94e7394494 | 
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 122 KiB After Width: | Height: | Size: 166 KiB | 
| @@ -1,17 +1,62 @@ | ||||
| package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Controllers; | ||||
|  | ||||
| import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models.Difficulty; | ||||
| import fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models.Word; | ||||
|  | ||||
| ; | ||||
| import java.util.*; | ||||
|  | ||||
| public class Game { | ||||
|     private Word word; | ||||
|     private int errors; | ||||
|     private List<Word> allwords; | ||||
|     private Difficulty difficulty; | ||||
|     private final int maxErrors = 6; | ||||
|  | ||||
|     public Game(Word word) { | ||||
|     /* Hangmam Game */ | ||||
|     public Game(Word word ,List<Word> allWord) { | ||||
|         this.word = word; | ||||
|         this.errors = 0; | ||||
|         | ||||
|         switch (difficulty) { | ||||
|             case EASY: | ||||
|                 this.word = selectWord(allWord, 0 , 7 ); | ||||
|             break; | ||||
|             case MEDIUM: | ||||
|                 this.word = selectWord(allWord, 0, Integer.MAX_VALUE); | ||||
|             break; | ||||
|             case HARD: | ||||
|                 this.allwords = selectTwoWords(allWord); | ||||
|             break; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /* Selected  Word with conditions */ | ||||
|     private Word selectWord(List<Word> list, int min, int max) { | ||||
|         for (Word word : list) { | ||||
|             int length = word.getWord().length(); | ||||
|             if (length >= min && length <= max) { | ||||
|                 return word; | ||||
|             } | ||||
|         } | ||||
|         return list.getFirst(); | ||||
|     } | ||||
|  | ||||
|     /* Selected word level Difficult */ | ||||
|     private List<Word> selectTwoWords(List<Word> list) { | ||||
|         return list.subList(0, Math.min(2, list.size()));  | ||||
|     } | ||||
|  | ||||
|     public boolean playLetter(char caractere) { | ||||
|         boolean correct; | ||||
|  | ||||
|         if(difficulty == Difficulty.HARD){ | ||||
|             correct = this.allwords.get(0).VerifyLetter(caractere) || this.allwords.get(1).VerifyLetter(caractere); | ||||
|         } else{ | ||||
|             correct = word.VerifyLetter(caractere); | ||||
|         } | ||||
|  | ||||
|         if (!correct) errors++; | ||||
|         return correct; | ||||
|     } | ||||
|  | ||||
|     /* Verify error number  */ | ||||
| @@ -23,17 +68,6 @@ public class Game { | ||||
|         return this.maxErrors; | ||||
|     } | ||||
|  | ||||
|     /* Vue call method VerifyLetter, check status letter false/True */ | ||||
|     public boolean playLetter(char c) { | ||||
|         boolean correct = word.VerifyLetter(c); | ||||
|  | ||||
|         if (!correct) { | ||||
|             errors++; | ||||
|         } | ||||
|  | ||||
|         return correct; | ||||
|     } | ||||
|  | ||||
|     /* All letter is completed : Won */  | ||||
|     public boolean isWon() { | ||||
|         return word.IsComplete(); | ||||
|   | ||||
| @@ -1,49 +1,7 @@ | ||||
| package fr.iutfbleau.TD3_DEV51_Qualite_Algo; | ||||
|  | ||||
| import fr.iutfbleau.TD3_DEV51_Qualite_Algo.View.hangedManView; | ||||
|  | ||||
| import javax.swing.*; | ||||
| import java.awt.*; | ||||
| import java.io.IOException; | ||||
|  | ||||
| public class Main { | ||||
|     public static void main(String[] args) throws IOException { | ||||
|     public static void main(String[] args) { | ||||
|         | ||||
|         JFrame frame = new JFrame(); | ||||
|         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||||
|         frame.setSize(800, 600); | ||||
|         frame.setResizable(false); | ||||
|  | ||||
|         frame.setLayout(new GridBagLayout()); | ||||
|         GridBagConstraints GBC = new GridBagConstraints(); | ||||
|  | ||||
|         GBC.fill = GridBagConstraints.BOTH; | ||||
|         GBC.gridx = 0; | ||||
|         GBC.gridy = 0; | ||||
|         GBC.gridwidth = 1; | ||||
|         GBC.gridheight = 1; | ||||
|         GBC.weightx = 1; | ||||
|         GBC.weighty = 1; | ||||
|  | ||||
|         hangedManView drawingView = new hangedManView(); | ||||
|         frame.add(drawingView, GBC); | ||||
|  | ||||
|  | ||||
|         GBC.gridy = 1; | ||||
|         GBC.weighty = 0; | ||||
|  | ||||
|         JPanel panel = new JPanel(); | ||||
|         panel.setLayout(new FlowLayout(FlowLayout.CENTER)); | ||||
|  | ||||
|         JTextField TextField = new JTextField(); | ||||
|         TextField.setColumns(10); | ||||
|         panel.add(TextField,GBC); | ||||
|  | ||||
|         JButton button = new JButton("send"); | ||||
|         panel.add(button); | ||||
|  | ||||
|         frame.add(panel,GBC); | ||||
|  | ||||
|         frame.setVisible(true); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,5 @@ | ||||
| package fr.iutfbleau.TD3_DEV51_Qualite_Algo.Models; | ||||
|  | ||||
| public enum Difficulty { | ||||
|     EASY, MEDIUM, HARD | ||||
| } | ||||
| @@ -5,7 +5,7 @@ import java.util.*; | ||||
| public class Word {      | ||||
|     private final String word; | ||||
|     private Letter[] tabLetter; | ||||
|     private String c; | ||||
|     private String character; | ||||
|  | ||||
|     private Word(String word){ | ||||
|         this.word = word; | ||||
| @@ -14,11 +14,11 @@ public class Word { | ||||
|         } | ||||
|     } | ||||
|     /* Lettre dans le mot */ | ||||
|     public boolean VerifyLetter(char c){ | ||||
|     public boolean VerifyLetter(char character){ | ||||
|         boolean return_bool  = false; | ||||
|         for(Letter letter : this.tabLetter){ | ||||
|             if(!letter.getStatus()){ | ||||
|                 if(letter.isGood(c)){ | ||||
|                 if(letter.isGood(character)){ | ||||
|                     return_bool = true; | ||||
|                 } | ||||
|             } | ||||
| @@ -36,4 +36,8 @@ public class Word { | ||||
|         } | ||||
|         return true; | ||||
|     } | ||||
|     public String getWord() { | ||||
|        return word; | ||||
|     } | ||||
|      | ||||
| } | ||||
| @@ -1,33 +1,31 @@ | ||||
| package fr.iutfbleau.TD3_DEV51_Qualite_Algo.View; | ||||
| import javax.imageio.ImageIO; | ||||
| import javax.swing.*; | ||||
| import java.awt.*; | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
|  | ||||
|  | ||||
| public class hangedManView extends JComponent { | ||||
|  | ||||
|     private int state; | ||||
|     private String word; | ||||
|     private String wrongLetters; | ||||
|  | ||||
|     public hangedManView() throws IOException { | ||||
|         super(); | ||||
|         this.state = 8; | ||||
|         this.word = "E _ E _ _ L E"; | ||||
|         this.wrongLetters = "G  H  J  Z  R"; | ||||
|         this.state = 0; | ||||
|     } | ||||
|  | ||||
|     protected void paintComponent(Graphics g) { | ||||
|         super.paintComponent(g); | ||||
|         Graphics2D g2d = (Graphics2D) g; | ||||
|  | ||||
|         int x = this.getWidth()/2; | ||||
|         int y = this.getHeight()/2; | ||||
|         int x = 150; | ||||
|         int y = 200; | ||||
|  | ||||
|  | ||||
|         if(this.state > 8) { | ||||
|             // paint une image | ||||
|             double ratio = 0.5; | ||||
|             g2d.drawImage(new ImageIcon("resources/HangedGirl.jpg").getImage(), (this.getWidth()-(int) (567*ratio))/2, 0, (int) (567*ratio), (int) (1080*ratio), this); | ||||
|             g2d.drawImage(new ImageIcon(Thread.currentThread().getContextClassLoader().getResource("resources/HangedGirl.jpg")).getImage(), x, y, this); | ||||
|         }else{ | ||||
|             // on paint un homme batton | ||||
|             // Base | ||||
| @@ -69,28 +67,9 @@ public class hangedManView extends JComponent { | ||||
|                 g2d.drawLine(x, y + 40, x + 20, y + 70); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         // on dessine le mot en dessous du pendu et au centre de la fenêtre. | ||||
|         g2d.setFont(new Font("Roboto", Font.BOLD, 20)); | ||||
|         g2d.drawString(this.word, (this.getWidth()-g2d.getFontMetrics().stringWidth(this.word))/2, this.getHeight()-50); | ||||
|  | ||||
|         // on dessine les mauvaises lettres en rouge | ||||
|         g2d.setColor(Color.RED); | ||||
|         g2d.drawString(this.wrongLetters, (this.getWidth()-g2d.getFontMetrics().stringWidth(this.wrongLetters))/2, this.getHeight()-10); | ||||
|     } | ||||
|  | ||||
|     public void setState(int state) { | ||||
|         this.state = state; | ||||
|         this.repaint(); | ||||
|     } | ||||
|  | ||||
|     public void setWord(String word) { | ||||
|         this.word = word; | ||||
|         this.repaint(); | ||||
|     } | ||||
|  | ||||
|     public void setWrongLetters(String letters) { | ||||
|         this.wrongLetters = letters; | ||||
|         this.repaint(); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user