Пример #1
0
def spawnResources(grid, centerPoint, resourceL, numRes, cellRange):
    #creates new resources in empty cells nearby
    spawnedResources = []
    occupiedList = [centerPoint]  #list of currently filled positions
    for resource in resourceL:
        occupiedList.append(resource.position)
        #is there a reason that I don't just put in the resource.position?
    for x in range(0, numRes):
        resPoint = centerPoint
        loopAgain = True

        #will loop until 2 valid and empty position are found
        while loopAgain or (not isValidPosition(grid, resPoint)):

            cellList = getSurrounding(centerPoint, cellRange, grid)

            #check how many empty surrounding cells
            numEmpty = 0
            for cell in cellList:
                if cell == 0:
                    numEmpty += 1

            #if there are less than 2 empty surrounding cells, stop
            if numEmpty < 2:
                print("No space for Resources")
                return []

            #Reset loopAgain and isOccupied.
            #This way if not occupied but not valid, will reset
            loopAgain = True
            isOccupied = False
            resPoint = entities.Point(
                occupiedList[0].x +
                random.randrange(-cellRange, cellRange + 1),
                occupiedList[0].y +
                random.randrange(-cellRange, cellRange + 1))
            for pos in occupiedList:
                if (resPoint.x == pos.x) and (resPoint.y == pos.y):
                    isOccupied = True
            if not isOccupied:
                loopAgain = False

        occupiedList.append(resPoint)
        spawnedResources.append(entities.MonsterEnergy(resPoint))
    return spawnedResources
Пример #2
0
def handleLeftClicks(actionList, grid, keys, p, bgGrid):
	if keys[K_LSHIFT]: 
		#new function below, pass grid, p, actionlist) 
		e = findEntity(grid.entityList, p)
		if not e: 
			return 

		if isinstance(grid.entityList[e], entities.MonsterEnergy): 
			grid.entityList.pop(e)
			t = entities.transformingMonster(p)
			grid.entityList.append(t)
			actionList.insert(t, 0)

	elif grid.placeMode == model.GATHERER: 
		removePrevInCell(grid, p)
		newGath = entities.CSCStudent(5, p)
		grid.entityList.append(newGath)
	elif grid.placeMode == model.GENERATOR: 
		removePrevInCell(grid, p)
		newGen = entities.CampusMarket(4, p)
		grid.entityList.append(newGen)
	elif grid.placeMode == model.RESOURCE: 
		removePrevInCell(grid, p)
		newRes = entities.MonsterEnergy(p)
		grid.entityList.append(newRes)
	elif grid.placeMode == model.OBSTACLE: 
		removePrevInCell(grid, p)
		newObs = entities.Obstacle(p)
		grid.entityList.append(newObs)
	#The following two only affect the bgGrid
	elif grid.placeMode == model.EMPTY: 
		model.set_cell(bgGrid, p, model.EMPTY)
	elif grid.placeMode == model.CONCRETE: 
		model.set_cell(bgGrid, p, model.CONCRETE)

	else: 
		newRes = resourceClick(grid, p, grid.entityList)
		grid.entityList += newRes

	print (grid.entityList)
Пример #3
0
def handleLeftClicks(grid, keys, p, bgGrid):
    if grid.placeMode == model.GATHERER:
        newGath = entities.CSCStudent(5, p)
        grid.entityList.append(newGath)
    elif grid.placeMode == model.GENERATOR:
        newGen = entities.CampusMarket(4, p)
        grid.entityList.append(newGen)
    elif grid.placeMode == model.RESOURCE:
        newRes = entities.MonsterEnergy(p)
        grid.entityList.append(newRes)
    elif grid.placeMode == model.OBSTACLE:
        newObs = entities.Obstacle(p)
        grid.entityList.append(newObs)
    #The following two only affect the bgGrid
    elif grid.placeMode == model.EMPTY:
        model.set_cell(bgGrid, p, model.EMPTY)
    elif grid.placeMode == model.CONCRETE:
        model.set_cell(bgGrid, p, model.CONCRETE)

    else:
        newRes = resourceClick(grid, p, grid.entityList)
        grid.entityList += newRes
Пример #4
0
def load(grid, bgGrid):
    model.emptyGrid(grid)
    model.emptyGrid(bgGrid)
    newList = []

    with open('gaia.sav', 'r') as f:
        for line in f:
            l = line.split()
            if l[0] == 'gatherer':
                p = entities.Point(int(l[1]), int(l[2]))
                resLim = 5
                newEnt = entities.CSCStudent(resLim, p)
                newEnt.rate = int(l[2]) * 100
                #print('YOU FOUND A GATHERER')

            elif l[0] == 'generator':
                p = entities.Point(int(l[1]), int(l[2]))
                rate = 2
                newEnt = entities.CampusMarket(rate, p)
                #print('YOU FOUND A GENERATOR')

            elif l[0] == 'resource':
                p = entities.Point(int(l[1]), int(l[2]))
                newEnt = entities.MonsterEnergy(p)
                #print('YOU FOUND A RESOURCE')

            elif l[0] == 'obstacle':
                p = entities.Point(int(l[1]), int(l[2]))
                newEnt = entities.Obstacle(p)

            elif l[0] == 'concrete':
                p = entities.Point(int(l[1]), int(l[2]))
                value = 6
                model.set_cell(bgGrid, p, value)

            newList.append(newEnt)
        f.close()
        grid.entityList = newList
        print("You loaded the file!")
Пример #5
0
import os
import entities
import pickle

p1 = entities.Point(2, 2)
p2 = entities.Point(3, 5)
p3 = entities.Point(2, 9)
p4 = entities.Point(0, 1)
gatherer = entities.CSCStudent('Nathan', 3, p1)
generator = entities.CampusMarket('market', 6, p2)
res1 = entities.MonsterEnergy('res', p3)
res2 = entities.MonsterEnergy('res2', p4)

entList = [gatherer, generator, res1, res2]

with open('gaia.sav', 'wb') as output:
    pickle.dump(entList, output, pickle.HIGHEST_PROTOCOL)

f = open('gaia.sav', 'r')
newList = pickle.load(f)
'''
for ent in entList: 
	if isinstance(ent, entities.CSCStudent): 

		f.write('gatherer' + ' ' + ent.name + ' ' + str(ent.resource_limit) + ' ' + str(ent.position.x) + ' ' + str(ent.position.y))
	elif isinstance(ent, entities.CampusMarket): 
		f.write(ent.name + ' ' + ent.rate + ' ' + ent.position.x + ' ' + ent.position.y)
	elif isinstance(ent, entities.MonsterEnergy): 
		f.write(ent.name + ' ' + ent.position.x + ' ' + ent.position.y)