def _perform_move(self, start_pos, finish_pos): if self.field.is_correct_move(start_pos, finish_pos): self.field.perform_move(start_pos, finish_pos) if not self._try_find_and_remove_line(finish_pos): if self.field.empty_cells_count < len(self.next_balls_to_add): self._is_over = True else: BallGenerator.place_balls(self.field, self, self.next_balls_to_add) self._generate_next_balls()
def test_generate_simple_balls(self): self.assertTrue( len( list( filter(lambda x: x.is_multicolor, BallGenerator.generate_balls(100, False, False)))) == 0)
def test_set_ball(self): ball = BallGenerator.generate_balls(1, False) coordinates = (1, 1) self.field.set_ball(coordinates, ball) self.assertTrue(self.field.empty_cells_count == 24) self.assertTrue(self.field[coordinates].ball == ball)
def main(): parser = create_parser() game_field = ConsoleField(parser.size) controller = ConsoleController( game_field, ScoreBoard.load_from(parser.records, parser.hint_mode), parser.debug) BallGenerator.place_balls( ConsoleField(parser.size), controller, BallGenerator.generate_balls(10, parser.debug, False)) cls() print("""Hello there! to start playing print 'start' use 'help' to get other commands Good luck!""") while not controller.is_over: try: run_command(controller) except (KeyboardInterrupt, EOFError): print("\nTo stop the game type 'exit'") while 1: cls() print("""Game Over You scored {} points Please input your name """.format(controller.current_score)) try: controller.score_table.set_name(input()) break except ValueError as e: print(e) controller.score_table.save()
def test_place_balls(self): ball = BallGenerator.generate_balls(1, False, False) field = GameField(5) controller = Controller(field, ScoreBoard("", {1: 1}, 1), False) BallGenerator.place_balls(field, controller, ball) self.assertTrue(ball[0] in map(lambda x: x[0], field.balls))
def test_generate_n_balls(self): self.assertTrue( len(BallGenerator.generate_balls(100, False, True)) == 100)
def _generate_next_balls(self): self.next_balls_to_add = BallGenerator.generate_balls( 3, self.debug, (self.score_table.current_score > max( 20 * self.min_score, self.score_table.max_score)))
from Gui.gui_field import GuiField from Model.ball_generator import BallGenerator from Model.game_field import GameField from Model.score_board import ScoreBoard from utils import create_parser try: from PyQt5 import QtGui, QtCore, QtWidgets except Exception as e: sys.stderr.write('PyQt5 not found: "{}"'.format(e).encode()) sys.exit(config.QT_NOT_FOUND) if __name__ == '__main__': parser = create_parser() app = QtWidgets.QApplication(sys.argv) game_field = GameField(parser.size) controller = GuiController( game_field, ScoreBoard.load_from(parser.records, parser.hint_mode), parser.debug) BallGenerator.place_balls(GameField(parser.size), controller, BallGenerator.generate_balls(10, parser.debug, False)) ex = GuiField(game_field, controller) sys.exit(app.exec_())