/usr/share/pyshared/tofu/single.py is in python-tofu 0.5-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | # TOFU
# Copyright (C) 2005 Jean-Baptiste LAMY
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""tofu.single
This module implements a Tofu single-player game (no network).
To lauch a single-player game, create a GameInterface instance, import this module,
and then call serve_forever().
"""
#from twisted.internet import reactor
import tofu
class Notifier(tofu.Notifier):
def __init__(self):
tofu.Notifier.__init__(self)
self.player = None
def login_player(self, filename, password, client_side_data = ""):
try: player = tofu.YourPlayer.get(filename)
except ValueError: player = tofu.YourPlayer(filename, password, client_side_data)
if password != player.password: raise ValueError("Password is wrong !")
player.login(self, 1, client_side_data)
self.player = player
def logout_player(self):
self.player.logout()
self.player = None
def notify_own_control(self, mobile):
mobile.control_owned()
def check_level_activity(self, level):
# XXX bots
for mobile in level.mobiles:
if (not mobile.controller.remote) and (not mobile.bot):
level.set_active(1)
return
# No local user for this level => we can inactive it
level.set_active(0)
def notify_discard(self, unique):
# Saves all data locally
if isinstance(unique, tofu.SavedInAPath) and unique.filename: unique.save()
def serve_forever(*args, **kargs):
"""serve_forever(*ARGS, **KARGS)
Starts a single-player game. ARGS and KARGS are passed to GameInterface.__init__()."""
tofu.YourGameInterface(*args, **kargs)
notifier = Notifier()
#reactor.callLater(0.0, lambda : tofu.GAME_INTERFACE.ready(notifier))
tofu.IDLER.next_round_tasks.append(lambda : tofu.GAME_INTERFACE.ready(notifier))
return tofu.IDLER.idle()
|