Differences between revisions 4 and 5
Revision 4 as of 2006-04-25 15:46:12
Size: 967
Editor: HuangYi
Comment:
Revision 5 as of 2009-12-25 07:11:12
Size: 969
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
[[TableOfContents]] <<TableOfContents>>
Line 34: Line 34:
 * ["Action Pattern Implement"]  * [[Action_Pattern_Implement]]
Line 36: Line 36:
 * 晚上看 [http://harkal.sylphis3d.com/2005/08/10/multithreaded-game-scripting-with-stackless-python/ 这篇好文]的时候, 看到里面有一部分讲到Action模式在游戏里面的应用, 感觉有点意思就随手写了写, 总算赶在熄灯之前搞定, 呵呵。  * 晚上看 [[http://harkal.sylphis3d.com/2005/08/10/multithreaded-game-scripting-with-stackless-python/|这篇好文]]的时候, 看到里面有一部分讲到Action模式在游戏里面的应用, 感觉有点意思就随手写了写, 总算赶在熄灯之前搞定, 呵呵。

模拟range的参数传递方式

刚才写程序的时候突然想到的, 模拟个range ( range([start],stop,[step]) ) 的参数机制。

   1 def myrange(stop,start=None,step=None):
   2   if not start:
   3     return range(stop)
   4   elif not step:
   5     return range(stop,start)
   6   else:
   7     return range(stop,start,step)

测试:

   1 >>> myrange(5)
   2 [0, 1, 2, 3, 4]
   3 >>> myrange(1,5)
   4 [1, 2, 3, 4]
   5 >>> myrange(1,5,2)
   6 [1, 3]

呵呵, python果然够灵活。

Action模式实现

  • Action_Pattern_Implement

  • 晚上看 这篇好文的时候, 看到里面有一部分讲到Action模式在游戏里面的应用, 感觉有点意思就随手写了写, 总算赶在熄灯之前搞定, 呵呵。


huangyi/2006-04-25 (last edited 2009-12-25 07:11:12 by localhost)