The Theory and Practice of Writing Music for Games