예제 #1
0
def index():
    """The main page of the application"""
    flask.g.vocab = WORDS.as_list()
    flask.session["target_count"] = min(len(flask.g.vocab),
                                        CONFIG.SUCCESS_AT_COUNT)
    flask.session["jumble"] = jumbled(flask.g.vocab,
                                      flask.session["target_count"])
    flask.session["matches"] = []
    return flask.render_template('vocab.html')
예제 #2
0
def index():
  flask.g.vocab = WORDS.as_list();
  flask.session["target_count"] = min( len(flask.g.vocab), CONFIG.SUCCESS_COUNT )
  flask.session["jumble"] = jumbled(flask.g.vocab, flask.session["target_count"])
  flask.session["matches"] = [ ]
  app.logger.debug("Session variables have been set")
  assert flask.session["matches"] == [ ]
  assert flask.session["target_count"] > 0
  app.logger.debug("At least one seems to be set correctly")
  return flask.render_template('vocab.html')
예제 #3
0
def index():
    """
    The main page of the application
    Get the global wordlist and set session
    variables, then render the page appropriately
    """
    flask.g.vocab = WORDS.as_list()
    flask.session["target_count"] = min(len(flask.g.vocab),
                                        CONFIG.SUCCESS_AT_COUNT)
    flask.session["jumble"] = jumbled(flask.g.vocab,
                                      flask.session["target_count"])
    flask.session["matches"] = []
    app.logger.debug("Session variables have been set")
    assert flask.session["matches"] == []
    assert flask.session["target_count"] > 0
    app.logger.debug("At least one seems to be set correctly")
    return flask.render_template('vocab.html')
def index():
    """The main page of the application"""
    flask.g.vocab = WORDS.as_list(
    )  # Create a global var with all the words in it
    flask.session[
        "target_count"] = min(  # Create a session variable called target_count and store it with the number of correct answers the user must get (defined in credentials.ini)
            len(flask.g.vocab), CONFIG.SUCCESS_AT_COUNT
        )  # Retrieve the success count value. If the number of words in the list is less than that value, use the number of words instead
    flask.session[
        "jumble"] = jumbled(  # Creat an anagram that scrambles 'target_count' number of words together from the word list
            flask.g.vocab, flask.session["target_count"])
    flask.session["matches"] = [
    ]  # Define an empty veriable to store the matches once we have them
    flask.session["input_letters"] = [
    ]  # Define an empty veriable to store the letters in #attempt
    app.logger.debug("Session variables have been set")
    assert flask.session["matches"] == []
    assert flask.session["target_count"] > 0
    app.logger.debug("At least one seems to be set correctly")
    return flask.render_template('vocab.html')
예제 #5
0
def test_jumbled_caps():
    assert not same(jumbled(["A", "a"], 2), "a")
예제 #6
0
def test_jumbled_more():
    assert same(jumbled(["aabc", "abac", "bcaa"], 2), "aabc")
예제 #7
0
def test_jumbled_pair():
    assert same(jumbled(["abbc", "abcc"], 2), "abbcc")
예제 #8
0
def test_jumbled_single():
    assert same(jumbled(["abbcd"], 1), "abbcd")
예제 #9
0
def test_jumbled_more():
    assert same( jumbled(["aabc", "abac", "bcaa"], 2), "aabc")
예제 #10
0
def test_jumbled_pair():
    assert same( jumbled(["abbc", "abcc"], 2), "abbcc")
예제 #11
0
def test_jumbled_single():
    assert same( jumbled(["abbcd"], 1), "abbcd" )
예제 #12
0
def test_jumbled_empty():
    assert same(jumbled([""], 1), "")
예제 #13
0
def test_jumbled_same():
    assert same(jumbled(["abbc", "abbc"], 2), "abbc")
예제 #14
0
	def index():
	"""The main page of the application"""
	flask.g.vocab = WORDS.as_list()
	flask.session["target_count"] = min(len(flask.g.vocab), CONFIG.SUCCESS_AT_COUNT)
	flask.session["jumble"] = jumbled(flask.g.vocab, flask.session["target_count"])
	flask.session["matches"] = []
	app.logger.debug("Session variables have been set")
	assert flask.session["matches"] == []
	assert flask.session["target_count"] > 0
	app.logger.debug("At least one seems to be set correctly")
	return flask.render_template('vocab.html')
	
	
	@app.route("/keep_going")
	def keep_going():
	"""
	After initial use of index, we keep the same scrambled
	word and try to get more matches
	"""
	flask.g.vocab = WORDS.as_list()
	return flask.render_template('vocab.html')
	
	
	@app.route("/success")
	def success():
	return flask.render_template('success.html')
	
#######################
# Form handler.
# CIS 322 note:
#   You'll need to change this to a
#   a JSON request handler
#######################
	
	
	@app.route("/_check", methods=["POST"])
	def check():
	"""
	User has submitted the form with a word ('attempt')
	that should be formed from the jumble and on the
	vocabulary list.  We respond depending on whether
	the word is on the vocab list (therefore correctly spelled),
	made only from the jumble letters, and not a word they
	already found.
	"""
	app.logger.debug("Entering check")
	
# The data we need, from form and from cookie
	text = flask.request.form["attempt"]
	jumble = flask.session["jumble"]
	matches = flask.session.get("matches", [])  # Default to empty list
	
	success = false		#flag
	
	
# Is it good?
	in_jumble = LetterBag(jumble).contains(text)
	matched = WORDS.has(text)
	
# Respond appropriately
	if matched and in_jumble and not (text in matches):
# Cool, they found a new word
	matches.append(text)
		flask.session["matches"] = matches	
        message = “Hey, you  found {}!".format(text)
            return flask.jsonify(message = message, target=flask.session["target_count"])                                                               
		elif text in matches:
			message = “You already found {}".format(text)
            return flask.jsonify(message = message, target=flask.session["target_count"])
		elif not matched:
			message = “{} isn't in the list of words".format(text)