def start_game(m): """Given two player names, start a new game of Tic Tac Toe""" player1 = m.group("player1") player2 = m.group("player2") result = logic.start_game(player1, player2) status = OK if not result: status = ERROR response_body = json.dumps(result) return response(status, JSON, response_body)
def start_game(db, json): players = db.get_by_keys(json['players']) if len(players) < len(json['players']): abort(400, "Not all players exist") if len(players) > MAX_PLAYERS: abort(400, "Can not have more than %i players in one game" % MAX_PLAYERS) if len(players) < MIN_PLAYERS: abort(400, "Can not have less than %i players in a game" % MIN_PLAYERS) game_id = logic.start_game(db, players) return {"game_id": game_id}
# 2048.py # importing the logic.py file # where we have written all the # logic functions used. import logic # Driver code if __name__ == '__main__': # calling start_game function # to initialze the matrix mat = logic.start_game() while (True): # taking the user input # for next step x = input("Press the command : ") # we have to move up if (x == 'W' or x == 'w'): # call the move_up funtion mat, flag = logic.move_up(mat) # get the current state and print it status = logic.get_current_state(mat) print(status) # if game not ove then continue
def init_matrix(self): self.matrix = logic.start_game() logic.add_new_2(self.matrix) logic.add_new_2(self.matrix)
import random from time import sleep import numbers_class as num from numbers_class import Numbers import logic pygame.init() display.set_caption('Simple 2408') screen = display.set_mode((512, 512)) screen.fill((255, 255, 255)) screen.blit(screen, (0, 0)) display.flip() board = logic.start_game() def tiles_change(board): tiles = [] for i in range(4): for j in range(4): tiles.append(Numbers(board, i, j)) return tiles tiles = tiles_change(board) running = True while running: current_events = event.get()