#created on: 17-abr-2009
package src.main.rules

dialect "mvel"

#list any import classes here.
import hangman.Hangman.RandomWord;
import hangman.Hangman.GuessedWord;
import hangman.Hangman.GameRules;
import hangman.Hangman.Solution;

import java.io.InputStreamReader;
import java.io.BufferedReader;


#declare any global variables here


rule "Letter or Solve"
	ruleflow-group "Decision"
	no-loop
	when    
	    rules : GameRules(g : allowedGuesses , s : allowedSolves)
	    GuessedWord( guess : guessedWord , l : letters )

	then
	    //Erase, if it exists, the previous value of decision
	    //modify ( rules ) { decision = null }
	    System.out.println("\n WORD:");
	    System.out.println(guess + "\n");
	    
	    System.out.println( "Said Letters: "+ l +"\n");
	    
	    System.out.println( "*You still have "+ g +" tries to guess a letter and "+ s + " tries to solve the word.\n");
	    System.out.println( "Press  \"X\" to exit, \"S\" to solve the word or \"L\" to guess a new Letter");
        br = new BufferedReader( new InputStreamReader( System.in ) );
        i = br.readLine().toUpperCase();     
	    modify ( rules ) { decision = i }
end



rule "Letter"
	ruleflow-group "Letter"
	no-loop
	when    
	    rules : GameRules( allowedGuesses > 0 )
	    guess : GuessedWord()	    
	then
	    modify ( rules ) { allowedGuesses -= 1 }
	    System.out.println( "Write a Letter:");
        br = new BufferedReader( new InputStreamReader( System.in ) );
        l = br.readLine().toUpperCase();  
        System.out.println( l ); 
		System.out.println( guess.guessedWord);
		guess.sayOneLetter(l);
		System.out.println( guess.guessedWord);
		System.out.println( guess.letters);
end	 



rule "Enter Solution"
	ruleflow-group "Solve"
	no-loop
	when    
	    rules : GameRules( allowedSolves > 0 )
	    sol : Solution()
	    RandomWord(word : randomWord)
	    
	then
		modify ( rules ) { allowedSolves -= 1 }
	    System.out.println( "Write the solution:");
        br = new BufferedReader( new InputStreamReader( System.in ) );
        i = br.readLine().toUpperCase();  
        System.out.println( "You have written"+i ); 
        System.out.println( "SSHHH Don´t say it to anyone:"+word );  
        System.out.println( word.compareTo(i));
        modify ( sol ) { solution = i }
        System.out.println( sol.solution);
end	