import random
import pygame
from pygame.locals import *
import sys
class Peg:
def __init__(self, color):
self.color = Row.colors[color]
self.num = color
def clicked(self):
self.num += 1
if(self.num>5):
self.num = 0
self.color = Row.colors[self.num]
class Row:
colors = ['red', 'white', 'blue', 'yellow', 'green', 'orange', 'none']
def __init__(self, solution):
if(not solution):
self.pegs = [Peg(6) for x in range(4)]
else:
self.pegs = [Peg(random.randint(0, 5)) for x in range(4)]
class Board:
def __init__(self):
self.rows = [Row(False) for x in range(12)]
self.solution = Row(True)
pygame.init()
b = Board()
def draw_board(b):
c=0
for x in range(50, 600, 50):
screen.blit(row, (50, x))
for y in range(0, 4):
screen.blit(pegs[b.rows[(int)(x/50)].pegs[y].num], ((84+(52*y), x+1)))
c+=1
screen = pygame.display.set_mode((400, 700))
pygame.display.set_caption('Mastermind')
pegs = [pygame.image.load('images/peg_{}.png'.format(Row.colors[x])) for x in range(7)]
row = pygame.image.load('images/row.png')
draw_board(b)
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
if event.type == MOUSEBUTTONDOWN:
if(event.button==1):
b.rows[0].pegs[0].clicked()
draw_board(b)
pygame.display.update()
can some one tell me what I'm doing wrong. after everything ids first drawn it wont update when i use the clicked function in the pegs class, i used the console and print statement to see if it was actually changing and it was. the problem is that it wont show the updated color. i know its not pygame its my code.