Advertisement
Guest User

jumble jan19

a guest
Jan 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.24 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
  5. C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
  6. Code, Compile, Run and Debug online from anywhere in world. First thing we need is random text.
  7. Jumble is a word puzzle with a clue, a drawing illustration the clue, and a set of words, each of which is jumped by
  8. scrabling its letters. A solver reconstructs the words, and then arranges letters at marked positions in the words to
  9. spell the answer phrase to the clue. The clue and illustration always provide hints about the answer phrase. The answer
  10. phrase frequently uses a homophone or a pun. Jumpbe was created in 1954 by Martin naydel, who is better known for his work
  11. on comic books. It originally appeared under the title Scramble. Henri Arnold and Bob Lee took over the feature in 1962 and
  12. continued for at least 30 years. As of 2013, Jumble is created by David L. Hoyt and Jeff Knurek. Jumpbe is one of the most
  13. valuable properties of its distributor, US company Tribune
  14.  
  15. *******************************************************************************/
  16. import java.util.*;
  17. import java.util.regex.*;
  18. import java.awt.*;
  19. import javax.swing.*;
  20. import java.awt.event.*;
  21. import javax.swing.GroupLayout.Alignment;
  22. import com.jgoodies.forms.layout.FormLayout;
  23. import com.jgoodies.forms.layout.ColumnSpec;
  24. import com.jgoodies.forms.layout.RowSpec;
  25. import net.miginfocom.swing.MigLayout;
  26.  
  27. public class Jumble extends JFrame
  28. {
  29. //Jumble frame;
  30. String randomword;
  31. String guessed;
  32. JTextField yourguess;
  33. JLabel winlose;
  34. ArrayList<String> thewords;
  35. JLabel label;
  36. private String jumble;
  37.  
  38.  
  39. public Jumble(String title) {
  40. super(title);
  41. getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
  42. }
  43.  
  44. public class MyActionListener implements ActionListener {
  45. public void actionPerformed( ActionEvent e ) {
  46. if (e.getActionCommand() == "Submit"){
  47. guessed = yourguess.getText();
  48. System.out.println(guessed);
  49. if(randomword.compareTo(guessed) == 0){
  50. winlose.setText("You won!");
  51. }
  52. else{
  53. winlose.setText("This is the correct word: " + randomword);
  54. }
  55.  
  56. }
  57. else if (e.getActionCommand() == "New Word"){
  58. Random r = new Random();
  59. randomword = thewords.get(r.nextInt(thewords.size()));
  60. jumble = scrambleletters(randomword);
  61. System.out.println("Solve this jumble: " + jumble);
  62. label.setText(jumble);
  63.  
  64. }
  65. else{
  66. System.out.println(e.getActionCommand());
  67. }
  68. // else if (e.getActionCommand() == "your guess"){
  69. // String text = e.getActionCommand()yourguess.getText();
  70. // }
  71. }
  72. }
  73. public static void main(String[] args) {
  74. Jumble frame = new Jumble("Jumble Game");
  75. // EventQueue.invokeLater(new Runnable() {
  76. // public void run() {
  77. // frame = new Jumble();
  78. // }
  79. // });
  80.  
  81. String txt = "Jumble is a word puzzle with a clue, a drawing illustrating the clue, and a set of words, each of which is " +
  82. "jumbled by scrambling its letters. A solver reconstructs the words, and then arranges letters at marked positions in the " +
  83. "words to spell the answer phrase to the clue. The clue and illustration always provide hints about the answer phrase. The " +
  84. "answer phrase frequently uses a homophone or pun.Jumble was created in 1954 by Martin Naydel, who is better known for " +
  85. "his work on comic books. It originally appeared under the title Scramble. Henri Arnold and Bob Lee took over the " +
  86. "feature in 1962 and continued for at least 30 years. As of 2013, Jumble is created by David L. Hoyt and Jeff Knurek. " +
  87. "Jumble is one of the most valuable properties of its distributor, US company Tribune Content Agency, which owns the " +
  88. "JUMBLE trademarks and copyrights. Daily and Sunday Jumble puzzles appear in over 600 newspapers in the United States and " +
  89. "internationally. The current syndicated version found in most daily newspapers (under the official title Jumble, That " +
  90. "Scrambled Word Game) has four base anagrams, two of five letters and two of six, followed by a clue and a series of blank " +
  91. "spaces in which the answer to the clue fits. The answer to the clue is generally a pun of some sort. A weekly kids version " +
  92. "of the puzzle features a 3-letter word plus three 4-letter words. In order to find the letters that are in the answer to " +
  93. "the given clue, the player must unscramble all four of the scrambled words; the letters that are in the clue will be " +
  94. "circled. The contestant then unscrambles the circled letters to form the answer to the clue. An alternate workaround is " +
  95. "to solve some of the scrambled words, figure out the answer to the clue without all the letters, then use the textra " +
  96. "letters as aids to solve the remaining scrambled words.There are many variations of puzzles from the Jumble brand including " +
  97. "Jumble, Jumble for Kids, Jumble Crosswords, TV Jumble, Jumble BrainBusters, Jumble BrainBusters Junior, Hollywood Jumble, " +
  98. "Jumble Jong, Jumble Word Vault, Jumpin' Jumble, Jumble Solitaire, and Jumble Word Web.";
  99. String[] words = txt.split(" ");
  100. ArrayList<String> wordlist = new ArrayList<String>(Arrays.asList(words));
  101. HashSet<String> filtered = new HashSet<String>();
  102. wordlist.stream()
  103. .filter(e -> frame.tester(e))
  104. .map(e -> e.toLowerCase())
  105. .forEach(e -> filtered.add(e));
  106. Random r = new Random();
  107. frame.thewords = new ArrayList <String>(filtered);
  108. frame.randomword = frame.thewords.get(r.nextInt(frame.thewords.size()));
  109. //System.out.println(thewords.get(r.nextInt(thewords.size())));
  110. //for (String s : thewords){
  111. //System.out.println(s);
  112.  
  113. //}
  114. frame.jumble = frame.scrambleletters(frame.randomword);
  115. frame.setupWindow(frame);
  116. System.out.println("Solve this jumble: " + frame.jumble);
  117. Scanner guess = new Scanner(System.in);
  118. frame.guessed = guess.nextLine();
  119. guess.close();
  120. }
  121. public boolean tester(String S){
  122. Pattern P = Pattern.compile( "[.,123456789();'0!?-]" );
  123. Matcher m = P.matcher(S);
  124. if (m.find()) {
  125. return false;
  126. }
  127. if (S.length() < 5){
  128. return false;
  129. }
  130. return true;
  131. }
  132. public String scrambleletters(String S){
  133. ArrayList<Character> scrambled = new ArrayList<Character>();
  134. for(char c : S.toCharArray()){
  135. scrambled.add(c);
  136. }
  137. StringBuilder scrambledletters = new StringBuilder();
  138. int len = scrambled.size();
  139. int l;
  140. Random r = new Random();
  141. for(int i = 0; i < len; i++){
  142. l = scrambled.size();
  143. int idx = r.nextInt(l);
  144. scrambledletters.append(scrambled.remove(idx));
  145. }
  146. return scrambledletters.toString();
  147. }
  148. public void setupWindow(Jumble frame){
  149. //JFrame frame = new JFrame( "Jumble Game" );
  150. label = new JLabel( jumble );
  151. winlose = new JLabel();
  152. yourguess = new JTextField( "Enter your guess" );
  153. JButton button = new JButton( "Submit" );
  154. JButton button1 = new JButton( "New Word" );
  155. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  156.  
  157. Container contentpane = frame.getContentPane();
  158. contentpane.add(button1, BorderLayout.PAGE_END);
  159. button1.addActionListener( new MyActionListener() );
  160. button1.setBounds(100, 280, 200, 100);
  161. contentpane.add(button, BorderLayout.LINE_END);
  162. button.addActionListener( new MyActionListener () );
  163. button.setBounds( 110, 110, 100, 50);
  164. contentpane.add(yourguess, BorderLayout.CENTER);
  165. yourguess.setPreferredSize(new Dimension(50,50));
  166. yourguess.setMaximumSize(new Dimension(50,50));
  167. yourguess.addActionListener( new MyActionListener () );
  168. yourguess.setBounds(100, 80, 200, 200);
  169. contentpane.add(label, BorderLayout.PAGE_START);
  170. contentpane.add(winlose, BorderLayout.LINE_START);
  171. winlose.setBounds(1,1,300,100);
  172. label.setBounds( 150, 0, 100, 50);
  173. contentpane.setLayout( null );
  174. frame.setVisible( true );
  175. frame.setSize(400,400);
  176. }
  177.  
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement