Counting Game Source Code

Controller

[sourcecode language="css"]
import view
import model

class Controller:
def __init__(self):
self.view = view.View()
“”"
Call this method to start a new game starting at level 1
“”"
def start_new_game(self):
self.level_num = 1
self.start_game()
“”"
Call this method to start a new game at a certain level
“”"
def start_game_at_level(self, level):
self.level_num = level
self.start_game()
“”"
Call this method to start a game based on current level
“”"
def start_game(self):
self.score = 0
if self.level_num < 3:
self.level = model.CountingLevel()
else:
self.level = model.AdditionLevel()
self.ask_new_question()
"""
Asks the current question
"""
def ask_question(self):
self.view.display_question(self.question, self.handle_answer)
"""
Asks a newly generated question
"""
def ask_new_question(self):
self.question = self.level.get_question()
self.ask_question()
"""
Returns a boolean whether the given answer matches the level's answer or not
"""
def verify_answer(self, answer):
return self.level.is_correct(answer)
"""
Callback for the view when an answer is given. Determines what to do with the given answer and how to proceed.
"""
def handle_answer(self, answer):
if self.verify_answer(answer):
# Success, go to next level
self.score = self.score + 3
if (self.level.questions_left > 0) and (self.score < (3 * 15)):
# Ask another question
self.ask_new_question()
else:
# Answered all of the questions in the level, ask if want to go to next level
if self.view.ask_next_level():
self.level_num = self.level_num + 1
self.start_game()
else:
# User wants to stay on this level, so ask new questions
self.ask_new_question()
else:
# Failed, try again with same question?
self.ask_question()
[/sourcecode]

Model
[sourcecode language="css"]
from random import randint

class Level:
def __init__(self):
pass
“”"
Returns a new question to ask
“”"
def get_question(self):
raise NotImplementedError( “Should have implemented this” )
“”"
Returns True if answer is the solution to the question
“”"
def is_correct(self, answer):
raise NotImplementedError( “Should have implemented this” )

class CountingLevel(Level):
def __init__(self):
self.questions_left = 20
“”"
Returns a new question to ask
“”"
def get_question(self):
self.questions_left = self.questions_left – 1
self.answer = randint(0, 10) # Number of objects
# Return in a way for the view to parse and display animals/objects
self.question = “counting: ” + str(self.answer)
return self.question
“”"
Returns True if answer is the solution to the question
“”"
def is_correct(self, answer):
try:
given_answer = int(answer)
except ValueError:
return False
return given_answer == self.answer

class AdditionLevel(Level):
def __init__(self):
self.questions_left = 20
“”"
Returns a new question to ask
“”"
def get_question(self):
self.questions_left = self.questions_left – 1
self.addend1 = randint(0, 10)
self.addend2 = randint(0, 10)
self.answer = self.addend1 + self.addend2
# Return in a way for the view to parse and display animals/objects
self.question = “addition: ” + str(self.addend1) + ” ” + str(self.addend2)
return self.question
“”"
Returns True if answer is the solution to the question
“”"
def is_correct(self, answer):
try:
given_answer = int(answer)
except ValueError:
return False
return given_answer == self.answer
[/sourcecode]

View
[sourcecode language="css"]
class View:
def __init__(self):
pass
def display_question(self, question, callback):
# TODO: Parse question to know how to represent the animals/objects
self.callback = callback
print(question) # Test
def handle_answer(self, user_input):
#self.callback(user_input)
pass
def background(self):
#show window background
pass
def correct_view(self):
pass
[/sourcecode]

[Final Version] Counting Game Architecture: Model-View-Controller

Below is the final version of the counting game’s architecture.

Architecture

Model
Player
- Scores: Current and High
- Name
- Current Level
Level
- Level: low and high
- Counting level (level 1 and 2): number of bears
- Addition level (level 3 to 5): Number of bears and Number of hamburgers
- Guess/Answer -> Boolean
- Question Count
- Score/Sound
- Counting level
View
Starting
- Beginning screen/ the picture that show on the screen every time player(s) start the game
Questions
- Pictures that contain object(s) for player to count
Award
- Pop up on the screen when player(s) completed each level
Demo
- Show player how to play the game
- One for each level
Controller
Main
Update (Data/users’ interaction)

More Details on Our Counting Game Project

Function/settings:

  • The player(s) can choice the level that they want to play in the beginning of the game
  • The player(s) can able to quit at any time during the game
  • There are 20 Questions for each level
  • Player(s) can rearrange the objects on the screen
  • Different set of animal(s) for each question
  • Lock/Unlock – player(s) need to complete the lower level before move to the upper level
  • Save option
  • Start new game option

Scoring system:

  • Score displays on the upper corner
  • Player(s) can see the cumulative score on the upper corner after answering each question
  • 1 to 3 points (3 points – first try, 2 points– second try, 1 point – beyond third try)

Sound features:

  • Achieve a new level: Happy Sound
  • Answer question correctly: Reward sound
  • Answer question incorrect: No sound, pop up a message such as “try again”

Design:

  • A friendly reminder message will be popped up, if the answer isn’t entered within 10 minutes
  • Animation demo for each level
  • Player(s) can choose to watch the demo or skip to the game (Flash)
  • Story plots – level 3 or above (addition/subtraction)

Optional:

  • Player(s) get extra scores if finish the game within X minutes

Graphics:

  • Starting screen (beginning of the game)
  • Pictures for questions (one picture for each question)
  • Reward picture (at the time player(s) finish each level)

Ideas for Our Next Project

Below are some ideas that we came up for our next project during last week’s meeting.

Type: Counting game
Target group: 6 to 7 years old
Game design:
Player needs to count the number of cute animals (or some other cute objects) that appear on the screen then enter the number in the input box. As the level goes up, player will need to do simple addition/subtraction.
Level 1: Player will count up to 10 animals/objects
Level 2: Player will count up to 20 animals/objects
Level 3: Player will do simple addition (the answers are limited to 10 or less)
Level 4: Player will do simple subtraction (the answers are limited to 10 or less, but bigger than 0)
Level 5: Player will do simple addition or subtraction (the answers are limited to 20 or less, but bigger than 0)
Ideas:
Story type – Five bears visit a restaurant, but the restaurant only serves three hamburgers to the bears. How many more hamburgers does the restaurant need to make for the bears so that all bears have a hamburger to eat?
Number only – example: 5 – 2 = ?

First Meeting of the School Year

We finally have a place to hold the weekly meeting! We reserved room 026 in the EE building for our weekly meeting throughout this quarter. Sorry for the delay, but there were many little things needed to be taken care of before the club able to request room reservation. The first meeting for this quarter (actually this school year) is next Friday from 5:00pm to 6:00pm.

Hope to see you there.