Python小遊戲之王者榮耀

歡迎來到王者榮耀…
閒來無事,寫點代碼複習複習!
遊戲內容涉及:
1.隨機數生成
2.相關模塊用法
3.0 1 用法
4.條件判斷
5.循環
6.列表
7.單詞的記憶…mmp(你四級過了嗎…)

注意:光理論是不夠的,送大家一套2020最新企業Pyhon項目實戰視頻教程,點擊此處進來獲取 跟着練習下,希望大家一起進步哦!

import random
print('*'*40)
print('\t歡迎來到王者榮耀')
print('*'*40)
role=input('請選擇遊戲人物:(1.魯班 2.后羿 3.李白 4.孫尚香 5.貂蟬 6.諸葛亮)')
coins=3000
#保存自己武器的容器
weapon_list=[]
print('歡迎!{1}來到王者榮耀,當前金幣是:{0}'.format(coins,role))
while True:
	choice=int(input('\n請選擇:\n 1.購買武器\n 2.打仗\n 3.刪除武器\n 4.查看武器\n 5.退出遊戲\n'))
	if choice==1:
		#購買武器
		print('歡迎進入武器庫:')
		weapons=[['暗影戰斧',2090],['破軍',2950],['破曉',3400],['制裁之刃',1800],['純淨蒼穹',2230],['碎星錘',2100]]
		for weapon in weapons:
			print(weapon[0],weapon[1],sep='    ')
		#提示輸入要購買的武器
		weaponname=input('請輸入要購買的武器名稱:')
		#1.原來有沒有買過武器 2.輸入後是否有武器
		if weaponname not in weapon_list:
			#輸入的武器名是否在武器庫中
			for weapon in weapons:
				if weaponname == weapon[0]:
					#購買武器
					if coins >= weapon[1]:
						coins-=weapon[1]
						weapon_list.append(weapon[0]) #添加到自己的武器庫中
						print('{}購買武器:{}'.format(role,weaponname))
						break
					else:
						print('金幣不足,趕快掙金幣去吧!')
						break
			else:
				print('輸入武器名稱錯誤')
		print('已經擁有該武器!')
	elif choice==2:
		#打仗 假設有多個武器
		print('歡迎來到王者榮耀戰場')
		if len(weapon_list)>0:
			#選擇武器
			print('{}擁有的武器如下:'.format(role))
			for weapon in weapon_list:  #拿到武器列表
				print(weapon)
			weaponname = input('請選擇:')
			if weaponname in weapon_list:
				#進入戰爭狀態 默認和張飛對戰(也可以隨機選擇)
				ran1 = random.randint(1,20) #張飛
				ran2 = random.randint(1,20) #role
				if ran1>ran2:
					print('此局對戰:張飛勝!!!')
				elif ran1<ran2:
					print('此局對戰:{}勝'.format(role))
					coins+=200
					print('此局對戰:{}勝!金幣{}'.format(role,coins))
				else:
					print('此局平局,可再次對戰')

			else:
				print('選擇的武器不存在,請重新選擇')
		else:
			print('還沒有購買武器,趕快使用金幣購買武器去吧')
	elif choice==3:
		#刪除武器
		print('武器太多啦,快扔掉一點吧.........')
		if len(weapon_list)>0:		
			print('{}擁有的武器如下:'.format(role))
			for weapon in weapon_list:
				print(weapon)
			while True:
				weaponname = input('請選擇需要刪除的武器名稱:')
				if weaponname in weapon_list:
						#刪除武器 remove,del,pop,clear
						weapon_list.remove(weaponname)
						for weapon in weapons:
							if weaponname==weapon[0]:
								coins+=weapon[1]
								break
						break
				else:
					print('武器名稱輸入有誤!')
		else:
			print('你都沒有武器,還沉啥......,快購買武器去吧!')
	elif choice==4:
		#遍歷武器
		print('{}擁有的武器如下:'.format(role))
		for weapon in weapon_list: 
			print(weapon)
		print('總金幣:',coins)
	elif choice==5:
		answer=input('確認要離開王者榮耀遊戲嗎?(yes/no)')
		if answer=='yes':
			print('GAME OVER')
			break
	else:
		print('輸入錯誤,請重新選擇')

注意:最後送大家一套2020最新企業Pyhon項目實戰視頻教程,點擊此處 進來獲取 跟着練習下,希望大家一起進步哦!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章