-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel.py
64 lines (50 loc) · 1.46 KB
/
level.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /usr/bin/env python2.7-32
#encoding: utf-8
import os
import pygame
import pickle
import random
from sprites import Block
class Level (object):
def __init__ (self, file, map, game):
self.grid = self.map (map[0], map[1])
self._file = file
self.game = game
def map (self, x, y):
grid = []
for row in range (x):
grid.append ([])
for column in range(y):
grid[row].append(0)
return grid
def load_level (self):
linha, coluna = (0, 0)
try:
file = open (os.path.join("data/levels", self._file))
except IOError:
self.build_word ()
file = open (os.path.join("data/levels", self._file))
grid = pickle.load (file)
file.close ()
for i, line in enumerate(grid):
for j, row in enumerate(line):
bl = Block([i, j], row, True, self.game)
bl.groups = self.game.blockgroup
def build_word (self, w=100, h=100):
grid = []
for row in range (w):
grid.append ([])
for column in range (h):
grid [row].append (random.randint(0, 3))
file = open(os.path.join ("data/levels", self._file), 'w')
pickle.dump (grid, file)
file.close ()
def update (self, playtime):
pass
def draw (self):
pass
#
#Criar level usando o pickle tbm, ainda nao sei como vou fazer isso
#
#
#