示例#1
0
 def render(self,
            outfile=sys.stdout,
            width: Optional[int] = None,
            height: Optional[int] = None,
            in_place: bool = False) -> None:
     height: int = height or self.HEIGHT
     width: int = width or self.WIDTH
     if not in_place:
         for _ in range(height):
             outfile.write("\n")
         util.print_up(height, outfile=outfile)
     for i in range(self.HEIGHT - height, self.HEIGHT):
         for j in range(width):
             empty = True
             for k in range(self.num_colors):
                 puyo = self.data[i + self.HEIGHT * k] & (1 << j)
                 if puyo:
                     util.print_puyo(k, outfile=outfile)
                     empty = False
             if self.has_garbage:
                 garbage_puyo = self.data[i + self.HEIGHT *
                                          self.num_colors] & (1 << j)
                 if garbage_puyo:
                     util.print_color(6, outfile=outfile)
                     outfile.write("\u25ce ")
                     empty = False
             if empty:
                 outfile.write("\u00b7 ")
             util.print_reset(outfile=outfile)
         util.print_down(1, outfile=outfile)
         util.print_back(2 * width, outfile=outfile)
示例#2
0
文件: versus.py 项目: brnor/dipl
 def render(self, outfile=sys.stdout, in_place=False):
     if not in_place:
         for _ in range(self.height + 1):
             outfile.write("\n")
         util.print_up(self.height + 1, outfile=outfile)
     super(VersusState, self).render(outfile=outfile, in_place=True)
     status_text = "x{} c{} s{} p{} {}".format(
         self.chain_number, self.chain_score, self.step_score,
         self.pending_garbage, "!" if self.all_clear_pending else "")
     outfile.write(status_text)
     util.print_down(1)
     util.print_back(len(status_text))
示例#3
0
 def render(self, outfile=sys.stdout, in_place=False) -> bool:
     height: int = self.players[0].height
     width: int = self.players[0].width
     if not in_place:
         for _ in range(height + 1):
             outfile.write("\n")
         util.print_up(height + 1, outfile=outfile)
     for player in self.players:
         player.render(outfile=outfile, in_place=True)
         util.print_up(height + 1)
         util.print_forward(2 * width + 9)
     util.print_down(height + 1)
     util.print_back(len(self.players) * (2 * width + 9))
     outfile.flush()
示例#4
0
 def render(self, outfile=sys.stdout, in_place=False):
     if not in_place:
         for _ in range(self.height):
             outfile.write("\n")
         util.print_up(self.height, outfile=outfile)
     self.field.render(outfile, width=self.width, height=self.height, in_place=True)
     util.print_up(self.height, outfile=outfile)
     util.print_forward(2 * self.width + 2, outfile=outfile)
     remaining = self.height
     for deal in self.deals[:self.height // 2]:
         for puyo in deal:
             util.print_puyo(puyo, outfile=outfile)
         util.print_back(4, outfile=outfile)
         util.print_down(2, outfile=outfile)
         remaining -= 2
     util.print_reset(outfile=outfile)
     util.print_down(remaining, outfile=outfile)
     util.print_back(2 * self.width + 2, outfile=outfile)
     outfile.flush()
示例#5
0
 def render(self,
            outfile=sys.stdout,
            width: Optional[int] = None,
            height: Optional[int] = None,
            in_place=False):
     height = height or self.HEIGHT
     width = width or self.WIDTH
     if not in_place:
         for _ in range(height):
             outfile.write("\n")
         util.print_up(height, outfile=outfile)
     for i in range(self.HEIGHT - height, self.HEIGHT):
         offset, row = divmod(i, 8)
         for j in range(width):
             empty = True
             for k in range(self.num_colors):
                 if self.data[row + 8 * k +
                              8 * self.num_layers * offset] & (1 << j):
                     if self.tsu_rules and i <= self.offset:
                         util.print_puyo(k + 7, outfile=outfile)
                     else:
                         util.print_puyo(k, outfile=outfile)
                     empty = False
             if self.has_garbage:
                 garbage_puyo = self.data[row + 8 * self.num_colors +
                                          8 * self.num_layers * offset] & (
                                              1 << j)
                 if garbage_puyo:
                     if self.tsu_rules and i <= self.offset:
                         util.print_color(4, outfile=outfile)
                     else:
                         util.print_color(6, outfile=outfile)
                     outfile.write("\u25ce ")
                     empty = False
             if empty:
                 outfile.write("\u00b7 ")
             util.print_reset(outfile=outfile)
         util.print_down(1, outfile=outfile)
         util.print_back(2 * width, outfile=outfile)