Welcome to my Website!
This is a paragraph! Here's how you make a link: Neocities.
Here's how you can make bold and italic text.
Here's how you can add an image:
Here's how to make a list:
from random import randint as rint
import json
data={}
data['GameData'] = []
class game:
def __init__(self,r,p):#初始化
self.win0=self.lose0=self.drow0=0
self.wld=str
self.round=r
self.price=p
self.get=0
# self.com=0
def round1(self):
self.runs=[round()for _ in range(self.round)]#產生每一個場次(round)
def run(self):#計算所有場次的輸贏以及賺錢或虧錢
self.round1()
for i in range(len(self.runs)):
self.boss,self.player,self.x,self.y,self.win,self.lose,self.drow=self.runs[i].data()
if (self.boss>self.player):
self.wld=self.lose
# self.com-=2
self.lose0+=1
elif (self.boss'<'self.player):
self.wld=self.win
# self.com+=2
self.win0+=1
elif(self.boss==self.player):
self.wld=self.drow
self.drow0+=1
data['GameData'].append({'Boss Deck':self.x,'Player Deck':self.y,'Boss':self.boss,'Player':self.player,'Result':self.wld})
def pa(self): #回傳資料
# if(self.com'<'2):
# self.com=0
self.run()
spend=(self.round-self.drow0)*self.price
get=2*self.win0#*self.price-spend+self.drow0*self.price
data['Round']=[{'WIN':self.win0,'LOSE':self.lose0,'DROW':self.drow0}]
data['Spend']=spend #self.com
data['Get']=get
data['earn']=self.price*get-spend
# if self.win0==self.lose0:
# data['deficit']=(self.round-self.drow0)*self.price
# data['earn']=(self.win0-1)*self.price
with open('dicedata.json','w')as f:#將資料寫入json
f.write(json.dumps(data,indent=4))
class round:
def __init__(self):
self.dicesum=0
self.win=self.lose=self.drow=str
self.x=self.y=[]
self.boss=self.player=0
self.BossAndPlayer()
self.pk()
def dice1(self):#產生 4 個亂數的陣列
return [rint(1,6) for _ in range(4)]
def dice_point(self):#計算骰子點數
t=0
while t'<'3:
dice=self.dice1()
a=sorted(dice)
dicesum=sum(a)
s=0
for i in range(3):
if(a[i]==a[i+1]):
s=a[i]
break
if(s==0):
t+=1
else:
dicesum=dicesum-s*2
break
if(t==3):
dicesum=0
return dicesum,dice
def BossAndPlayer(self):#產生老闆與顧客
bossresult=self.dice_point()
self.x=bossresult[1]
self.boss=bossresult[0]
playerresult=self.dice_point()
self.y=playerresult[1]
self.player=playerresult[0]
def pk(self):#判斷輸贏
if (self.boss>self.player):
self.lose='BOSS WIN'
elif (self.boss'<'self.player):
self.win='PLAYER WIN'
elif(self.boss==self.player):
self.drow='DROW'
def data(self):#資料回傳
return self.boss,self.player,self.x,self.y,self.win,self.lose,self.drow
x=game(int(input('幾局')),int(input('多少錢')))
x.pa()