Sharedwww / talks / 2006-05-09-sage-digipen / tutorial / run_tofudemo.pyOpen in CoCalc
Author: William A. Stein
1
#! /usr/bin/python -O
2
3
# Game Skeleton
4
# Copyright (C) 2005 Jean-Baptiste LAMY
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20
# Soya gaming tutorial, lesson 6
21
# Network gaming with Tofu !
22
23
# Run this script to launch the demo.
24
# For more info, do :
25
#
26
# python ./run_tofudemo.py --help
27
28
from tofudemo import *
29
30
31
# Print usage
32
33
if (not sys.argv[1:]) or ("--help" in sys.argv):
34
print """run_tofudemo.py -- Launch Soya Tofu Demo
35
Usages :
36
37
python run_demo.py --single <login> [<password>]
38
Starts a single player game
39
40
python run_demo.py --server
41
Starts the server
42
43
python run_demo.py --client <host> <login> [<password>]
44
Starts a client and connect to server <host> with login <login>
45
and password <password>. If login doesn't exist, a new player is
46
created.
47
"""
48
49
else:
50
51
# Creates and run an Idler
52
# To enable Tofu, we must use soya.tofu4soya.Idler; this special Idler combine
53
# soya.Idler and tofu.Idler in a single one.
54
55
soya.tofu4soya.Idler(scene)
56
57
58
# Lauch a single player game, a server or a client.
59
# For both client and single player game, we initialize Soya. For server, we DON'T
60
# initialize Soya, in order to not show the 3D rendering window.
61
# Calling serve_forever will start the idler.
62
63
if sys.argv[1] == "--single":
64
soya.init()
65
66
import tofu.single
67
tofu.single.serve_forever()
68
69
elif sys.argv[1] == "--server":
70
import tofu.server
71
tofu.server.serve_forever()
72
73
elif sys.argv[1] == "--client":
74
soya.init()
75
76
import tofu.client
77
hostname = sys.argv[2]
78
tofu.client.serve_forever(hostname)
79
80