2017-05-18 3 views
0

私は、グラフィックスと呼ばれるモジュールを使用して、Pythonゲームを作成します。 私は氷でボードを作成しましたが、初めにプレイヤーのポジションを作成する方法を混乱させています。グラフィックスモジュールへ のリンクは: http://mcsp.wartburg.edu/zelle/python/graphics.py は、ここに私のコードです:砕氷機ゲーム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]])   

position in the beginning MS1()

のは、 'X' の赤い円と 'O' であるとしましょう青い円です。

+3

あなたが実際に何を明確にすることができ質問は? –

+0

最初のプレイヤー位置の関数を作成する方法を知りたい –

+1

ようこそStackOverflow。ヘルプドキュメントの投稿ガイドラインを読み、それに従ってください。 [on topic](http://stackoverflow.com/help/on-topic)および[How to Ask](http://stackoverflow.com/help/how-to-ask)をここで適用してください。 StackOverflowは、デザイン、コーディング、リサーチまたはチュートリアルサービスではありません。 – Prune

答えて

1

私は砕氷船ゲームについて何も知らないが、私は以下のあなたを提供し、追加のロジックはあなたが前方に移動するために十分与えます願っています:

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() 

enter image description here

関連する問題