python sample code
#####################################################################################
# Agent.cs by Jessica.kjm ,
#
# About the sample:
# i havent seen sammy for three days.where is he? is he lost?
# i try to find him.then i wrote this small game.
#
# KEY WORDS:IRONPYTHON1.0 PYTHON2.5 clr time AddReferenceToFile msagent
# Description:
# 1) using the clr.AddReferenceToFile :its a easy way to call component in python.
# 2) msagent.dll :its an agent server pre-installed in windows.
# Dependency:
# 1) Ironpython1.01
# 2) PYTHON 2.5:
# 3) DotNet Framework 2.0.
####################################################################################
###
### import agentserver
###
import clr
clr.AddReferenceToFile("AgentServerObjects.dll")
from AgentServerObjects import *
import sys
import time
###
### copy .acs to %windir%\msagent\chars
###
#from shutil import *
#copyfile(".\\mnkyking.acs","%windir%\\msagent\\chars\\.")
###
### load agent and show
###
a = AgentServerClass()
cid = a.Load(".\\mnkyking.acs")[0];
c = a.GetCharacter(cid)
c.SetPosition(250,250)
c.Show(0)
time.sleep(1)
###
### define globals variable
###
for n in c.GetAnimationNames(): globals()[n] = lambda name=n: c.Play(name)
### play "Say Hello!"
Greeting()
Wave()
time.sleep(5)
### play "Say Hello!"
c.Think("where is sammy?")
time.sleep(5)
### play "finding"
LookRight()
time.sleep(2)
LookLeft()
time.sleep(2)
LookUp()
time.sleep(2)
LookDown()
time.sleep(2)
### play "Let me search for him!"
c.Think("Let me search for him!")
time.sleep(1)
c.Speak("sammy!","where r u?")
Searching()
time.sleep(15)
### play "find it!"
c.Speak("sammy!u r here!","coming!")
time.sleep(5)
c.StopAll(0)
### play "888888!"
GetAttention()
time.sleep(5)
c.Think("u r here!i find u!")
time.sleep(1)
Idle_swing();
time.sleep(10)
### play "bye!"
c.StopAll(0)
c.Think("c u later!")
time.sleep(1)
Goodbye()
time.sleep(5)
c.StopAll(0)
c.Hide(0)
顺便有两个问题请教下大家:
1) 我如何发布这个程序呢?它运行的时候究竟需要IronPython和Python中的哪些文件呢?
我试着copy了所有文件到其他机器上运行,一台可以运行但提示报错;一台始终连ipy都不能正常运行。
我看到说要写安装脚本,但没看太懂。如果copy式傻瓜安装就好了。
2) 要使我的朋友sammy能够欣赏到这个小小的game,必须装DotNet框架。因为我使用了IronPython。如果不使用IronPython;我该怎么直接使用python中的包来完成调用com组件的功能呢?
希望高手指点(最好有例子代码),不胜感激!