Python board game grid [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to make a simple board game for school in python it has to have a grid sort of like a chess board individual spaces where the character can stand. But I have no idea how, we are not allowed to download anything since it's school computers. Also I need to make the character move. I just need this is the most simple form. The example the book gave us looked like this:
..........
..P.......
..........
..T.......
....T.....
..........
..T.......
..........
.........X
P is the player, T is a trap and X is the treasure. I don't need it exactly like that I just need a board like that and how to make the player move on it.

As this question is not very precise the answer can't be as well; but maybe there are some general hints:
-think about how to store the positions of the elements on the boards (lists (-> lines of the game) might be a good start)
-think about what it means to move the figure (taking the list approach this means you can increment or decrement the position in the list or switch to another one)
-think about how you could see that the player has fallen in to a trap/won (check if a position is already acquired before moving the figure)

Related

How to make collisions in tkinter? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am making a python game and I am not exactly sure how to make the enemy's and the player have collisions. Could someone show me a easy way to add collisions to multiple things efficiently. I want the enemy in my python game to collide with the player. Here is the code I use to move the enemy to the player. This code moves the enemy but the enemy does not collide with the player.
if self.canvas.coords(self.man)[0] > self.canvas.coords(Man1.man)[0]:
self.canvas.move(self.man,-1,0)
if self.canvas.coords(self.man)[0] < self.canvas.coords(Man1.man)[0]:
self.canvas.move(self.man,1,0)
if self.canvas.coords(self.man)[1] < self.canvas.coords(Man1.man)[1]:
self.canvas.move(self.man,0,1)
if self.canvas.coords(self.man)[1] > self.canvas.coords(Man1.man)[1]:
self.canvas.move(self.man,0,-1)
You can use the canvas.overlapping() which returns all the items in a given rectangle. Just give it the x,y coordinates of one of your objects and see if the tuple returns more than one.
if you show us some code or give more details we might be able to better help you

Randomly generated dungeon with Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm trying to figure out how to create a completely random maze/dungeon for a small text game I'm working on. I'm really not sure where to start since I've never done anything like this before. How do I do this? I need the rooms to know what mobs it holds, what items are on the ground, where the exits are and what other rooms they go to. Any help is appreciated.
You can make an 2 dimentional int array (your map). Each "object" such as an item or exit gets another number.
for example:
0 = no object
1 = knife
2 = sword
3 = helm
When you need to make it posible to combine objects on one field (for example put an sword and an helm on one field) you can create an 3d array. So you can add an object on top of another object.
You can generate and random x and y whitin your array dimentions and give this an random number within your object scope (in this example between -1 and 4)
Hope this helps ;-)
Since this is a very broad question I will just give you a general answer. You are probably going to want to make a new class that will contain the data for a room. In this class you could have variable that could store randomly generated numbers (using the random module) and then have methods use those numbers to determine the layout, monsters, and items in each room. All you would then have to do is to have a 2D or 3D grid (probably using lists of the room class) and randomly fill the grid with rooms that each contain random data.

Audio visualization [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
So I am attempting to make a little audio player using Pygame. I wanted to add a little audio visualizer similar to in Windows Media Player. I was thinking of starting with an audio wave that scrolls across the screen. But I'm not sure where to start.
Right now I'm just using pygame.mixer to start, stop, and pause the music. I think I would have to use pygame.sndarray and get some samples but I don't know what to do from there. What can I do to turn those samples into a visual audio wave?
Check out the pygame.draw methods.
You can probably take the audio values and map them to one of the draw options - like draw.arc or draw.line. You will have to map the signal output to values that remain within the X and Y max and min of the viewport.
Processing can do the same thing, but is a bit easier to implement if you are interested in learning the scripting language. It has methods specifically for doing the mapping for you and you can do some pretty extreme visuals without a lot of code.

Pygame - How to detect if sprites are in area? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need a way to get a list of all sprites in a certain area of the screen, and I cannot find one anywhere on the internet.
Can someone please give me an example code of how to do this?
If it helps, all the sprites are in an "active" list.
Depends on whether you have obstacles or not, i.e. what the definition of "In the Area" means and also home many sprites you are dealing with.
If there's not many sprites and the distance calc is fast then brute force is probably ok.
for sprite in sprites:
if something.distance(sprite) < THRESHOLD:
do_something_with_near_sprite(sprite)
If you have a lot of sprites have a look at quadtrees and things like that. If calculating the distance is complicated then you're probably going to want to look at A* algorithm. There are libraries for these things so you shouldn't have to implement them yourself unless you want to.
This is a pretty general question (prepare to have it voted down by others :)

How to find if player surrounded enemy's cells [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am making simple game. (A matrix where players can take cells(x,y), only one player on one cell, and they acquire new cells after the player before). Every player has a unique color. I am trying to find out if one player has surrounded cells of other users. In which case all cells are going to change color. Is there any known algorithm for this problem, to check only when user plays a new move ?
I would suggest that you take a look at a flood fill algorithm, these are simple algorithms that searches from a start point and tries to fill the board. You would simply have to check if the fill algorithm can reach the end of the board or not.

Categories