def select_second(game_array_select): global turns global moves row1 = first_position[0] column1 = first_position[1] if turns == 2: turns = 1 x = stddraw.mouseX() y = stddraw.mouseY() for i in range(9): for j in range(7): if x > j and x < j + 1 and y > i and y < i + 1: if i == row1 and j == column1: stddraw.setPenColor(stddraw.WHITE) stddraw.square(first_position[1] + 0.5, first_position[0] + 0.5, 0.5) juweimodule.draw_new_things(game_board, score) else: if i == row1 and j != column1: if j - 1 == column1 or j + 1 == column1: swap = game_board[i][j] game_board[i][j] = game_board[row1][column1] game_board[row1][column1] = swap scan_for_same() if display() == 1: moves -= 1 juweimodule.draw_new_things( game_board, score) else: swap = game_board[i][j] game_board[i][j] = game_board[row1][ column1] game_board[row1][column1] = swap reminding_not_matching() else: reminding_faulse_move() elif j == first_position[1] and i != first_position[0]: if i - 1 == row1 or i + 1 == row1: swap = game_board[i][j] game_board[i][j] = game_board[row1][column1] game_board[row1][column1] = swap scan_for_same() if display() == 1: moves -= 1 juweimodule.draw_new_things( game_board, score) else: swap = game_board[i][j] game_board[i][j] = game_board[row1][ column1] game_board[row1][column1] = swap reminding_not_matching() else: reminding_faulse_move() else: reminding_faulse_move() return game_array_select
def reSquares(n, x, y, r): if n == 0: return stddraw.setPenColor(stddraw.GRAY) stddraw.filledSquare(x, y, r) stddraw.setPenColor() stddraw.square(x, y, r) reSquares(n - 1, x - r, y + r, r / 2.2) reSquares(n - 1, x - r, y - r, r / 2.2) reSquares(n - 1, x + r, y + r, r / 2.2) reSquares(n - 1, x + r, y - r, r / 2.2)
def draw(self): # draw the tile as a filled square stddraw.setPenColor(self.background_color) stddraw.filledSquare(self.position.x, self.position.y, 0.5) # draw the bounding box of the tile as a square stddraw.setPenColor(self.boundary_color) stddraw.setPenRadius(Tile.boundary_thickness) stddraw.square(self.position.x, self.position.y, 0.5) stddraw.setPenRadius() # reset the pen radius to its default value # draw the number on the tile stddraw.setPenColor(self.foreground_color) stddraw.setFontFamily(Tile.font_family) stddraw.setFontSize(Tile.font_size) stddraw.boldText(self.position.x, self.position.y, str(self.number))
def select_first(game_array_select): global turns global moves if turns == 1: turns = 2 x = stddraw.mouseX() y = stddraw.mouseY() for i in range(7): for j in range(9): if x > i and x < i + 1 and y > j and y < j + 1: stddraw.setPenColor(stddraw.RED) stddraw.square(i + 0.5, j + 0.5, 0.5) game_array_select[j][i] = 1 return game_array_select
def draw_squares(n, center_x, center_y, size): if n <= 1: return draw_squares(n - 1, center_x - size, center_y - size, size / 2.1) draw_squares(n - 1, center_x + size, center_y - size, size / 2.1) draw_squares(n - 1, center_x - size, center_y + size, size / 2.1) draw_squares(n - 1, center_x + size, center_y + size, size / 2.1) stddraw.square(center_x, center_y, size) stddraw.setPenColor(color.GRAY) stddraw.filledSquare(center_x, center_y, size - 0.002) # you may need to change the value of 0.002 because of your screen resolution stddraw.setPenColor(color.BLACK)
def swap(gridValues): gridVal = (0, 0) gridVal2 = (0, 0) notDone = True notDone2 = True lastVal = 0 lastVal2 = 0 while (notDone2): while (notDone): gridVal = clickToValue() stddraw.setPenColor(stddraw.RED) stddraw.square(-300 + 100 * gridVal[1], 400 - 100 * gridVal[0], 48.5) gridVal2 = clickToValue() if (gridVal2 == (gridVal[0] + 1, gridVal[1]) or gridVal2 == (gridVal[0] - 1, gridVal[1]) or gridVal2 == ( gridVal[0], gridVal[1] + 1) or gridVal2 == (gridVal[0], gridVal[1] - 1)): temp = gridValues[gridVal[0]][gridVal[1]] gridValues[gridVal[0]][gridVal[1]] = gridValues[gridVal2[0]][gridVal2[1]] gridValues[gridVal2[0]][gridVal2[1]] = temp fillValue(gridVal[0], gridVal[1], gridValues) fillValue(gridVal2[0], gridVal2[1], gridValues) notDone = False else: fillValue(gridVal[0], gridVal[1], gridValues) stddraw.show(250) if (not horizCheck(gridValues) or not vertCheck(gridValues)): gridValues = replaceAndPoints(gridValues) refresh(gridValues[0]) notDone2 = False else: temp = gridValues[gridVal[0]][gridVal[1]] gridValues[gridVal[0]][gridVal[1]] = gridValues[gridVal2[0]][gridVal2[1]] gridValues[gridVal2[0]][gridVal2[1]] = temp fillValue(gridVal[0], gridVal[1], gridValues) fillValue(gridVal2[0], gridVal2[1], gridValues) if (horizCheck(gridValues) and vertCheck(gridValues) and notDone2): notDone = True return gridValues[0], gridValues[1]
def drawShapes(number,x,y): stddraw.setPenColor(stddraw.BLACK) stddraw.setPenRadius(0.01) if number == 0: stddraw.square(x,y,0.4) stddraw.setPenColor(stddraw.YELLOW) stddraw.filledSquare(x,y,0.4) if number == 1: stddraw.setPenColor(stddraw.RED) stddraw.filledCircle(x,y,0.4) stddraw.setPenColor(stddraw.BLACK) stddraw.setPenRadius(0.004) stddraw.circle(x,y,0.4) if number == 2: xs = [x-0.4,x+0.4,x] ys = [y-0.4,y-0.4,y+0.4] stddraw.polygon(xs,ys) stddraw.setPenColor(stddraw.ORANGE) stddraw.filledPolygon(xs,ys) if number == 3: xs = [x-0.4,x,x+0.4,x] ys = [y,y+0.4,y,y-0.4] stddraw.polygon(xs,ys) stddraw.setPenColor(stddraw.GREEN) stddraw.filledPolygon(xs,ys) if number == 4: xs = [x-0.4,x-0.2,x+0.2,x+0.4,x] ys = [y,y+0.4,y+0.4,y,y-0.4] stddraw.polygon(xs,ys) stddraw.setPenColor(stddraw.MAGENTA) stddraw.filledPolygon(xs,ys) if number == 5: xs = [x-0.4,x-0.2,x+0.4,x+0.2] ys = [y-0.4,y+0.4,y+0.4,y-0.4] stddraw.polygon(xs,ys) stddraw.setPenColor(stddraw.BLUE) stddraw.filledPolygon(xs,ys)
def redBox(x,y): if y <= 9: stddraw.setPenColor(stddraw.BLACK) stddraw.setFontSize(20) stddraw.setPenColor(stddraw.RED) stddraw.square(x+0.5,y+0.5,0.5)
sd.setYscale(-1, 9) p2Mod.fill(board, COLUMNS, ROWS) while p2Mod.winCheck(board, COLUMNS, ROWS): p2Mod.fill(board, COLUMNS, ROWS) while not p2Mod.isDraw(board, COLUMNS, ROWS) and turn < FINALTURN: #Note a turn is used up if a turn is Valid but does not result in any pieces getting removed and thus the move is #reversed but a turn is still counted. This is intentional. If this is not wanted the turn+1 can be moved to the #combo loop turn += 1 p2Mod.drawBoard(board, COLUMNS, ROWS, score, turn) sd.show(1) validMove = False while not validMove: piece1 = p2Mod.getMove(board, COLUMNS, ROWS) sd.square(piece1[0]+.5, piece1[1]+.5, .5) sd.show(1) piece2 = p2Mod.getMove(board, COLUMNS, ROWS) sd.square(piece2[0] + .5, piece2[1] + .5, .5) sd.show(500) dif1 = (piece1[0] - piece2[0]) * (piece1[0] - piece2[0]) dif2 = (piece1[1] - piece2[1]) * (piece1[1] - piece2[1]) p2Mod.drawBoard(board, COLUMNS, ROWS, score, turn) if (dif1 == 0 and dif2 == 1) or (dif1 == 1 and dif2 == 0): validMove = True p2Mod.move(board, piece1, piece2) sd.clear() p2Mod.drawBoard(board, COLUMNS, ROWS, score, turn) sd.show(200) if not p2Mod.winCheck(board, COLUMNS, ROWS): p2Mod.move(board, piece1, piece2)
import stddraw as d import sys d.square(.2, .8, .1) d.filledSquare(.8, .8, .2) d.circle(.8, .2, .2) d.show(0) c = '' while c != '.': c = input()
def draw(self): # draw the tile as a filled square if (self.number == 2): self.background_color = Color(238, 228, 218) # background (tile) color if (self.number == 4): self.background_color = Color(237, 224, 200) # background (tile) color if (self.number == 8): self.background_color = Color(242, 177, 121) # background (tile) color if (self.number == 16): self.background_color = Color(245, 149, 99) # background (tile) color if (self.number == 32): self.background_color = Color(246, 124, 95) # background (tile) color if (self.number == 64): self.background_color = Color(246, 94, 59) # background (tile) color if (self.number == 128): self.background_color = Color(237, 207, 114) # background (tile) color if (self.number == 256): self.background_color = Color(237, 204, 97) # background (tile) color if (self.number == 512): self.background_color = Color(237, 200, 80) # background (tile) color if (self.number == 1024): self.background_color = Color(237, 197, 63) # background (tile) color if (self.number == 2048): self.background_color = Color(237, 194, 46) # background (tile) color #used proper colors until 2048 #used remainder in order to get a proper color for every number #with this the value will never exceed 255 however better solution may be proposed if (self.number > 2048): self.background_color = Color( (self.number % 255), (self.number % 20), (self.number % 255)) stddraw.setPenColor(self.background_color) stddraw.filledSquare(self.position.x, self.position.y, 0.5) # draw the bounding box of the tile as a square stddraw.setPenColor(self.boundary_color) stddraw.setPenRadius(Tile.boundary_thickness) stddraw.square(self.position.x, self.position.y, 0.5) stddraw.setPenRadius() # reset the pen radius to its default value # draw inner lines x = self.position.x y = self.position.y stddraw.setPenColor(self.foreground_color) stddraw.square(x, y, 0.3) stddraw.setPenRadius(Tile.boundary_thickness) stddraw.line(x - 0.5, y - 0.5, x + 0.5, y + 0.5) stddraw.line(x - 0.5, y + 0.5, x + 0.5, y - 0.5) #draw inner box stddraw.setPenRadius() stddraw.setPenColor(self.background_color) stddraw.filledSquare(self.position.x, self.position.y, 0.3) ############################### #stddraw.setPenColor(stddraw.RED) #stddraw.filledCircle(0.5, 0.5, 0.3) #stddraw.filledCircle(-0.5,0.5,0.3) # draw the number on the tile stddraw.setPenColor(self.foreground_color) stddraw.setFontFamily(Tile.font_family) stddraw.setFontSize(Tile.font_size) stddraw.boldText(self.position.x, self.position.y, str(self.number))
def draw_box(x, y): stddraw.setPenColor(stddraw.BOOK_LIGHT_BLUE) stddraw.setPenRadius(0.005) stddraw.square(x, y, 2.0) stddraw.show(50.0)
def clear_box(x, y): stddraw.setPenColor(stddraw.WHITE) stddraw.setPenRadius(0.005) stddraw.square(x, y, 2.0) stddraw.show(50.0)
def drawYSquare(x, y): erase(x, y) stddraw.setPenColor(stddraw.YELLOW) stddraw.filledSquare(x, y, r) stddraw.setPenColor(stddraw.BLACK) stddraw.square(x, y, r)
def drawSquare(x, y, size): stddraw.setPenColor(stddraw.LIGHT_GRAY) stddraw.filledSquare(x, y, size / 2) stddraw.setPenColor(stddraw.BLACK) stddraw.square(x, y, size / 2)
centro = dimN / 2 d.setXscale(0, dimN) d.setYscale(0, dimN) while times != 0: i = input("1 para seguir otro numero para cancelar: ") if i == 1: d.clear() create_matrix(dim, matrix) stil = run_dog(times, dim, matrix, listX, listY) tam = len(listX) ini = 0 while ini < tam: d.square(listX[ini], listY[ini], 5) d.setPenColor(d.BLUE) d.text(listX[ini], listY[ini], str(ini)) ini += 1 if stil == 1: d.setPenColor(d.RED) d.text(centro, 3, "PERRITO VIVE! :D") else: d.setPenColor(d.RED) d.text(centro, 3, "PERRITO MUERE T.T") times -= 1 matrix = [] listX = [] listY = [] d.show(0)
def clear_box(x, y): stddraw.setPenColor(stddraw.WHITE) stddraw.square(x, y, .5)
def box(x, y): stddraw.setPenColor(stddraw.MAGENTA) stddraw.square(x, y, .5)
#----------------------------------------------------------------------- # shapestext.py #----------------------------------------------------------------------- import stddraw # Draw some shapes and some text. stddraw.createWindow() stddraw.square(.2, .8, .1) stddraw.filledSquare(.8, .8, .2) stddraw.circle(.8, .2, .2) xd = [.1, .2, .3, .2] yd = [.2, .3, .2, .1] stddraw.filledPolygon(xd, yd) stddraw.setFontFamily('Times') stddraw.setFontSize(40) stddraw.text(.2, .5, 'black') stddraw.setPenColor(stddraw.WHITE) stddraw.setFontFamily('Courier') stddraw.setFontSize(30) stddraw.text(.8, .8, 'white') stddraw.show() stddraw.wait()