Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Row Count and coloumn count
#1
Im making my first game on python and it was talking about adding row and coloumn counts could someone explain what that means and what does it do ?
Reply
#2
You will need to provide more information. The question is kinda vague.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
(Oct-15-2022, 06:31 PM)menator01 Wrote: You will need to provide more information. The question is kinda vague.
So im watching this video on a tile game and he said everytime i go through one of the tiles increase that variable by one and I didnt really Understand what he was talking about. Ive also never used this type of code before so I dont understand it. here is my code for reference
row_count = 0
        for row in data: 
            col_count = 0
            for tile in row:
                if tile == 1:
                    img = pygame.transform.scale(dirt_img, (tile_size, tile_size)) 
                    img_rect = img.get_rect()
                    img_rect.x = col_count * tile_size
                    img_rect.y = row_count * tile_size
                    tile = (img, img_rect) 
                    self.tile_list.append(tile)              
                col_count += 1
            row_count += 1

world_data = [
[ 1 ,1 ,1, 1, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,1 ,1, 1, 1],
]
Reply
#4
world_data can be thought of as a grid, like a chessboard. "tile" is used to refer to the individual squares. A row is a group of tiles aligned in one direction, and a column is a group of tiles aligned in the other direction (often horizontal rows and vertical columns).

For your example:
world_data = [
[ 1 ,1 ,1, 1, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,1 ,1, 1, 1],
]
The first row is:
[ 1 ,1 ,1, 1, 1]
and the first column is
[ 1,
  1,
  1,
  1,
  1 ],
The way world_data is organized, it is very easy to loop through the rows, because each row is a list.
row[0] = [ 1 ,1 ,1, 1, 1]
row[1] = [ 1 ,0, 0, 0, 1]
row[2] = [ 1 ,0, 0, 0, 1]
row[3] = [ 1 ,0, 0, 0, 1]
row[4] = [ 1 ,1 ,1, 1, 1],
The "for row in data:" loop will run 5 times, once for each row shown above. The first time through the loop it uses row[0], the second time through the loop it uses row[1]. This continues until the last loop uses row[4].

"for tile in row:" works just like "for row in data", except this time it loops through the values in row. If row == row[1]:
tile[0] = 1
tile[1] = 0
tile[2] = 0
tile[3] = 0
tile[4] = 1
Reply
#5
(Oct-16-2022, 04:28 AM)deanhystad Wrote: world_data can be thought of as a grid, like a chessboard. "tile" is used to refer to the individual squares. A row is a group of tiles aligned in one direction, and a column is a group of tiles aligned in the other direction (often horizontal rows and vertical columns).

For your example:
world_data = [
[ 1 ,1 ,1, 1, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,0, 0, 0, 1],
[ 1 ,1 ,1, 1, 1],
]
The first row is:
[ 1 ,1 ,1, 1, 1]
and the first column is
[ 1,
  1,
  1,
  1,
  1 ],
The way world_data is organized, it is very easy to loop through the rows, because each row is a list.
row[0] = [ 1 ,1 ,1, 1, 1]
row[1] = [ 1 ,0, 0, 0, 1]
row[2] = [ 1 ,0, 0, 0, 1]
row[3] = [ 1 ,0, 0, 0, 1]
row[4] = [ 1 ,1 ,1, 1, 1],
The "for row in data:" loop will run 5 times, once for each row shown above. The first time through the loop it uses row[0], the second time through the loop it uses row[1]. This continues until the last loop uses row[4].

"for tile in row:" works just like "for row in data", except this time it loops through the values in row. If row == row[1]:
tile[0] = 1
tile[1] = 0
tile[2] = 0
tile[3] = 0
tile[4] = 1

Thank you for the help
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Count image's colors very fast flash77 18 1,564 Mar-05-2024, 06:12 PM
Last Post: deanhystad
  Function to count words in a list up to and including Sam Oldman45 15 6,573 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Strange argument count error rowan_bradley 3 718 Aug-06-2023, 10:58 AM
Last Post: rowan_bradley
  count certain task in task manager[solved] kucingkembar 2 1,122 Aug-29-2022, 05:57 PM
Last Post: kucingkembar
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,593 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  How to get unique entries in a list and the count of occurrence james2009 5 2,984 May-08-2022, 04:34 AM
Last Post: ndc85430
  df column mean and count of unique SriRajesh 0 1,117 May-07-2022, 08:19 AM
Last Post: SriRajesh
  Unable to count the number of tries in guessing game. Frankduc 7 1,906 Mar-20-2022, 08:16 PM
Last Post: menator01
  Problem : Count the number of Duplicates NeedHelpPython 3 4,374 Dec-16-2021, 06:53 AM
Last Post: Gribouillis
  Bot refuses to count logs. M1racle 0 1,256 Dec-13-2021, 06:42 PM
Last Post: M1racle

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020