Apr-25-2018, 03:36 PM
Hi Everyone,
I'm new to Python and I'm trying to write a small game using Pygame called Necromancers Vs Werewolves. Its not a game in the normal sense, I want to see if using the rules I laid down if it will demonstrate any unique patterns. Anyway, N represents a necromancer, and W a werewolf. My Ns are supposed to teleport across the screen but what it is doing is teleporting once or twice and then all the Ns vanish. Please look at my source code below and help me out.
I'm new to Python and I'm trying to write a small game using Pygame called Necromancers Vs Werewolves. Its not a game in the normal sense, I want to see if using the rules I laid down if it will demonstrate any unique patterns. Anyway, N represents a necromancer, and W a werewolf. My Ns are supposed to teleport across the screen but what it is doing is teleporting once or twice and then all the Ns vanish. Please look at my source code below and help me out.

import pygame import time import random pygame.init() screen = pygame.display.set_mode((1024, 768)) done = False is_blue = True x = 30 y = 30 pause = True random.seed() clock = pygame.time.Clock() #lists necromancers = [0 for x in range(100)] werewolves = [0 for x in range(100)] corpses = [0 for x in range(100)] fireballs = [0 for x in range(100)] necromancers = [0 for x in range(100)] w, h = 100, 100; necro_pos = [[0 for x in range(w)] for y in range(h)] werewolve_pos = [[0 for x in range(w)] for y in range(h)] fireball_pos = [[0 for x in range(w)] for y in range(h)] bones_pos = [[0 for x in range(w)] for y in range(h)] stench_pos = [[0 for x in range(w)] for y in range(h)] #initialize positions #initalize necromancers for index in range(10): #Winitialize 10 necromancers necromancers[index] = index x = random.randint(1,99) y = random.randint(1,99) necro_pos[x][y] = index #initialize werewolves for index2 in range(10): #Winitialize 10 werewolves werewolves[index2] = index2 x = random.randint(1,99) y = random.randint(1,99) werewolve_pos[x][y] = index2 while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True pressed = pygame.key.get_pressed() if pressed[pygame.K_q]: done = True time.sleep(1) screen.fill((0,0,0)) myfont = pygame.font.Font(pygame.font.get_default_font(), 24) #draw werewolves for idx in range(99): for idy in range(99): if werewolve_pos[idx][idy] is not 0: surface = pygame.font.Font.render(myfont, "W", False, (255, 255, 0), (0, 0, 0)) screen.blit(surface, (10*idx, 10*idy)) #draw necromancers for idx in range(99): for idy in range(99): if necro_pos[idx][idy] is not 0: surface = pygame.font.Font.render(myfont, "N", False, (255, 0, 0), (0, 0, 0)) screen.blit(surface, (10 * idx, 10 * idy)) # randomly change the position of the necromancers for ind in range(10): for idx in range(99): for idy in range(99): if necro_pos[idx][idy] is not 0: movement_random_x = random.randint(1, 99) movement_random_y = random.randint(1, 99) print("Movement Random X: " + str(movement_random_y) + " Movement Random Y:" + str(movement_random_y)) print("IND is : " + str(ind)) necro_pos[idx][idy] = 0 necro_pos[movement_random_x][movement_random_y] = ind screen.blit(surface, (99,99)) pygame.display.flip() clock.tick(60)