學習物件導向時的乙個小想法,鬧著玩的,在定義人,裝備,野怪屬性時可以考慮用繼承方法做,方便一些。
遊戲劇本,一開始會出現,定義名字,性別,年齡(沒什麼用的屬性)
接下來隨機發你個裝備,遇見野怪,是否戰鬥,'y』戰鬥,'n』逃跑,戰鬥失敗人物死亡,提示是否重新來,'y』從新開始,'n』遊戲結束
# coding=utf-8
import random
class person:
def __init__(self, name, ***, age, level, ad, hp):
self.name = name
self.*** = ***
self.age = age
self.leve = level
self.ad = ad
self.ap = 0
self.hp = hp
def equip(self, tool):
self.tool = tool
self.ad = self.ad+tool.ad
self.ap = self.ap+tool.ap
def fight(self):
n = 99
list = [wild_boar, wild_dog, birdie, tiger, mouse, dragon]
while people_one.leve <= n:
k = random.randint(0, 5)
print('遇到', list[k].name)
key = input('是否進行戰鬥,y & n')
try:
if key == 'y':
print('進行戰鬥')
if self.ad > list[k].hp:
print('%s用%s擊殺了%s' % (self.name, self.tool.name, list[k].name))
print('you win,公升級了', 'leve=', people_one.leve)
people_one.leve = people_one.leve+1
else:
print('%s吃掉了%s' % (list[k].name, people_one.name))
print('you dad')
i = input('是否重新開始, y & n')
if i == 'y':
i = random.randint(0, 5)
equip_list = [knife, spear, cloak, plate, gemstone, shoes]
people_one.equip(equip_list[i])
print(people_one.tool.name)
print(people_one.ap, people_one.ad)
callable(people_one.fight())
else:
print('遊戲結束')
break
else:
print('開始逃跑')
except:
print('遊戲bug')
class equipment:
def __init__(self, name, hp, ad, ap, armor, magic_resistance):
self.name = name
self.hp = hp
self.ad = ad
self.ap = ap
self.armor = armor
self.magic_resistance = magic_resistance
class wildmonster:
def __init__(self, name, ad, ap, hp, armor, magic_resistance):
self.name = name
self.ad = ad
self.ap = ap
self.hp = hp
self.armor = armor
self.magic_resistance = magic_resistance
keyword_1 = input('請輸入名字')
keyword_2 = input('請輸入性別')
keyword_3 = input('請輸入年齡')
'''people'''
people_one = person(keyword_1, keyword_2, keyword_3, 1, 10, 100)
'''knife, spear, cloak, plate, gemstone, shoes'''
knife = equipment('小刀', 80, 20, 0, 0, 0)
spear = equipment('長槍', 50, 40, 0, 0, 0)
cloak = equipment('斗篷', 30, 50, 0, 20, 10)
plate = equipment('板甲', 60, 50, 0, 40, 0)
gemstone = equipment('寶石', 70, 0, 0, 0, 50)
shoes = equipment('鞋子', 20, 0, 50, 10, 10)
'''wild_boar, wil_dog, birdie, tiger, mouse, dragon'''
wild_boar = wildmonster('野豬', 20, 0, 10, 5, 5)
wild_dog = wildmonster('野狗', 10, 0, 5, 0, 0)
birdie = wildmonster('鳥', 5, 0, 10, 0, 0)
tiger = wildmonster('老虎', 30, 0, 30, 10, 10)
mouse = wildmonster('老鼠', 10, 0, 5, 5, 5)
dragon = wildmonster('巨龍', 100, 0, 100, 50, 50)
''''''
i = random.randint(0, 5)
equip_list = [knife, spear, cloak, plate, gemstone, shoes]
people_one.equip(equip_list[i])
print(people_one.tool.name)
print(people_one.ap, people_one.ad)
# k = random.randint(0, 5)
# list = [wild_boar, wild_dog, birdie, tiger, mouse, dragon]
# people_one.fight(list[k])
# n = 99
# while people_one.leve <= n:
# k = random.randint(0, 5)
people_one.fight()
簡單的C 物件導向打怪小遊戲
簡單的boos打小怪,還能繼續優化。battle.h pragma once 防止標頭檔案重複 class battle battle.cpp include include battle.h using namespace std battle battle g attack new int 2 ...
打怪小遊戲
打怪小遊戲 include using namespace std double shengmingli 2000 定義主角初始生命力 int gongjili 150 定義主角初始攻擊力 int fangyuli 200 定義主角初始防禦力 int money 20 定義主角初始金錢數量 bool...
打怪小遊戲
打怪小遊戲,好玩到爆!include include include using namespace std double shanghai 20 double bosshealth 20 double wj shanghai 1,wj health 10,wj max health 10,boss...