 # Start Game {{{
 
 startGame = () ->
-	CANVAS = $("<canvas></canvas>")
-	CANVAS.attr "height", CANVAS_HEIGHT
-	CANVAS.attr "width",  CANVAS_WIDTH
-	CANVAS.click onDiagramClick
-
-	CONTEXT = CANVAS.get(0).getContext("2d")
-	$("#site").empty()
-	$("#site").append(CANVAS)
-	$("#check_button").click onCheckButtonClick
-	$("#check_button").prop('disabled', false)
-	$("#done_button").click onDoneButtonClick
-	$("#done_button").prop('disabled', false)
-
-	loadDiagram "demo2"
+	game = new Game()
+	loadDiagram "demo1"
+	markAllActive
 # }}}
 
 # Main function {{{

# High-level things
markAllActive = (c = "blue") ->
	clearAll()
	# Mark all selected points
	for p in active_points
		fillCircle(p, color=c, r=5)
		drawCircle(p, color=c, r=30)
	$("span#active_points").html(active_points.toString())

	# Decide whether "Check", Done button enabled
	enableButtonIf("#check_button", active_points.length > 0)
	enableButtonIf("#done_button", (active_points.length == 0) &&
		(diagram.unfound_tuples.length != diagram.tuples.length))

# }}}
# Click handler {{{
toggle = (p) ->
	if not (p in active_points)
		active_points.push(p)
	else
		del(active_points, p)
	markAllActive()

onDiagramClick = (e) ->

		toggle p

onCheckButtonClick = (e) ->
	clone = diagram.active_points.slice(0) # I hate JS
	stringifiedActive = JSON.stringify(
		(p.toString() for p in pointSort(clone)) )
	if stringifiedActive in diagram.unfound_tuples
		# Good job, delete it
		$("#found").append(
			$("<li>" + diagram.active_points.toString() + "</li>"))
		del(diagram.unfound_tuples, stringifiedActive)
		# Highlight green momentarily
		markAllActive("green")
		diagram.active_points = []
		setTimeout markAllActive, 400
		tempAddClass "#check_button", "button_green"
	else
