项目部署:
简介:
初衷想复刻《赌博默示录》中的这个游戏,然后提高游戏难度,最后搞得沙雕一点。逻辑写了许多,美工一点没弄,被导师发配企业,且移情别恋剧本杀,等有缘人接盘它。
player.py
'''
玩家类
'''
import random
import time
class Player:
with open("rpsname.txt", 'r', encoding='UTF-8') as f:
player_name = f.readline().split(',') # 静态变量
def __init__(self, id):
self.id = id # 玩家id
self.alive = True # 玩家存活标记
self.win = False # 玩家胜利标记
self.rock = 4 # 石头 - 0
self.paper = 4 # 布 - 1
self.scissors = 4 # 剪刀 - 2
self.stars = 3 # 星星
self.arrears = 0.00 # 贷款金额
self.arrears_final = 0 # 贷款结算
self.money = 0
self.ltime = 0 # 贷款时间
self.buycard_num = 0 # 购买次数
self.prflag = False # 是否是别人同伴的标记
self.partner_0 = [] # 同伴 - 收取所有手牌,游戏结束支付100万人民币
self.partner_1 = [] # 同伴 - 收取所有手牌,并协助其通关
self.human = 0 # 玩家身份
self.card_m = 0 # 赌怪牌
# 玩家身份随机初始化
h = random.randint(1, 20)
if h == 1 or h == 2 or h == 3:
self.human = 1
elif h == 4:
self.human = 2
# 随机加载玩家名字
self.name = Player.player_name[random.randint(0, len(Player.player_name) - 1)]
Player.player_name.remove(self.name) # 保证姓名唯一性
def cardmaster(self, badluck): # 赌怪作弊器
card_list = [badluck.rock, badluck.paper, badluck.scissors]
card = card_list.index(max(card_list))
if card + 1 < 3:
self.card_m = card + 1
card = self.playcard()
return card
else:
return 0
# 玩家出牌
def playcard(self):
if self.human == 1:
# 模拟 15% “高质量人类” 完全随机打牌
index = random.randint(0, 2)
while True:
if index == 0 and self.rock > 0:
self.rock -= 1
break
if index == 1 and self.paper > 0:
self.paper -= 1
break
if index == 2 and self.scissors > 0:
self.scissors -= 1
break
index = random.randint(0, 2)
elif self.human == 2: # 模拟赌怪打牌
while True:
if self.card_m == 0 and self.rock > 0:
self.rock -= 1
index = self.card_m
break
if self.card_m == 1 and self.paper > 0:
self.paper -= 1
index = self.card_m
break
if self.card_m == 2 and self.scissors > 0:
self.scissors -= 1
index = self.card_m
break
self.card_m = random.randint(0, 2)
else:
# 模拟人类,均衡出牌 - 给予数量多的牌种更高的打出权重
card_n = self.rock + self.paper + self.scissors
index = random.randint(1, card_n) # 随机范围[1 - card_n]
if 1 <= index <= self.rock:
index = 0
self.rock -= 1
elif self.rock + 1 <= index <= self.paper + self.rock:
index = 1
self.paper -= 1
elif self.paper + self.rock + 1 <= index <= self.scissors + self.paper + self.rock:
index = 2
self.scissors -= 1
return index
def meplaycard(self, card): # 我的出牌
if card == 0:
self.rock -= 1
elif card == 1:
self.paper -= 1
elif card == 2:
self.scissors -= 1
def isalive(self): # 判断玩家是否GAME OVER
if self.stars == 0:
self.alive = False
elif self.rock == 0 and self.paper == 0 and self.scissors == 0 and self.stars < 3:
self.alive = False
elif self.rock == 0 and self.paper == 0 and self.scissors == 0 and self.stars >= 3:
self.win = True
return self.win, self.alive
def activity(self): # 玩家积极性
card_num = self.rock + self.paper + self.scissors
if card_num >= 10:
return 100
elif 6 <= card_num <= 9:
return 50
elif 4 <= card_num <= 5:
return 25
elif card_num == 3:
return 10
elif card_num == 2:
return 5
elif card_num == 1:
return 1
# 贷款
def startloan(self, arrears):
self.ltime = time.time()
self.money = self.money + arrears
self.arrears = self.arrears + arrears
# 利滚利
def addinterest(self):
etime = time.time()
if etime - self.ltime >= 1:
self.arrears = self.arrears + self.arrears * 0.005
self.arrears_final = float(format(self.arrears, '.2f'))
self.ltime = etime
# 卡牌定价
def buycard(self):
self.buycard_num += 1
if self.buycard_num >= 8:
buyflag = 4 # 滚
return 99999, 99999, buyflag
if self.stars >= 3:
buyflag = 0 # 5万,全买
card_price = 5
tprice = card_price * (self.rock + self.paper + self.scissors)
elif self.rock <= 1 and self.paper <= 1 and self.scissors <= 1:
buyflag = 1 # 不卖
card_price = 99999
tprice = 99999
else:
buyflag = 2 # 自己的理解
if random.randint(1, 10) == 1:
card_price = random.randint(10, 100)
else:
card_price = random.randint(0, 10)
tprice = card_price * (self.rock + self.paper + self.scissors)
return card_price, tprice, buyflag
# 成为同伴
def becomepartner(self):
if self.stars >= 3:
return 0
elif self.stars >= 1:
return (3 - self.stars) * 500
# 与同伴一起消除卡牌
def rmcwithpartner(self, ctype):
if ctype == 0:
if self.rock >= 2:
self.rock -= 2
elif ctype == 1:
if self.paper >= 2:
self.paper -= 2
elif ctype == 2:
if self.scissors >= 2:
self.scissors -= 2
elif ctype == 3:
if self.rock >= 1 and self.paper >= 1:
self.rock -= 1
self.paper -= 1
elif ctype == 4:
if self.paper >= 1 and self.scissors >= 1:
self.paper -= 1
self.scissors -= 1
elif ctype == 5:
if self.scissors >= 1 and self.rock >= 1:
self.scissors -= 1
self.rock -= 1
rsp.py
import pygame
import random
from player import Player
import time
class RSPGame:
def __init__(self, player_number):
self.m_width = 800 # 窗口大小
self.m_height = 600
self.size = (self.m_width, self.m_height)
pygame.init() # 初始化游戏
self.window_main = pygame.display.set_mode(self.size)
pygame.display.set_caption("Rock Paper Scissors") # 标题
self.quit = False
self.clock = pygame.time.Clock()
self.t_rock = 4 * player_number
self.t_paper = 4 * player_number
self.t_scissors = 4 * player_number
self.players = [Player(i) for i in range(player_number - 1)] # 电脑玩家数
self.players_list = [i for i in range(player_number - 1)] # 电脑玩家id列表
self.winner = []
self.me = Player(99999)
self.t_time = time.time()
pygame.draw.rect(self.window_main, (240, 248, 255), (0, 0, self.m_width, self.m_height)) # 背景
def gamestart(self):
while True: # 选择双方对战玩家
p1 = random.choice(self.players_list)
p2 = random.choice(self.players_list)
if (self.players[p1].prflag is False) and (self.players[p2].prflag is False):
if p1 == p2:
continue
active1 = self.players[p1].activity()
active2 = self.players[p2].activity()
if random.randint(1, 100) <= active1 and random.randint(1, 100) <= active2:
self.check(self.players[p1], self.players[p2])
break
break
self.me.addinterest()
# 检查玩家出牌大小
def check(self, player1, player2, mecard=0):
p1_card = 0
p2_card = 0
if player1.id == 99999:
p1_card = mecard
if player2.human == 2:
p2_card = player2.cardmaster(player1)
else:
p2_card = player2.playcard()
pass
else:
# 赌怪打牌
p1_master = False # 初始化变量
p2_master = False
# master
if player1.human == 2 and player2.human != 2:
p1_card = player1.cardmaster(player2)
p1_master = True
elif player1.human != 2 and player2.human == 2:
p2_card = player2.cardmaster(player1)
p2_master = True
# normal
if p1_master is False:
p1_card = player1.playcard()
if p2_master is False:
p2_card = player2.playcard()
winner = player1
loser = player2
if p1_card == 0 and p2_card == 2:
winner = player1
loser = player2
elif p1_card == 2 and p2_card == 0:
winner = player2
loser = player1
elif p1_card < p2_card:
winner = player2
loser = player1
elif p1_card > p2_card:
winner = player1
loser = player2
elif p1_card == p2_card: # 卡牌相同时
win, alive = player1.isalive()
self.checkplayer(win, alive, player1)
win, alive = player2.isalive()
self.checkplayer(win, alive, player2)
self.rvcard(p1_card)
self.rvcard(p2_card)
return 'p'
winner.stars += 1
win, alive = winner.isalive()
self.checkplayer(win, alive, winner)
loser.stars -= 1
win, alive = loser.isalive()
self.checkplayer(win, alive, loser)
self.rvcard(p1_card)
self.rvcard(p2_card)
if player1.id == 99999 and winner.id == 99999:
return 'y'
else:
return 'n'
# 清除比赛队列中的胜利者与失败者
def checkplayer(self, win, alive, player):
if player.id != 99999:
if win is True:
self.winner.append(player)
self.players_list.remove(player.id)
if alive is False: # 人死回收卡牌
self.players_list.remove(player.id)
self.t_rock -= player.rock
self.t_paper -= player.paper
self.t_scissors -= player.scissors
return 0
else:
if win is True:
self.winner.append(player)
return 1
if alive is False:
return 2
# 回收卡牌 - 消除比赛过后的卡
def rvcard(self, card):
if card == 0:
self.t_rock -= 1
if card == 1:
self.t_paper -= 1
if card == 2:
self.t_scissors -= 1
# 卡牌交易
def sellcards(self, buyer, seller, card_price, tprice, buyflag, card):
if card == 999:
r = seller.rock
p = seller.paper
s = seller.scissors
seller.rock = 0
seller.paper = 0
seller.scissors = 0
buyer.rock += r
buyer.paper += p
buyer.scissors += s
if buyflag == 0:
if buyer.money >= tprice:
buyer.money -= tprice
r = seller.rock
p = seller.paper
s = seller.scissors
seller.rock = 0
seller.paper = 0
seller.scissors = 0
win, alive = seller.isalive()
self.checkplayer(win, alive, seller) # seller直接获胜
buyer.rock += r
buyer.paper += p
buyer.scissors += s
elif buyflag == 2:
if buyer.money >= card_price:
buyer.money -= card_price
if card == 0:
seller.rock -= 1
buyer.rock += 1
elif card == 1:
seller.paper -= 1
buyer.paper += 1
elif card == 2:
seller.scissors -= 1
buyer.scissors += 1
# 惩罚
def punishment(self, arrears, msg):
organ = ["眼睛", "肾", "无期", "心脏", "生殖器", "阑尾", "鼻子", "大脑"]
price = [500, 400, 0, 800, 1000, -100, 200, 99999]
if arrears > 1000:
idx = random.randint(0, len(organ) - 1)
if idx == 3:
arrears -= 1000
years = int(arrears / 25)
msg += "由于你负债太多,因此我们对你的身体进行检查,发现你竟然有两颗心脏,于是我们取走了一颗抵债1000万人民币。 \n"
msg += "最终,你将在地下世界强制打工" + str(years) + "年,从此你开始了你的打工生涯。"
elif idx == 2:
years = int(arrears / 25)
msg += "最终,你将在地下世界强制打工" + str(years) + "年,从此你开始了你的无期打工生涯, 可能或许大概应该你再也看不见昨日的太阳。"
elif idx == 7:
msg += "由于你负债太多,因此我们对你的身体进行检查,发现你的大脑非常适合一项秘密项目,于是我们清空了你的负债,但同时你的踪迹也变得无人知晓,只知道你被送往实验室的那天,一架火箭搭载着一个特殊物品前往深空。 \n"
else:
arrears -= price[idx]
years = int(arrears / 25)
msg += "由于你负债太多,因此我们对你的身体进行检查,发现你的身体一切正常,于是我们取走了你的一个" + str(organ[idx]) + \
"抵债" + str(price[idx]) + "万人民币。 \n"
msg += "最终,你将在地下世界强制打工" + str(years) + "年,从此你开始了你的打工生涯。"
else:
years = int(arrears / 25)
msg += "最终,你将在地下世界强制打工" + str(years) + "年,从此你开始了你的打工生涯。"
# 触发结局
def triggeroutcome(self):
win, alive = self.me.isalive()
status = self.checkplayer(win, alive, self.me)
isover = False
overmsg = ["你赢了", "你输了"]
overindex = 0
msg_w_final = ""
if status == 1:
red_stars = self.me.stars - 3
msg_w_final += "手牌打光的这一刻,你拥有" + str(self.me.stars) + \
"颗星星。你成功在本次游戏中存活了下来 \n"
isover = True
overindex = 0
if len(self.me.partner_1) >= 1:
msg_w_final += "但是,"
for i in self.me.partner_1:
msg_w_final += "你的同伴 " + str(i.name) + "缺少" + str(3 - i.stars) + "颗星星。 \n"
if red_stars >= 3 - i.stars:
red_stars -= 3 - i.stars
msg_w_final += "你给予了他缺少的星星,他顺利的通关了。 \n"
else:
msg_w_final += "你已经没有多余的星星给他,你想抛弃他自己通关,结果被他发现打了一顿,并抢走了你身上的所有星星。 \n"
if self.me.arrears > 0:
msg_w_final += "最后判定你在本次游戏中失败,你的500万贷款无法被清空,加之在游戏中你的贷款共负债" + \
str(int(self.me.arrears) - int(self.me.money) + 500) + "万人民币。 \n"
self.punishment(int(self.me.arrears) - int(self.me.money) + 500, msg_w_final)
else:
msg_w_final += "最后判定你在本次游戏中失败,你的500万贷款无法被清空,你将被圈禁在地下世界挖矿,强制打工 20 年来还清贷款。 \n"
msg_w_final += "你也顺利将自己的500万贷款消除了。 \n"
if red_stars >= 1:
self.me.money += red_stars * 500
msg_w_final += "然后你通过拍卖,将多余的星星兑换成了" + str(red_stars * 500) + \
"万人民币。 \n"
if len(self.me.partner_0) >= 1:
for i in self.me.partner_0:
msg_w_final += "按照约定,你支付给你的同伴" + str(i.name) + "100万人民币。"
if self.me.money >= 100:
self.me.money -= 100
msg_w_final += "\n"
else:
msg_w_final += "然而你已经没钱支付了,看在你们一起奋斗的情分上以及你帮助他清空了他的贷款,他不再向你索求报酬。 \n"
if self.me.arrears > 0:
msg_w_final += "由于你在游戏中贷款,最后需要扣除你的贷款和利息共计" + str(int(self.me.arrears)) + "万人民币。 \n"
self.me.money -= int(self.me.arrears)
if self.me.money >= 0:
msg_w_final += "最终,你成功清除了所有贷款,并且赚取了" + str(self.me.money) + "万人民币下船,从此开启了新的人生。"
else:
msg_w_final += "最终,你虽然清除了之前的500万贷款,但是却背上了" + str(-1 * self.me.money) + "万的新贷款,从此开启了新的还贷人生。"
else:
msg_w_final += "最终,你成功清除了所有贷款,并且赚取了" + str(self.me.money) + "万人民币下船,从此开启了新的人生。"
elif status == 2:
isover = True
overindex = 1
msg_w_final += "看到你的失败,你的同伴 "
for i in self.me.partner_0:
msg_w_final += str(i.name) + " "
msg_w_final += "也不管与你之前约定的100万酬金了,反正他们已经达成了通关条件,撒腿就跑了。 \n"
for i in self.me.partner_1:
if 3 - i.stars <= self.me.stars:
msg_w_final += "你的同伴" + str(i.name) + "非常恼怒,抢走了你的" + str(3 - i.stars) + "颗星星,逃走了。 \n"
else:
msg_w_final += "因为你的失败,你的同伴" + str(i.name) + "将被带到地下世界,强制打工 20 年来偿还贷款。 \n"
if self.me.arrears > 0:
msg_w_final += "最后判定你在本次游戏中失败,你的500万贷款无法被清空,加之在游戏中你的贷款共负债" + \
str(int(self.me.arrears) - int(self.me.money) + 500) + "万人民币。 \n"
self.punishment(int(self.me.arrears) - int(self.me.money) + 500, msg_w_final)
else:
msg_w_final += "最后判定你在本次游戏中失败,你的500万贷款无法被清空,你将被圈禁在地下世界挖矿,强制打工 20 年来还清贷款。 \n"
msg_w_final += "从此你过上了猪狗不如的生活。"
if isover is True:
self.window_main.fill((0, 0, 0))
while not self.quit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.quit = True
font = pygame.font.SysFont("simsunnsimsun", 12)
msg_w = msg_w_final.split('\n')
pygame.draw.rect(self.window_main, (255, 255, 255), (0, 0, self.m_width, self.m_height))
h = 0
for m in msg_w:
msg = font.render(m, True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(msg, (50, 50 + h))
h += 50
self.clock.tick(60) # 帧频
pygame.display.update()
def run(self):
font = pygame.font.Font(None, 32)
cfont = pygame.font.SysFont("simsunnsimsun", 16)
pygame.draw.rect(self.window_main, (240, 248, 255), (600, 10, 60, 20))
loan_label = cfont.render("贷款/万 :", True, (255, 0, 0), (240, 248, 255))
self.window_main.blit(loan_label, (600, 25))
loan_input_box = pygame.Rect((680, 20, 100, 25))
loan_color_inactive = pygame.Color('lightskyblue3')
loan_color_active = pygame.Color('dodgerblue2')
color = loan_color_inactive
active = False
text = ''
loan_flag = False
while not self.quit:
if loan_flag is True:
font = pygame.font.Font(None, 32)
cfont = pygame.font.SysFont("simsunnsimsun", 16)
pygame.draw.rect(self.window_main, (240, 248, 255), (600, 10, 60, 20))
loan_label = cfont.render("贷款/万 :", True, (255, 0, 0), (240, 248, 255))
self.window_main.blit(loan_label, (600, 25))
loan_input_box = pygame.Rect((680, 20, 100, 25))
loan_color_inactive = pygame.Color('lightskyblue3')
loan_color_active = pygame.Color('dodgerblue2')
color = loan_color_inactive
active = False
text = ''
loan_flag = False
# 处理事件
for event in pygame.event.get():
if event.type == pygame.QUIT: # 退出
self.quit = True
if event.type == pygame.MOUSEBUTTONDOWN:
if loan_input_box.collidepoint(event.pos):
active = not active
else:
active = False
color = loan_color_active if active else loan_color_inactive
x, y = pygame.mouse.get_pos()
player_rect_row = 0
player_rect_col = 0
for p in self.players:
oflag = False
row = 30 + player_rect_row * 80
col = 100 + player_rect_col * 30
if row < x < row + 75 and col < y < col + 25 and p.alive is True: # face to one player 页面
print(p.name)
self.window_main.fill((0, 0, 0))
while not self.quit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.quit = True
if event.type == pygame.MOUSEBUTTONDOWN and p.prflag is True:
x, y = pygame.mouse.get_pos()
if 160 < x < 240 and 450 < y < 570:
break
elif 360 < x < 440 and 450 < y < 570:
break
elif 560 < x < 640 and 450 < y < 570:
break
if event.type == pygame.MOUSEBUTTONDOWN: # 我来打牌
x, y = pygame.mouse.get_pos()
if 160 < x < 240 and 450 < y < 570:
card = 0
elif 360 < x < 440 and 450 < y < 570:
card = 1
elif 560 < x < 640 and 450 < y < 570:
card = 2
# 购买卡牌
elif 730 < x < 790 and 10 < y < 30:
self.window_main.fill((0, 0, 0))
buyisover = False
card_price, tprice, buyflag = p.buycard()
numfont = pygame.font.Font(None, 64)
cfont = pygame.font.SysFont("simsunnsimsun", 12)
while not self.quit:
for event in pygame.event.get():
if event.type == pygame.QUIT: # 退出
self.quit = True
if event.type == pygame.MOUSEBUTTONDOWN:
x, y = pygame.mouse.get_pos()
if 730 < x < 790 and 10 < y < 30: # 返回
buyisover = True
break
elif buyflag == 0 and 360 < x < 440 and 240 < y < 360: # 全买
self.sellcards(self.me, p, card_price, tprice, buyflag, 99999)
buyisover = True
break
elif buyflag == 2: # 单买
if 160 < x < 240 and 240 < y < 360:
self.sellcards(self.me, p, card_price, tprice, buyflag, 0)
buyisover = True
break
elif 360 < x < 440 and 240 < y < 360:
self.sellcards(self.me, p, card_price, tprice, buyflag, 1)
buyisover = True
break
elif 560 < x < 640 and 240 < y < 360:
self.sellcards(self.me, p, card_price, tprice, buyflag, 2)
buyisover = True
break
if buyflag == 0:
pygame.draw.rect(self.window_main, (255, 255, 255), (360, 240, 80, 120)) # 价格
msg = "全部购买,每张: " + str(card_price) + "万人民币;总价格: " + str(tprice) + "万人民币"
me_paper_num = cfont.render(msg, True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_paper_num, (360, 240))
elif buyflag == 2:
msg = "单价: " + str(card_price) + "万人民币"
pygame.draw.rect(self.window_main, (255, 255, 255), (160, 240, 80, 120)) # 拳头牌价格
me_rock_num = cfont.render(msg, True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_rock_num, (160, 240))
pygame.draw.rect(self.window_main, (255, 255, 255), (360, 240, 80, 120)) # 布牌价格
me_paper_num = cfont.render(msg, True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_paper_num, (360, 240))
pygame.draw.rect(self.window_main, (255, 255, 255), (560, 240, 80, 120)) # 剪刀牌价格
me_scissors_num = cfont.render(msg, True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_scissors_num, (560, 240))
elif buyflag == 1:
pygame.draw.rect(self.window_main, (255, 255, 255), (360, 240, 80, 120))
msg = "不卖啦,亲"
me_paper_num = cfont.render(msg, True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_paper_num, (360, 240))
elif buyflag == 4:
pygame.draw.rect(self.window_main, (255, 255, 255), (360, 240, 80, 120))
msg = "你点你马那?还买不买?搁着卡BUG呢?不买滚!"
me_paper_num = cfont.render(msg, True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_paper_num, (360, 240))
pygame.draw.rect(self.window_main, (255, 255, 255), (730, 10, 60, 20))
enemy_card_num = cfont.render("离开", True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(enemy_card_num, (730, 10))
pygame.display.flip()
self.clock.tick(60) # 帧频
pygame.display.update()
if buyisover is True:
self.window_main.fill((0, 0, 0))
break
continue
# 招募同伴
elif 730 < x < 790 and 40 < y < 60 and p.prflag is False:
self.window_main.fill((0, 0, 0))
recisover = False
numfont = pygame.font.Font(None, 64)
cfont = pygame.font.SysFont("simsunnsimsun", 12)
partner = p.becomepartner()
while not self.quit:
for event in pygame.event.get():
if event.type == pygame.QUIT: # 退出
self.quit = True
if event.type == pygame.MOUSEBUTTONDOWN:
x, y = pygame.mouse.get_pos()
if 730 < x < 790 and 10 < y < 30: # 返回
recisover = True
break
if 100 < x < 500 and 200 < y < 350: # 招募
if partner == 0:
self.me.partner_0.append(p)
else:
self.me.partner_1.append(p)
p.prflag = True
self.sellcards(self.me, p, 0, 0, 9, card=999)
recisover = True
break
if partner == 0:
pygame.draw.rect(self.window_main, (255, 255, 255), (100, 200, 400, 150))
msg = "$: 收取所有手牌,游戏结束支付100万人民币"
me_paper_num = cfont.render(msg, True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_paper_num, (100, 200))
else:
pygame.draw.rect(self.window_main, (255, 255, 255), (100, 200, 400, 150))
msg = "$: 收取所有手牌,并协助其通关"
me_paper_num = cfont.render(msg, True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_paper_num, (100, 200))
pygame.draw.rect(self.window_main, (255, 255, 255), (730, 10, 60, 20))
enemy_card_num = cfont.render("离开", True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(enemy_card_num, (730, 10))
pygame.display.flip()
self.clock.tick(60) # 帧频
pygame.display.update()
if recisover is True:
self.window_main.fill((0, 0, 0))
break
continue
# 消除卡牌
elif 730 < x < 790 and 40 < y < 60 and p.prflag is True:
self.window_main.fill((0, 0, 0))
remisover = False
numfont = pygame.font.Font(None, 64)
cfont = pygame.font.SysFont("simsunnsimsun", 12)
while not self.quit:
for event in pygame.event.get():
if event.type == pygame.QUIT: # 退出
self.quit = True
if event.type == pygame.MOUSEBUTTONDOWN:
x, y = pygame.mouse.get_pos()
if 730 < x < 790 and 10 < y < 30: # 返回
remisover = True
break
if 60 < x < 160 and 60 < y < 210:
self.me.rmcwithpartner(0)
elif 310 < x < 410 and 60 < y < 210:
self.me.rmcwithpartner(1)
elif 560 < x < 660 and 60 < y < 210:
self.me.rmcwithpartner(2)
elif 60 < x < 160 and 410 < y < 560:
self.me.rmcwithpartner(3)
elif 310 < x < 410 and 410 < y < 560:
self.me.rmcwithpartner(4)
elif 560 < x < 660 and 410 < y < 560:
self.me.rmcwithpartner(5)
pygame.draw.rect(self.window_main, (211, 211, 211), (50, 50, 100, 150)) # r - r
pygame.draw.rect(self.window_main, (255, 255, 255), (60, 60, 100, 150))
rr = cfont.render("石头-石头", True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(rr, (60, 60))
pygame.draw.rect(self.window_main, (211, 211, 211), (300, 50, 100, 150)) # p - p
pygame.draw.rect(self.window_main, (255, 255, 255), (310, 60, 100, 150))
pp = cfont.render("布-布", True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(pp, (310, 60))
pygame.draw.rect(self.window_main, (211, 211, 211), (550, 50, 100, 150)) # s - s
pygame.draw.rect(self.window_main, (255, 255, 255), (560, 60, 100, 150))
ss = cfont.render("剪刀-剪刀", True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(ss, (560, 60))
pygame.draw.rect(self.window_main, (211, 211, 211), (50, 400, 100, 150)) # r - p
pygame.draw.rect(self.window_main, (255, 255, 255), (60, 410, 100, 150))
rp = cfont.render("石头-布", True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(rp, (60, 410))
pygame.draw.rect(self.window_main, (211, 211, 211), (300, 400, 100, 150)) # p - s
pygame.draw.rect(self.window_main, (255, 255, 255), (310, 410, 100, 150))
ps = cfont.render("布-剪刀", True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(ps, (310, 410))
pygame.draw.rect(self.window_main, (211, 211, 211), (550, 400, 100, 150)) # s - r
pygame.draw.rect(self.window_main, (255, 255, 255), (560, 410, 100, 150))
sr = cfont.render("剪刀-石头", True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(sr, (560, 410))
pygame.draw.rect(self.window_main, (255, 255, 255), (100, 280, 120, 40)) # 我的rps数量
me_rock_num = numfont.render(str(self.me.rock), True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_rock_num, (100, 280))
pygame.draw.rect(self.window_main, (255, 255, 255), (300, 280, 120, 40))
me_paper_num = numfont.render(str(self.me.paper), True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_paper_num, (300, 280))
pygame.draw.rect(self.window_main, (255, 255, 255), (500, 280, 120, 40))
me_scissors_num = numfont.render(str(self.me.scissors), True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_scissors_num, (500, 280))
pygame.draw.rect(self.window_main, (255, 255, 255), (730, 10, 60, 20))
enemy_card_num = cfont.render("离开", True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(enemy_card_num, (730, 10))
pygame.display.flip()
self.clock.tick(60) # 帧频
pygame.display.update()
if remisover is True:
self.window_main.fill((0, 0, 0))
break
continue
elif 730 < x < 790 and 70 < y < 90: # 返回
oflag = True
break
else:
break
self.me.meplaycard(card)
rel = self.check(self.me, p, card)
if rel == 'p':
print("平手")
elif rel == 'y':
print("你赢了")
elif rel == 'n':
print("你输了")
# 触发结局
self.triggeroutcome()
if p.id not in self.players_list:
oflag = True
break
numfont = pygame.font.Font(None, 64)
font = pygame.font.Font(None, 16)
cfont = pygame.font.SysFont("simsunnsimsun", 12)
pygame.draw.rect(self.window_main, (255, 255, 255), (730, 10, 60, 20))
enemy_card_num = cfont.render("购买卡牌", True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(enemy_card_num, (730, 10))
if p.prflag is False:
pygame.draw.rect(self.window_main, (255, 255, 255), (730, 40, 60, 20))
enemy_card_num = cfont.render("招募同伴", True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(enemy_card_num, (730, 40))
else:
pygame.draw.rect(self.window_main, (255, 255, 255), (730, 40, 60, 20))
enemy_card_num = cfont.render("消除卡牌", True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(enemy_card_num, (730, 40))
pygame.draw.rect(self.window_main, (255, 255, 255), (730, 70, 60, 20))
enemy_card_num = cfont.render("离开", True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(enemy_card_num, (730, 70))
pygame.draw.rect(self.window_main, (255, 255, 255), (10, 10, 60, 20)) # 敌方星星数量
enemy_card_num = font.render(str(p.stars), True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(enemy_card_num, (10, 10))
pygame.draw.rect(self.window_main, (255, 255, 255), (730, 570, 60, 20)) # 我方星星数量
enemy_card_num = font.render(str(self.me.stars), True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(enemy_card_num, (730, 570))
pygame.draw.rect(self.window_main, (255, 255, 255), (360, 20, 80, 120)) # 敌方纸牌数量
enemy_card_num = numfont.render(str(p.rock + p.paper + p.scissors), True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(enemy_card_num, (360, 20))
pygame.draw.rect(self.window_main, (255, 255, 255), (160, 450, 80, 120)) # 我方拳头牌剩余数量
me_rock_num = numfont.render(str(self.me.rock), True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_rock_num, (160, 450))
pygame.draw.rect(self.window_main, (255, 255, 255), (360, 450, 80, 120)) # 我方布牌剩余数量
me_paper_num = numfont.render(str(self.me.paper), True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_paper_num, (360, 450))
pygame.draw.rect(self.window_main, (255, 255, 255), (560, 450, 80, 120)) # 我方剪刀牌剩余数量
me_scissors_num = numfont.render(str(self.me.scissors), True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(me_scissors_num, (560, 450))
self.clock.tick(60) # 帧频
pygame.display.update()
self.me.addinterest()
if oflag is True:
self.window_main.fill((0, 0, 0))
pygame.draw.rect(self.window_main, (240, 248, 255), (0, 0, self.m_width, self.m_height)) # 背景
loan_flag = True
break
break
player_rect_row += 1
if player_rect_row == 9:
player_rect_row = 0
player_rect_col += 1
if event.type == pygame.KEYDOWN:
if active:
if event.key == pygame.K_RETURN: # 贷款
print(text)
arrears = float(text)
self.me.startloan(arrears)
text = ''
elif event.key == pygame.K_BACKSPACE:
text = text[:-1]
else:
text += event.unicode
txt_surface = font.render(text, True, color)
loan_input_x = loan_input_box.x + 5
self.window_main.blit(txt_surface, (loan_input_x, loan_input_box.y + 5))
pygame.draw.rect(self.window_main, color, loan_input_box, 2)
# 渲染
pygame.draw.rect(self.window_main, (255, 255, 255), (20, 20, 75, 25)) # 倒计时
numfont = pygame.font.Font(None, 16)
t_rock = numfont.render(str(self.t_rock), True, (255, 0, 0), (255, 255, 0)) # 拳头牌总数量
t_rock_label = numfont.render("T ROCK", True, (255, 0, 0), (255, 255, 0)) # 拳头
pygame.draw.rect(self.window_main, (255, 255, 255), (100, 20, 75, 25))
self.window_main.blit(t_rock_label, (125, 27))
self.window_main.blit(t_rock, (100, 20))
t_paper = numfont.render(str(self.t_paper), True, (255, 0, 0), (255, 255, 0)) # 布牌总数量
t_paper_label = numfont.render("T PAPER", True, (255, 0, 0), (255, 255, 0)) # 布牌
pygame.draw.rect(self.window_main, (255, 255, 255), (200, 20, 75, 25))
self.window_main.blit(t_paper_label, (225, 27))
self.window_main.blit(t_paper, (200, 20))
t_scissors = numfont.render(str(self.t_scissors), True, (255, 0, 0), (255, 255, 0)) # 剪刀牌总数量
t_scissors_label = numfont.render("T SCI", True, (255, 0, 0), (255, 255, 0)) # 剪刀
pygame.draw.rect(self.window_main, (255, 255, 255), (300, 20, 75, 25))
self.window_main.blit(t_scissors_label, (325, 27))
self.window_main.blit(t_scissors, (300, 20))
pygame.draw.rect(self.window_main, (255, 255, 255), (20, 60, 75, 25))
me_rock = numfont.render(str(self.me.rock), True, (255, 0, 0), (255, 255, 0)) # 我的拳头牌总数量
me_rock_label = numfont.render("M ROCK", True, (255, 0, 0), (255, 255, 0)) #
pygame.draw.rect(self.window_main, (255, 255, 255), (100, 60, 75, 25))
self.window_main.blit(me_rock_label, (125, 67))
self.window_main.blit(me_rock, (100, 60))
me_paper = numfont.render(str(self.me.paper), True, (255, 0, 0), (255, 255, 0)) # 我的布牌总数量
me_paper_label = numfont.render("M PAPER", True, (255, 0, 0), (255, 255, 0)) #
pygame.draw.rect(self.window_main, (255, 255, 255), (200, 60, 75, 25))
self.window_main.blit(me_paper_label, (225, 67))
self.window_main.blit(me_paper, (200, 60))
me_scissors = numfont.render(str(self.me.scissors), True, (255, 0, 0), (255, 255, 0)) # 我的剪刀牌总数量
me_scissors_label = numfont.render("M SCI", True, (255, 0, 0), (255, 255, 0)) #
pygame.draw.rect(self.window_main, (255, 255, 255), (300, 60, 75, 25))
self.window_main.blit(me_scissors_label, (325, 67))
self.window_main.blit(me_scissors, (300, 60))
me_arrears = numfont.render(str(self.me.arrears_final), True, (255, 0, 0), (255, 255, 0)) # 我的贷款
pygame.draw.rect(self.window_main, (255, 255, 255), (400, 60, 75, 25))
self.window_main.blit(me_arrears, (400, 60))
me_money = numfont.render(str(self.me.money), True, (255, 0, 0), (255, 255, 0)) # 我的钱
pygame.draw.rect(self.window_main, (255, 255, 255), (500, 60, 75, 25))
self.window_main.blit(me_money, (500, 60))
pygame.display.flip()
namefont = pygame.font.SysFont("simsunnsimsun", 12)
player_rect_row = 0
player_rect_col = 0
for i in self.players: # 玩家列表
row = 30 + player_rect_row * 80
col = 100 + player_rect_col * 30
if i.alive is True:
pygame.draw.rect(self.window_main, (255, 255, 255), (row, col, 75, 25))
else:
pygame.draw.rect(self.window_main, (220, 220, 220), (row, col, 75, 25))
name = namefont.render(str(i.name), True, (255, 0, 0), (255, 255, 0))
self.window_main.blit(name, (row, col))
player_rect_row += 1
if player_rect_row == 9:
player_rect_row = 0
player_rect_col += 1
self.clock.tick(60) # 帧频
pygame.display.update()
self.gamestart()
if len(self.players_list) <= 1:
break
overtime = time.time() - self.t_time
if overtime >= 600:
print("Time Out")
break
for w in self.winner:
print(w.name + " --- " + str(w.stars))
print("胜利人数:", len(self.winner))
etime = time.time()
print(etime - self.t_time)
print(self.me.arrears)
if __name__ == "__main__":
rsp = RSPGame(100)
rsp.run()