Esempio n. 1
0
 def __init__(self, player_id, gs, myBoard, otherBoard):
     self.id = player_id
     self.board = myBoard
     self.other_board = otherBoard
     self.score = 0
     self.gs = gs
     self.keep_shape=None
     self.next_shape=None
     self.randomizer=MyRandomizer(7)
     self.gen_next_shape()
     self.shape = self.get_next_shape()
Esempio n. 2
0
class Player():
    def __init__(self, player_id, gs, myBoard, otherBoard):
        self.id = player_id
        self.board = myBoard
        self.other_board = otherBoard
        self.score = 0
        self.gs = gs
        self.keep_shape=None
        self.next_shape=None
        self.randomizer=MyRandomizer(7)
        self.gen_next_shape()
        self.shape = self.get_next_shape()

        
    def handle_move(self, direction):
        #if you can't move then you've hit something
        if self.shape:
            if direction==UP:
                self.shape.rotate(clockwise=False)
            else:
                if not self.shape.move( direction ):
                    # if you're heading down then the shape has 'landed'
                    if direction == DOWN:
                        points = self.board.check_for_complete_row(
                            self.shape.blocks)
                        #del self.shape
                        self.shape = self.get_next_shape()
                        
                        self.score += points
                        if self.gs.num_players == 2:
                            if points > 1:
                                self.other_board.receive_lines(points-1) 
           
                        # If the shape returned is None, then this indicates that
                        # that the check before creating it failed and the
                        # game is over!
                        if self.shape is None:
                            self.gs.state = "ending" #you lost!
                            if self.gs.num_players == 2:
                                self.gs.winner = (self.id + 1) % 2
                            else:
                                self.gs.winner = self.id
                                
                        # do we go up a level?
                        #if (self.gs.level < len(LEVEL_SPEEDS)-1 and 
                        #    self.score / LINES_TO_ADVANCE >= self.gs.level+1 ):
                        #    self.gs.level+=1
                        #    print "level",self.gs.level
                        #    self.gs.delay = LEVEL_SPEEDS[self.gs.level]
                        
                        # Signal that the shape has 'landed'
                        return False
        return True
        
    def get_next_shape( self ):
        #Randomly select which tetrominoe will be used next.
        self.the_shape = self.next_shape
        self.gen_next_shape()
        return self.the_shape.check_and_create(self.board)
    def gen_next_shape( self ):
        #self.next_shape=self.gs.shapes[ random.randint(0,len(self.gs.shapes)-1) ]
        #self.next_shape = self.gs.shapes[ random.randint(0,len(self.gs.shapes)-1) ]
        self.next_shape = self.gs.shapes[ self.randomizer.rand() ]
        self.next_shape = self.next_shape.check_and_create(self.board)