seigot / tetris

A Tetris Game for programming education in Japanese
MIT License
30 stars 107 forks source link

1ライン消し〜4ライン消しした際にその旨をフィールドにわかりやすく表示したい #114

Open seigot opened 1 year ago

seigot commented 1 year ago

1ライン消し〜4ライン消しした際にその旨をフィールドにわかりやすく表示したい "1 line!!" "2 line!!" "3 line!!" "4 line!!" "HOLD!!" "all clear" "N len" など

seigot commented 1 year ago

この辺りを触る、テキスト表示の条件分岐は別途加える 画像はイメージ

diff --git a/game_manager/game_manager.py b/game_manager/game_manager.py
index c661825..49efbcb 100644
--- a/game_manager/game_manager.py
+++ b/game_manager/game_manager.py
@@ -4,7 +4,7 @@
 import sys
 from PyQt5.QtWidgets import QMainWindow, QFrame, QDesktopWidget, QApplication, QHBoxLayout, QLabel
 from PyQt5.QtCore import Qt, QBasicTimer, pyqtSignal
-from PyQt5.QtGui import QPainter, QColor
+from PyQt5.QtGui import QPainter, QColor, QFont

 from board_manager import BOARD_DATA, Shape
 from block_controller import BLOCK_CONTROLLER
@@ -896,6 +896,7 @@ class SidePanel(QFrame):
         painter.drawLine(0, height_offset,
                          self.width(), height_offset)
         painter.drawText(0, self.height(), 'HOLD');
+        # draw
         holdShapeClass, holdShapeIdx, holdShapeRange = BOARD_DATA.getholdShapeData()
         if holdShapeClass != None:
             # if holdShape exists, try to draw
@@ -965,6 +966,15 @@ class Board(QFrame):
         painter.drawLine(self.width()-1, 0, self.width()-1, self.height())
         painter.setPen(QColor(0xCCCCCC))
         painter.drawLine(self.width(), 0, self.width(), self.height())
+        # Draw text
+        painter.setPen(QColor(0x777777))
+        font = painter.font();
+        font.setPixelSize(30);
+        painter.setFont(font);
+        painter.drawText(60, 120, '1 LINE !!');
+        painter.drawText(65, 155, 'HOLD !!');
+        painter.drawText(20, 190, 'Perfect Clear!!');
+#        painter.drawText(65, 190, 'Reset !!');

     ###############################################
     # ログファイル出力
スクリーンショット 2023-05-08 0 06 53
seigot commented 1 year ago

変更箇所は以下の付近

LENとパーフェクトクリアはレベル3対応にするか??

以下、参考コード(途中のもの)

diff --git a/game_manager/block_controller.py b/game_manager/block_controller.py
index b294234..25b45c0 100644
--- a/game_manager/block_controller.py
+++ b/game_manager/block_controller.py
@@ -29,6 +29,10 @@ class Block_Controller(object):
         # print GameStatus
         print("=================================================>")
         pprint.pprint(GameStatus, width = 61, compact = True)
+#        print(GameStatus["debug_info"]["line_score_stat_lasttime"][0])
+#        print(GameStatus["debug_info"]["line_score_stat_lasttime"][1])
+#        print(GameStatus["debug_info"]["line_score_stat_lasttime"][2])
+#        print(GameStatus["debug_info"]["line_score_stat_lasttime"][3])

         # search best nextMove -->
         # random sample
diff --git a/game_manager/game_manager.py b/game_manager/game_manager.py
index c661825..ad4fd6a 100644
--- a/game_manager/game_manager.py
+++ b/game_manager/game_manager.py
@@ -4,7 +4,7 @@
 import sys
 from PyQt5.QtWidgets import QMainWindow, QFrame, QDesktopWidget, QApplication, QHBoxLayout, QLabel
 from PyQt5.QtCore import Qt, QBasicTimer, pyqtSignal
-from PyQt5.QtGui import QPainter, QColor
+from PyQt5.QtGui import QPainter, QColor, QFont

 from board_manager import BOARD_DATA, Shape
 from block_controller import BLOCK_CONTROLLER
@@ -264,6 +264,9 @@ class Game_Manager(QMainWindow):
         self.tboard.linescore = 0
         self.tboard.line = 0
         self.tboard.line_score_stat = [0, 0, 0, 0]
+        self.tboard.line_score_stat_lasttime = [0, 0, 0, 0]
+#        self.tboard.hold_lasttime = 0
+#        self.tboard.perfectclear_lasttime = 0
         self.tboard.start_time = time.time()
         ##画面ボードと現テトリミノ情報をクリア
         BOARD_DATA.clear()
@@ -374,6 +377,7 @@ class Game_Manager(QMainWindow):

                 # if use_hold_function
                 if use_hold_function == "y":
+                    self.tboard.hold_lasttime = time.time_ns()
                     isExchangeHoldShape = BOARD_DATA.exchangeholdShape()
                     if isExchangeHoldShape == False:
                         # if isExchangeHoldShape is False, this means no holdshape exists. 
@@ -482,6 +486,14 @@ class Game_Manager(QMainWindow):
         # 同時消去数をカウント
         if removedlines > 0:
             self.tboard.line_score_stat[removedlines - 1] += 1
+            self.tboard.line_score_stat_lasttime[removedlines - 1] = time.time_ns()
+        # perfect clear判定
+        width = BOARD_DATA.width
+        height = BOARD_DATA.height
+        data = BOARD_DATA.getData()
+        print(data.count(0), width*height)
+        if data.count(0) == width*height:
+            self.tboard.perfectclear_lasttime = time.time_ns()

     ###############################################
     # ゲーム情報の取得
@@ -576,6 +588,7 @@ class Game_Manager(QMainWindow):
                           },
                         },
                         "line_score_stat":"none",
+                        "line_score_stat_lasttime":"none",
                         "shape_info_stat":"none",
                         "random_seed":"none",
                         "obstacle_height":"none",
@@ -630,7 +643,10 @@ class Game_Manager(QMainWindow):
         status["debug_info"]["dropdownscore"] = self.tboard.dropdownscore
         status["debug_info"]["linescore"] = self.tboard.linescore
         status["debug_info"]["line_score_stat"] = self.tboard.line_score_stat
+        status["debug_info"]["line_score_stat_lasttime"] = self.tboard.line_score_stat_lasttime
         status["debug_info"]["shape_info_stat"] = BOARD_DATA.shape_info_stat
+        status["debug_info"]["hold_lasttime"] = self.tboard.hold_lasttime
+        status["debug_info"]["perfectclear_lasttime"] = self.tboard.perfectclear_lasttime
         status["debug_info"]["line_score"]["line1"] = Game_Manager.LINE_SCORE_1
         status["debug_info"]["line_score"]["line2"] = Game_Manager.LINE_SCORE_2
         status["debug_info"]["line_score"]["line3"] = Game_Manager.LINE_SCORE_3
@@ -705,7 +721,10 @@ class Game_Manager(QMainWindow):
                           },
                         },
                         "line_score_stat":"none",
+                        "line_score_stat_lasttime":"none",
                         "shape_info_stat":"none",
+                        "hold_lasttime":"none",
+                        "perfectclear_lasttime":"none",
                         "random_seed":"none",
                         "obstacle_height":"none",
                         "obstacle_probability":"none",
@@ -725,7 +744,10 @@ class Game_Manager(QMainWindow):
         # update status
         ## debug_info
         status["debug_info"]["line_score_stat"] = self.tboard.line_score_stat
+        status["debug_info"]["line_score_stat_lasttime"] = self.tboard.line_score_stat_lasttime
         status["debug_info"]["shape_info_stat"] = BOARD_DATA.shape_info_stat
+        status["debug_info"]["hold_lasttime"] = self.tboard.hold_lasttime
+        status["debug_info"]["perfectclear_lasttime"] = self.tboard.perfectclear_lasttime
         status["debug_info"]["line_score"]["line1"] = Game_Manager.LINE_SCORE_1
         status["debug_info"]["line_score"]["line2"] = Game_Manager.LINE_SCORE_2
         status["debug_info"]["line_score"]["line3"] = Game_Manager.LINE_SCORE_3
@@ -802,6 +824,9 @@ class Game_Manager(QMainWindow):
             # 消去ライン数と落下数によりスコア計算
             self.UpdateScore(removedlines, dropdownlines)
         elif key == Qt.Key_C:
+            print("cc!!")
+            self.tboard.hold_lasttime = time.time_ns()
+            print("self.hold_lasttime:",self.tboard.hold_lasttime)
             BOARD_DATA.exchangeholdShape()
         else:
             # スタート前はキーキャプチャしない
@@ -896,6 +921,7 @@ class SidePanel(QFrame):
         painter.drawLine(0, height_offset,
                          self.width(), height_offset)
         painter.drawText(0, self.height(), 'HOLD');
+        # draw
         holdShapeClass, holdShapeIdx, holdShapeRange = BOARD_DATA.getholdShapeData()
         if holdShapeClass != None:
             # if holdShape exists, try to draw
@@ -934,6 +960,9 @@ class Board(QFrame):
         self.linescore = 0
         self.line = 0
         self.line_score_stat = [0, 0, 0, 0]
+        self.line_score_stat_lasttime = [0, 0, 0, 0]
+        self.hold_lasttime = 0
+        self.perfectclear_lasttime = 0
         self.reset_cnt = 0
         self.start_time = time.time() 
         ##画面ボードと現テトリミノ情報をクリア
@@ -965,6 +994,52 @@ class Board(QFrame):
         painter.drawLine(self.width()-1, 0, self.width()-1, self.height())
         painter.setPen(QColor(0xCCCCCC))
         painter.drawLine(self.width(), 0, self.width(), self.height())
+        # Draw text
+        painter.setPen(QColor(0x777777))
+        font = painter.font();
+        font.setPixelSize(30);
+        painter.setFont(font);
+
+        _1line_score_stat_lasttime = self.line_score_stat_lasttime[0]
+        _2line_score_stat_lasttime = self.line_score_stat_lasttime[1]
+        _3line_score_stat_lasttime = self.line_score_stat_lasttime[2]
+        _4line_score_stat_lasttime = self.line_score_stat_lasttime[3]
+        print(_1line_score_stat_lasttime)
+        print(_2line_score_stat_lasttime)
+        print(_3line_score_stat_lasttime)
+        print(_4line_score_stat_lasttime)
+        print(time.time_ns())
+        print(self.line_score_stat_lasttime)
+        print("self.hold_lasttime:", self.hold_lasttime)
+        print("self.perfectclear_lasttime:", self.perfectclear_lasttime)
+
+        # Draw text
+        blank_text = "              "
+        text = blank_text
+        currentTime = time.time_ns()
+        _1sec = 1000000000 * 0.9 # nsec
+        # removed line
+        if currentTime - self.line_score_stat_lasttime[0] < _1sec:
+            text = '1 LINE !!'
+        if currentTime - self.line_score_stat_lasttime[1] < _1sec:
+            text = '2 LINE !!'
+        if currentTime - self.line_score_stat_lasttime[2] < _1sec:
+            text = '3 LINE !!'
+        if currentTime - self.line_score_stat_lasttime[3] < _1sec:
+            text = '4 LINE !!'
+        painter.drawText(60, 120, text);
+#        painter.drawText(10, 120, '1 LINE !!(11len)');
+        # hold
+        text = blank_text
+        if currentTime - self.hold_lasttime < _1sec:
+            text = 'HOLD !!'
+        painter.drawText(65, 155, text);
+        # perfect clear
+        text = blank_text
+        if currentTime - self.perfectclear_lasttime < _1sec:
+            text = 'Perfect Clear !!'
+        painter.drawText(20, 190, text);
+#        painter.drawText(65, 190, 'Reset !!');

     ###############################################
     # ログファイル出力
seigot commented 1 year ago

https://github.com/seigot/tetris/commit/856c0ee3bc0a5b0322427596d1dbb250263630ab

seigot commented 1 year ago

とりあえず表示だけ

seigot commented 1 year ago

https://github.com/seigot/tetris/pull/116

gitauto-ai[bot] commented 2 days ago

@seigot Pull request completed! Check it out here https://github.com/seigot/tetris/pull/184 🚀

Note: I automatically create a pull request for an unassigned and open issue in order from oldest to newest once a day at 00:00 UTC, as long as you have remaining automation usage. Should you have any questions or wish to change settings or limits, please feel free to contact info@gitauto.ai or invite us to Slack Connect.