hello peoples today I wanted to turn this into a Connect 4 style of game first I would load a connect4startmenu.pyui that has one TextField that has a placeholder that says add number of games to play, and one button on it that says Add Winning shape and , and I would like the Add Winning shape button to start my connect4addwinningshape.py scene ............. so I could pick any shape to win the game for each new game added like 4 in a row, or a 5 in a row, or 2by2 square, or a 3by3 square that has an empty square in the middle, or a 5by5 square that has the middle 3by3 squares empty, or the four corners of the grid, or like an L shape, or a Triangle of any size..........then when I tap the P button on the top of the connect4addwinngshape.py scene the game starts the connect4game.py and loads the number of games to play .......the hearts would represent the number of games your playing, for example 2 games at the same time , or 5 games and TAPPING the heart would switch between games
The first screen is connect4startmenu.pyui
The pyui with the TextField and button
Then the second screen is connect4addwinngshape.py
from scene import*
import scene, ui
class Block(scene.ShapeNode):
def __init__(self, x, y, w, h,fill_color='blue', parent=None):
path = ui.Path.rect(0, 0, w, h)
self.label = None
self.root = parent
super(Block, self).__init__(path=path,
fill_color=fill_color,
position=(x, y),
parent=parent)
def touch_began(self, touch):
if not self.label:
self.label = scene.LabelNode('♛',
font=('Helvetica', 40),
color='green', parent=self.root)
self.add_child(self.label)
class MyScene (scene.Scene):
def setup(self):
self.background_color = 'gray'
colorlist = ['black', 'white']
self.grid = {}
for grid in range(2):
m, n = 10,10
w, h = 64, 64
start_x, start_y = self.size[1]/2-n/1.53*w, self.size[1]/2 - m/2*h
#self.grid = {}
for i in range(m):
for j in range(n):
x, y = start_x+i*w, start_y+j*h
self.grid[i,j] = Block(x, y, w, h,
fill_color=colorlist[(i+j)%2],
parent=self)
#start playing games symbol
self.play_button = SpriteNode('iow:social_pinterest_256', position=(32, self.size.h-32), parent=self)
self.play_button.size = (50,50)
#undo symbol
self.undo_button = SpriteNode('iow:reply_256', position=(90, self.size.h-31), parent=self)
self.undo_button.size = (50,50)
#redo symbol
self.redo_button = SpriteNode('iow:refresh_24', position=(160, self.size.h-31), parent=self)
self.redo_button.size = (50,50)
def touch_began(self, touch):
for i, j in self.grid:
if (touch.location in (self.grid[i, j].frame)):
self.grid[i,j].touch_began(touch)
return
scene.run(MyScene(), show_fps=True)
Then the third screen is the playing game screen that lets you switch between games being played (it would be useful if you could choose different wining shape for the games in the pawz menu
from scene import*
import scene, ui
import random
class Block(scene.ShapeNode):
def __init__(self, x, y, w, h,fill_color='blue', parent=None):
path = ui.Path.rect(0, 0, w, h)
self.label = None
self.root = parent
super(Block, self).__init__(path=path,
fill_color=fill_color,
position=(x, y),
parent=parent)
def touch_began(self, touch):
if not self.label:
self.label = scene.LabelNode('😜',
font=('Helvetica', 40),
color='#ffffff', parent=self.root)
self.add_child(self.label)
class MyScene (scene.Scene):
def setup(self):
self.background_color = 'gray'
colorlist = ['black', 'white']
self.grid = {}
for grid in range(2):
m, n = 10,10
w, h = 64, 64
start_x, start_y = self.size[1]/2-n/1.53*w, self.size[1]/2 - m/2*h
#self.grid = {}
for i in range(m):
for j in range(n):
x, y = start_x+i*w, start_y+j*h
self.grid[i,j] = Block(x, y, w, h,
fill_color=colorlist[(i+j)%2],
parent=self)
#pause symbol
self.pause_button = SpriteNode('iow:pause_32', position=(32, self.size.h-32), parent=self)
#undo symbol
self.undo_button = SpriteNode('iow:reply_256', position=(90, self.size.h-31), parent=self)
self.undo_button.size = (50,50)
#redo symbol
self.redo_button = SpriteNode('iow:refresh_24', position=(160, self.size.h-31), parent=self)
self.redo_button.size = (50,50)
#number of games you are playing symbols so you can switch between scenes(games)
self.emojis = []
emoji_image_list = ['emj:Card_Hearts']
for y in range(2):
for x in range(10):
new_emoji = SpriteNode(random.choice(emoji_image_list))
new_emoji.position = (x * 70+75,y * 80+840)
self.add_child(new_emoji)
self.emojis.append(new_emoji)
def touch_began(self, touch):
for i, j in self.grid:
if (touch.location in (self.grid[i, j].frame)):
self.grid[i,j].touch_began(touch)
return
def touch_ended(self, touch):
if self.pause_button.frame.contains_point(touch.location):
self.v = ui.load_view('pawz.pyui')
self.v['button1'].action = self.pawz_button_action
self.v.present('sheet')
self.v['textfield1'].begin_editing()
def pawz_button_action(self,sender):
txt = self.v['textfield1'].text
self.v.close()
scene.run(MyScene(), show_fps=True)