+ 2

How can I switch between 2 or more add_child ?

https://sololearn.com/compiler-playground/cn7TS87qF17j/?ref=app Can this work? Count = 0 Player = true Player_2 = false If count == 0 and player == True: Add_child 1 Count += 1 Elif count == 1 and player == false and player_2 == true: Add_child 2 Count -= 1

24th Dec 2023, 2:42 AM
Nicola
Nicola  - avatar
15 Answers
+ 1
What is done in a typical tic-tac-toe game with gui is that a cell class is created that initially displays a blank square. It displays x or o depending on whether the move counter is even or odd. The move counter is incremented when the cell is touched. Create 9 cells and arrange them into a grid of 3x3 and you have the start of a tic-tac-toe gui. Then it's a matter of getting the display of the states and determining win/lose/tie. Here is an html mockup of the basic structure. The internal state representation and win/lose/tie logic is not yet implemented. It's just a quick proof of concept. The important part is that each cel is an individual reactive instance, so there is no need to track the entire board. https://sololearn.com/compiler-playground/WsvbidfvDLOr/?ref=app
25th Dec 2023, 12:19 AM
Bob_Li
Bob_Li - avatar
+ 1
Bob_Li Tóxico ! i have solved, i made 9 series of if who on every serie of if i increment +1 after every player chose, and work. This is the code. https://sololearn.com/compiler-playground/cOLTg3T2u9GX/?ref=app
25th Dec 2023, 7:30 AM
Nicola
Nicola  - avatar
+ 1
Bob_Li i’m a baginner
25th Dec 2023, 10:56 AM
Nicola
Nicola  - avatar
+ 1
Nicola It's a good start. Getting code to work with the method you know and understand is the way to go. Optimization is an iterative process.🤓
25th Dec 2023, 2:51 PM
Bob_Li
Bob_Li - avatar
0
In the provided code, you're attempting to switch between two add_child operations based on certain conditions. However, the code has a few issues. Here's an improved version: count = 0 player = True player_2 = False if count == 0 and player: print("Adding child 1") count += 1 elif count == 1 and not player and player_2: print("Adding child 2") count -= 1
24th Dec 2023, 8:49 AM
卂ㄚㄩ丂卄
卂ㄚㄩ丂卄 - avatar
0
卂ㄚㄩ丂卄 this the part of cose who i add your if, but continue to add only first 9 add_child and the rest not Bob_Li check the code https://sololearn.com/compiler-playground/cn7TS87qF17j/?ref=app
24th Dec 2023, 10:30 AM
Nicola
Nicola  - avatar
0
your indentations are messed up...
24th Dec 2023, 10:40 AM
Bob_Li
Bob_Li - avatar
0
Bob_Li 卂ㄚㄩ丂卄 Self.croce_1 and self.cerchio_1 are in the same position but after the first self.croce ( add_child ) dont switch to self.cerchio_1 but add self.croce_1 count = 0 player = True player_2 = False if count == 0 and player: self.add_child(self.croce) count += 1 self.add_child(self.croce_1) count += 1 if count == 1 and not player and player_2: self.add_child(self.cerchio_1)
24th Dec 2023, 1:04 PM
Nicola
Nicola  - avatar
0
perhaps you want replace child, not add child? But not being familiar with your app, I'm afraid I'm not sure how to do this.
24th Dec 2023, 1:29 PM
Bob_Li
Bob_Li - avatar
0
Bob_Li is the tiktaktoe with scene2d PYTHON GUI. Game with 2 players and 18 simbols, 9 ✖️, and 9 ⭕️, i want to switch between player1 ✖️ and player2 ⭕️. 1 position for both symbols and players
24th Dec 2023, 1:44 PM
Nicola
Nicola  - avatar
0
Whit this part of code add first croce and cerchio in te same position, And croce_1 and cerchio_1 in the other position. I wanth first croce 1 time in 1 position becouse is the first add, and after i wanth cerchio_1 in the other position, switch between all croce and all cerchio , how to do ? player = 0 player_1 = 5 for player in range(player_1): if player_1: self.add_child(self.croce) self.add_child(self.croce_1) if player: self.add_child(self.cerchio) self.add_child(self.cerchio_1)
24th Dec 2023, 6:01 PM
Nicola
Nicola  - avatar
24th Dec 2023, 6:11 PM
Nicola
Nicola  - avatar
0
class MyScene (Scene): def setup(self): # ... (código de setup) def did_change_size(self): pass def update(self): pass def touch_began(self, touch): x, y = touch.location # Lógica para tratar toques e animações # Loop para adicionar elementos for _ in range(5): # Utilizando um loop simples para adicionar 5 elementos self.add_child(self.croce) self.add_child(self.croce_1) self.add_child(self.cerchio) self.add_child(self.cerchio_1) # Remova esta parte caso você queira adicionar elementos baseado em alguma condição # player = 0 # player_1 = 5 # for player in range(player_1): # if player_1: # self.add_child(self.croce) # self.add_child(self.croce_1) # if player: # self.add_child(self.cerchio) # self.add_child(self.cerchio_1)
24th Dec 2023, 6:41 PM
Tóxico !
Tóxico ! - avatar
0
Great. Still too many hardcoded values for my taste, but if it works, then it's good. 9 buttons arranged in a grid might works as well.
25th Dec 2023, 8:15 AM
Bob_Li
Bob_Li - avatar
0
Hi
25th Dec 2023, 4:11 PM
Afrid Afrid
Afrid Afrid - avatar