Project1

标题: 把判定喂食的腳本寫好惹.... [打印本页]

作者: 熊喵酱    时间: 2013-10-19 10:30
标题: 把判定喂食的腳本寫好惹....
Ruby很強大.
只能說這一句話
  1. class Feed
    7 g0 i5 f8 h# W; x3 U
  2.   def initialize(type, like, dislike)
    0 [/ m  H* z) U: n4 A
  3.     @like_type = like
    , M/ S6 t; ?, _8 ^2 v. e( J
  4.     @dislike_type = dislike# X0 @2 a1 q" ~7 a# i
  5.     @type = type
    3 s* e3 n* U% u8 ^. z
  6.     start) _; V' h9 O! C- y
  7.   end
    % p' f/ b0 h8 w  d
  8.   def start
    ! H% X! U: ?; h
  9.     case @type
    " d  v9 L2 U9 ?, J
  10.       when 1 #Waters
    / c% L% s  D+ |% y: y9 x1 A
  11.         p "成長值增加了#{rand(3)+1},積分增加了#{rand(3)+1}"6 m0 i: H4 M% j# V5 o( D
  12.       when 2 #Fruits
    ( D4 e2 |0 K; Z4 O  j
  13.         a = 2 if @like_type = 2
    ; ]7 w# R  M3 v4 C" J, t+ j
  14.         a = -2 if @dislike_type = 2
    * z# X7 F8 y( I: }$ h# E- M
  15.         p "成長值增加了#{rand(5)+a},積分增加了-1"5 g; o' `) ?; C8 O4 @
  16.       when 3 #Insects' G. [7 X* q7 A. y8 f$ c% C
  17.         a = 3 if @like_type = 33 P6 Q% y5 o7 Y3 _* j# b6 q% j) @) E, B3 Y
  18.         a = -3 if @dislike_type = 3
    0 G2 p: h# Q0 a" Z! b
  19.         p "成長值增加了#{rand(6)+a},積分增加了-1"1 T  m2 e' E8 [4 T, x, q3 q
  20.       when 4
    7 w( P' I+ T1 h
  21.       a = 3 if @like_type = 3
    & M8 }  j' ^0 @
  22.       a = -3 if @dislike_type = 30 `5 A  {% A- p3 ^/ H0 [
  23.       p "成長值增加了#{rand(8)+a},積分增加了-2"7 j3 Q/ I* Y+ s, G& c+ V
  24.     end+ t) p( Z6 R, N8 ?7 Y
  25.   end, W# p) M) ~4 E/ u+ |0 H* x
  26. end
复制代码
調用方法:
  1. Feed.new(feeding type, like type, dislike type)
复制代码
feeding type(喂食種類) 有四種選擇:1 f  v" V8 X* ]
1.! V" F" H) L* _- f
2.果子8 ?! r0 s! h# Y% u  o
3.昆蟲$ A+ V& q. H* p# e
4.3 w5 L2 K1 w5 t' \' I' g, J
like type(喜歡種類) 有三種選擇:
, ^! w+ r, V9 _; K5 U9 p+ A1.果子
' I/ J0 Q' }* d& ^2.昆蟲
/ X' m; n( t3 J8 ^' C0 G3 Z, s- {3.8 `1 S( s. h6 o# z) a
dislike type(不喜歡種類) 有三種選擇:
4 n  {# F0 P$ V' ?1.果子0 e+ |7 V! f+ B: W# ^
2.昆蟲
: a& e1 V3 _- a: k9 P. A5 O3.: w% h- _( B* |1 f  V
例子:
  1. Feed.new(1,3,4)
复制代码
代表喂了$ ~+ K" y- W1 f- }
然後喂食者喜歡昆蟲  不喜歡




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1