I got a problem right now. I need to create a starting player menu with the options on how many players and giving those players a color. Also whenever a player has a color, the color will get deleted from a list.
Can any1 help me :(
You can treat menu almost as separated game - with own mainloop, own functions and classes - but in the same file with rest of code.
And use pygame.init(), pygame.display.set_mode() only once - when you init game.
Latter you can find better solution (but more complicated) with only one mainloop - Finite-State Machine "FSM"
Related
Im new to using asciimatics, and im playing around with it to make a game. However, when i add a cross_hairs to a scene, it wont move to the next scene. How can i move to the next scene when i have cross_hairs?
Assuming you are using something very similar to this sample, asciimatics is playing a Scene with 2 or more Sprites.
If so, this sample already allows you to move to the next Scene by pressing space. Job done! :-)
In a little more detail... It relies on the default global key handler to do this. As covered here, it just raises the NextScene exception to tell asciimatics to move on.
If you want to move to a new Scene based off a different event (e.g. the cross hairs hitting another Sprite), you should just raise that Exception at the time you detect the condition.
Firstly, there are a couple of similar questions posted on this. But they are not complete questions, and no one has really answered them all. I am using Python to send input to a game active in widow modes using "ctypes" package. The original idea is mentioned here
In particular, my codes are:
x=500
y=400
for i in range(10):
time.sleep(4)
if i > 0:
x=x+17
pos=(x,y)
#ctypes.windll.user32.SetCursorPos(x,y) # this does not work in game but
#outside the game window
ctypes.windll.user32.mouse_event(0,x,y,0,0)
print i
In order for the "mouse_event" to work, I tried inputting hexadecimal values but can't get it to move consistently. I tried setting up separate class & functions to import, then calling the function. The function works outside the game window but not inside the game window.
The separate class & functions are based on this question
Thank you for your help in advance.
I am developing a small game with four members for a board. When a player moves something, that move has to updated in remaining players screen(their webpage). I ended up tornado, but I can't find any examples for my case.
I need to display the move to all players when a move was saved in DB. Polling DB continuously after x seconds may miss some moves. How can I achieve this.
Use websockets instead. Here's the documentation with a simple example.
I am making a kind of puzzle game and it's been suggested that I use Pygame. I have looked at some tutorials but I am unable to get certain things to show.
Number of moves - I'm basically looking for something that will count how many times the numbers 1 - 6 are pressed.
Timer - I'd like this to start when someone presses a key and stop after a condition has been fulfilled.
Win / fail screen - I'm looking to have something pop up saying the user has won or failed depending on if certain criteria have been met.
Any help on getting these displayed would be greatly appreciated.
Firstly get familiar with pygame font module : http://www.pygame.org/docs/ref/font.html
You will need a way to display string and numbers to the user. Simply make a font object, and render surfaces with the strings, to later blit them like any other bitmap you had.
Also i suggest to look into the time module: the pygame docs are really helpful : http://www.pygame.org/docs/ref/time.html. Here you will use this module to create a small class Timer, with a Clock object to stop and reset, and update functions. In the update functions, you can add the delta(the difference between the last and recent call of tick()) to the overall time or simply depend on the functions given in the time module. You can call stop when a condition is satisfied.
Last, for the screen, you may want to divide your game/app into states, where the game state is only rendered and looped when a play flag == true. When the game is over, you can switch the state to win/lose state to display the information and probably a prompt if the player may want to play again.
I've created a simple console based Scrabble game using Python. I tried to encapsulate the game model from the I/O as much as possible, meaning I created a few classes to describe the game with its rules and the current state. Basically I came up with these classes:
LetterSet: To describe the tiles in the game (score, total amount, etc.)
Board: A representation of the Board with its tiles and auxiliry functions
Player: A virtual class to subclass real Classes like Human or Bot, got one method play() which should return the players move
Game: Well ...
Everything works fine using a simple linear and synchronous flow with my console app.
But it turns out that its not that easy to port this concept to Qt. I've created all neccessary widgets like a Dragable board, general visual elements describing the game state and simple buttons like 'Pass', 'Continue', 'Exchange'.
The problem is, that I'm not sure how to handle the play() method which may use the Qt interface I created to generate a valid move. That's no problem for the Bot though, which simply searches a move without any interaction.
My current idea is to create a local event loop like described here and to wait for the buttons to get clicked in my play() method defined in Human(Bot). This is kinda ugly so I'm wondering if there is a better way to do it.
I would like the main logic to be the same e.g. the Player class serves a play() method which generates a move and returns it. This way it should be possible to create any type of Player's, like network players or bots. This synchronous way of doing it doesn't work very well with Qt's based signal/slot way of doing things. Hope someone got a neat idea to solve my problem.
Summarized: How to generate the Player's move inside its play() method and returning it like a simple move = player.play(game) call?
Edit: A snapshot to get an idea of what I'm talking about:
(source: b52 at reaktor42.de)
Edit2: This is rather old and I completed the assignment about two years ago successfully. Nevertheless I thought it might be useful for others if I publish the results through github.
Thanks in advance, Oli
What you can do in the Player play function is:
Enabled the buttons and connect them to slots (one per action)
Wait until the player move is validate (or any other reason to quit)
Disconnect signals to slot when the player move has been received (or is validated)
This is one way but you should modify it to fit your game model
My current idea is to create a local event loop like described here and to wait for the buttons to get clicked in my play() method defined in Human(Bot). This is kinda ugly so I'm wondering if there is a better way to do it.
I don't see why you think this is ugly. This is how practically any GUI program works: initialise a set of controls (buttons, etc), wait for the user to interact with the controls, respond to the interaction, and repeat.
I'd recommend you have a button for the player to submit their move. They click that, an event fires, the event handler tells your Player object that a move has been made and it passes it to the game logic event handler. The game logic checks whether the move is legal (you should put the code here rather than in the GUI classes), and passes control to the next Player object if the move was legal.
I think you're right that there's a bit of a disconnect between the event based model in a GUI environment and your original application design. With a console app you write the event loop, but in a GUI app in any of the frameworks I know, the framework has one of it's own.
I'd have the Player object send it's move via a signal to the game object. You would need to structure your base Player class around this design. It shouldn't all that hard to do as you've already got the actual logic worked out, you're just re-wiring it a bit.
Note that your Player objects are actually just interfaces between the game and the actual player which might be someone clicking buttons in the UI, or a remote player over a network connection. Only in the case of a bot can the player object actually be the player, and even in that case you might be best off having separate strategy engine objects. Thinking about it that way might help get a grip on the design.
You don't have to do it that way. You can work around it e.g. by the method you describe, but I wouldn't want to mess around with my own event loops inside an application that has it's own GUI event loop. That's fighting against the GUI framework rather than working with it. It's not just Qt that's like this, you'd have an issue similar to this in any GUI framework. It's a different way to think about structuring an application and I'd recommend embracing it.