roguev6 > system.py


※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

doctestが動いていないことに気づく。

テスト書き直ししまする(´・ω・)

#coding:shift_jis

# ゲーム中における最大キャラクタ数
GAME_OBJECT_NUM = 1024

# ゲーム中における最大アイテム数
GAME_ITEM_NUM = 1024

#敵キャラクタパラメータテーブル
#コンストラクタに *(enemy_param[敵キャラ名])で渡せるようにする。
#(hp, power, defence, money, speed, evade, origin_values={'key':value})
enemy_param = {
    'player'   : (100, 10, 10, 10, 1, 0, {'sex_male':True,}),

    'goblin'         : (100, 20, 10, 23, 1, 0, {'kinoko':300}),

    'tukiyono_ookami': (100, 10, 10, 10, 1, 0, None),
 
    'ontama':          (100, 10, 10, 10, 1, 0, None),
    'kotodama':        (100, 10, 10, 10, 1, 0, None),

    'hiyoko_storker':  (100, 10, 10, 10, 1, 1, None),
    'storker':         (100, 10, 10, 10, 1, 1, None),
    'night_storker':   (100, 10, 10, 10, 1, 1, None),

    'madman':          (100, 10, 10, 10, 0, 1, None),
    'sandman':         (100, 10, 10, 10, 0, 1, None),
    'rockman':         (100, 10, 10, 10, 0, 1, None),

    'kitune_miko':     (100, 10, 10, 10, 0, 1, None),
    'kitune_kitousi':  (100, 10, 10, 10, 0, 1, None),

    'air_mole':        (100, 10, 10, 10, 0, 1, None),
    
    'kakasi_obake':    (100, 10, 10, 10, 0, 1, None),

    'neco':            (100, 10, 10, 10, 0, 1, None),
    'necoco':          (100, 10, 10, 10, 0, 1, None),
    'nenecoco':        (100, 10, 10, 10, 0, 1, None),
}


class CharcterParam:
  def __init__(self,name,hp,pow,dfn,mon,spd,evd,tag):
    self.maxhp=hp
    self.power=pow
    self.defence=dfn
    self.money=mon
    self.speed=spd
    self.evade = evd
    self.name = name
    if tag:
      self.tag=tag.copy()
    else:
      self.tag={}
    #特殊パラメータはキーとバリューによって表記,
  def copy(self):
    return CharcterParam(
        name= self.name,
        hp=self.maxhp,
        pow=self.power,
        dfn=self.defence,
        mon=self.money,
        spd=self.speed,
        evd=self.evade,
        tag=self.tag.copy() )

#パラメータを生成する関数
def make_param(name):
  return CharcterParam(name,*enemy_param[name])

# ---
# システム計算式、パラメータ列挙のスクリプト
# ---

def damage_culc(victimizer,victim):
  #ドラクエ式+ゲタはかせ
  base_damage = victimizer.power/2 - victim.defence/4
  if base_damage <=0:
    base_damage=1
  return base_damage


def test_code():
  goblin= CharcterParam('goblin',*enemy_param['goblin'])
  goblin_param = enemy_param['goblin']
  assert goblin.maxhp == goblin_param[0]
  assert goblin.power == goblin_param[1]
  assert goblin.defence == goblin_param[2]
  assert goblin.money == goblin_param[3]
  assert goblin.speed == goblin_param[4]
  assert goblin.evade == goblin_param[5]
  assert goblin.tag == goblin_param[6]
  assert goblin.name == 'goblin'

  g= CharcterParam('goblin',*enemy_param['goblin'])
  goblin_param = enemy_param['goblin']
  goblin = g.copy()
  assert goblin.maxhp == goblin_param[0]
  assert goblin.power == goblin_param[1]
  assert goblin.defence == goblin_param[2]
  assert goblin.money == goblin_param[3]
  assert goblin.speed == goblin_param[4]
  assert goblin.evade == goblin_param[5]
  assert goblin.tag == goblin_param[6]
  assert goblin.name == 'goblin'

  class Stab:
    def __init__(self,pw,df):
      self.power=pw
      self.defence=df
  a = Stab(5,10)
  b = Stab(10,10)
  assert damage_culc(a,b) == 1
  assert damage_culc(b,a) == 3

if __name__=='__main__':
  test_code()