python小游戏 雷方块小解密

点击一个它和他相邻的方块会加1

数组里数字全相同成功

import random

def result(list_1,n):

max_num = 3

list_2 = [n-2,n-1 , n]

list_3 = [True ,True ,True]#是否+1表

length = len(list_1)

for i in list_2:

if i < 0 or i >= length:

list_3[list_2.index(i)] = False

continue

#print(list_3)

for i in range(0,3):

if list_3[i]:

list_1[list_2[i]] += 1

if list_1[list_2[i]] > max_num:

list_1[list_2[i]] = 1

#print(list_1)

return list_1

def demo(list_1,list_2):

yep = True

a = list_1[0]

for i in list_1:

if i == a:

a == i

else:

yep = False

break

if yep and len(list_2) < 7:

return list_2

else:

x = random.randint(1,len(list_1))

list_2.append(x)

list_1 = result(list_1,x)

return demo(list_1,list_2)

def game(lis):

num=int(input("请输入数值:"))

lis= result(lis,num)

return lis

#print(game([1,2,3,2]))

lis = [1,2,1,3]

while(True):

try:

lis_1 = lis.copy()

answer = demo(lis_1,[])

print(answer)

break

except:

pass

yep = True

print(lis)

while(yep):

lis = game(lis)

print(lis)

a = lis[0]

for i in lis:

if i == a:

a == i

yep = False

else:

yep = True

break

if not yep :

print("You are winner!")

上一篇:实验四


下一篇:从Linux源码看Socket(TCP)的accept