Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 破冰游戏巨蟒_Python_Zelle Graphics - Fatal编程技术网

Python 破冰游戏巨蟒

Python 破冰游戏巨蟒,python,zelle-graphics,Python,Zelle Graphics,我将使用名为graphics的模块创建一个python游戏。 我已经用冰制作了一个棋盘,我不知道如何在开始时为球员创造位置。 链接到图形模块: 这是我的密码: from graphics import * from random import * column, row = 7, 10 WIN_W, WIN_H = 450, 315 WIN_SZ, GAP = 40, 5 COLORS = [ 'blue', 'white'] player = 'X' win = None ice

我将使用名为graphics的模块创建一个python游戏。 我已经用冰制作了一个棋盘,我不知道如何在开始时为球员创造位置。 链接到图形模块: 这是我的密码:

from graphics import *
from random import *

column, row = 7, 10

WIN_W, WIN_H = 450, 315

WIN_SZ, GAP = 40, 5

COLORS = [ 'blue', 'white']

player = 'X'

win = None

ices = []

def draw_ice(x, y):
    global ices

    left = GAP + x* (WIN_SZ+GAP)
    top =  GAP + y* (WIN_SZ+GAP)
    r = Rectangle(Point(left, top), Point(left+WIN_SZ, top+WIN_SZ))
    ices[x][y].append(r)
    bit = randint(1,1)
    ices[x][y].append(bool(bit))
    ices[x][y][0].setFill(COLORS[bit])
    ices[x][y][0].draw(win)

def draw_ices():
    for i in range(row):
        ices.append([])
        for j in range(column):
            ices[i].append([])
        draw_ice(i, j)

def MS1():
    global win
    win = GraphWin("Icebreaker", WIN_W, WIN_H)
    draw_ices()
    while True:
        pt = win.getMouse()

        x = int((pt.x - GAP)/(WIN_SZ + GAP))
        y = int((pt.y - GAP)/(WIN_SZ + GAP))
        print(str((pt.x, pt.y)) + ' --> ' + str((x, y)))

        ices[x][y][1] = not ices[x][y][0]
        ices[x][y][0].setFill(COLORS[ices[x][y][1]])        
MS1()


假设“X”是红色的圆圈,“O”是蓝色的圆圈。

我对破冰游戏一无所知,但我希望我在下面为您提供的附加逻辑能够让您继续前进:

from graphics import *

COLUMN, ROW = 7, 10

WIN_W, WIN_H = 455, 320

WIN_SZ, GAP = 40, 5

COLORS = ['blue', 'white']

CIRCLE, RECTANGLE, COLOR = range(3)

player = 'X'

ices = []

def draw_ice(x, y):
    left = GAP + x * (WIN_SZ + GAP)
    top = GAP + y * (WIN_SZ + GAP)
    r = Rectangle(Point(left, top), Point(left + WIN_SZ, top + WIN_SZ))
    c = Circle(r.getCenter(), WIN_SZ / 4)
    bit = 1
    c.setFill(COLORS[bit])
    c.setOutline('white')
    r.draw(win)
    c.draw(win)
    ices[x][y] = [c, r, bool(bit)]

def draw_ices():
    for i in range(ROW):
        ices.append([])
        for j in range(COLUMN):
            ices[i].append(None)
            draw_ice(i, j)

def MS1():
    draw_ices()

    x_player = ices[0][3][CIRCLE]  # X / Red Player
    x_player.setFill('red')

    o_player = ices[9][3][CIRCLE]  # O / Red Player
    o_player.setFill('blue')

    while True:
        pt = win.getMouse()

        x = int((pt.x - GAP) / (WIN_SZ + GAP))
        y = int((pt.y - GAP) / (WIN_SZ + GAP))
        print((pt.x, pt.y), '-->', (x, y))

        ices[x][y][COLOR] = not ices[x][y][COLOR]
        ices[x][y][CIRCLE].setFill(COLORS[ices[x][y][COLOR]])

win = GraphWin("Icebreaker", WIN_W, WIN_H)

MS1()

您能澄清实际问题是什么吗?我想知道如何创建一个函数,欢迎使用StackOverflow。请阅读并遵循帮助文档中的发布指南。在这里申请。StackOverflow不是设计、编码、研究或教程服务。