[Tutor] problems finding position in list and changing it for GO game
Lee Meredith
tesujicamera at gmail.com
Tue Dec 16 05:01:12 CET 2008
Hi
I am looking for some help if you have or worked with pygame or not
I'm sure if you have not you could still help me
I am working on a *GO game* no AI a analog behavior only
I have the stones going to the board and switching colors between black and
white
but I want to take *stones/pieces* off and count them
and if you don't play go it's okay as well but might help
the MOUSEBUTTONDOWN gives the black0 XandYpositions with the*.append*
how do I reference the address in the list by using XandYpositions
Then replace them or take it out off the list
This code puts out an error when you hit the letter "b"
Traceback (most recent call last):
File "C:/Users/Lee/Desktop/pyGame01/GO/GO_1_2_3.py", line 46, in <module>
for stone in len(black0):
TypeError: 'int' object is not iterable
Which I'm not really sure what that means or how to remedy it as well
Thank you everyone
## geting there black and white stones alternate now the issue
## of taking the stones off the board
## Or more precisely to .insert into the list at an address that I detected
by finding the X. and the Y. by using the
## if event.pos == range( black0[stone][0] - (stoneWidth/2),
black0[stone][0] + ((stoneWidth/2)+1)):
import pygame
from pygame.locals import *
from sys import exit
pygame.init()
screen = pygame.display.set_mode((758, 758), 0, 32)
##Color
color0 = (0,255)
b = 0
white0 = [] #white0
black0 = [] #black0
stoneWidth = 20
while True:
pressed_keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == QUIT:
exit()
if event.type == MOUSEBUTTONDOWN:##makes a variable out of the X.
and Y. coordinates
if b==0:
b=1
black0.append(event.pos)##black0.append [X. and Y.]
black1.append(event.pos)
print "black points1"
print black0
print
else:
b=0
white0.append(event.pos)
white1.append(event.pos)
print "white points"
print white0
print
if event.type == KEYDOWN:
if event.key == K_b:
print "cut black"
for stone in len(black0):##I'm not sure here either is
this the way I would look for detection of mouse in the range
Circle if event.pos == range( black0[stone][0] -
(stoneWidth/2), black0[stone][0] + ((stoneWidth/2)+1)):
## this is where I get confused what should I do
<<<<<<<
## black0.insert(event.pos,0)
if event.pos == range( black0[stone][1] -
(stoneWidth/2), black0[stone][1] + ((stoneWidth/2)+1)):
## this is where I get confused what should I do
<<<<<<<
##black0.insert(event.pos,1)
screen.fill((229,181,83))
screen.lock()
for white in white0: #you're drawing
pygame.draw.circle(screen, (color0[1],color0[1],color0[1]), white,
20)
for black in black0:
pygame.draw.circle(screen, (color0[0],color0[0],color0[0]), black,
20)
screen.unlock()
pygame.display.update()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081215/d4cec1ad/attachment.htm>
More information about the Tutor
mailing list