• sodoku

    @cvp So could ? this be an alternative for scene selecting ,as opposed to presenting scene and dismissing scene

    posted in Pythonista read more
  • sodoku

    How do I add SpriteNodes and label nodes to the different coloured views

    import ui
    class TabbedView(ui.View):
        def __init__(self,tablist=[], frame=(0,0)+ui.get_screen_size()):
            #takes an iterable of Views, using the view name as the tab selector.  
            #empty views sre just given generic names
            self.tabcounter=0    #unique counter, for name disambiguation
            self.buttonheight=30 #height of buttonbar
            #setup button bar
            self.tabbuttons=ui.SegmentedControl(frame=(0,0,self.width, self.buttonheight))
            self.tabbuttons.action=self.tab_action
            self.tabbuttons.flex='W'
            self.tabbuttons.segments=[]
            self.add_subview(self.tabbuttons)
    
            for tab in tablist:
                self.addtab(tab)
        def tab_action(self,sender):
            if sender.selected_index >= 0:
                tabname=sender.segments[sender.selected_index]
                self[tabname].bring_to_front()
        def focus_tab_by_index(self,index):
            self.tabbuttons.selected_index=index
            self.tab_action(self.tabbuttons)
        
        def focus_tab_by_name(self,tabname):
            self.tabbuttons.selected_index=self.tabbuttons.segments.index(tabname)
            self.tab_action(self.tabbuttons)
    
        def addtab(self,tab):
                if not tab.name:
                    tab.name='tab{}'.format(self.tabcounter)
                if tab.name in self.tabbuttons.segments:
                    #append unique counter to name
                    tab.name+=str(self.tabcounter)
                self.tabcounter+=1
                self.tabbuttons.segments+=(tab.name,) 
                tab.frame=(0,self.buttonheight,self.width,self.height-self.buttonheight)
                tab.flex='WH'
                self.add_subview(tab)
                self.focus_tab_by_name(tab.name)
    
        def removetab(self,tabname):
            self.tabbuttons.segments=[x for x in self.tabbuttons.segments if x != tabname]
            self.remove_subview(tabname)
            # if tab was top tab, think about updating selected tab to whatever is on top 
            
        def layout(self):
            pass   # maybe set tabbuttons size
            
    if __name__=='__main__':
        v=TabbedView()
        v.addtab(ui.View(name='card1',bg_color='red'))
        v.addtab(ui.View(name= 'card3',bg_color='blue'))
        v.addtab(ui.View(name='card2',bg_color='green'))
        v.addtab(ui.View(name= 'card4',bg_color='#ff78be'))
        v.addtab(ui.View(name= 'mycard',bg_color='#f7ff43'))
        v.present()
    

    posted in Pythonista read more
  • sodoku

    @ccc I could not figure out how the Pyui files from github were able to be copied to my iPad Pythonista module, and it looked intimidating and more confusing to use than this website site

    posted in Pythonista read more
  • sodoku

    Another feature to add is deaclare the winner some how and notify the players who won

    posted in Pythonista read more
  • sodoku

    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)
    

    posted in Pythonista read more
  • sodoku

    Wow fantastic, your truly amazing I can’t thank you enough

    posted in Pythonista read more
  • sodoku

    @cvp is it possible not to erase the emoji when you add more then one
    For example if I add emojis to Level 1 then if I add an emoji to Game Over without deleting the Level 1 emojis so all three are covered??or all four can be covered
    This aspect worked in the previous version you coded before the undo redo upgrade

    posted in Pythonista read more
  • sodoku

    @cvp
    Awesome logic skills dude thanks I’m learning a lot from you

    posted in Pythonista read more
  • sodoku

    Just the last one should do the trick

    posted in Pythonista read more
  • sodoku

    After I’ve added an emoji with the button inside the pause menu then I would like to undo add emoji and then redo add emoji Incase I’ve made mistakes

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!