Can a java flowchart end with a method rather then a stop?
When my game ends, it calls a method to show the menu again, so I finish the flowchart with a subroutine box that calls the menu method, can this be possible or should a flowchart always end with a stop?
In the menu there is an option to exit the program so it is not an infinite loop.
What I did:
I created a simple hangman game, at first it outputs a menu (has a method of its own).
The menu has 3 options, Play game, Show score, Exit.
If the user plays the game and either loses or wins the game will take him to the menu which will give the user the same 3 options.
In my flowchart of the Play Game method I dont know if I can end the flowchart with calling the method that outputs the menu, rather than a stop function.
Related
I have been trying to make a GUI Blackjack game in C++ with Qt. However, I have hit a road block on my way. I made the game and the game logic last year in pure C++ (link below). I am trying to use the same code to build the GUI version of the game Github/Blackjack.
It's mostly done to the point that I have the cards showing up, adding the values of those cards, the dealer and the player set up.
In the C++ version I made a vector of all the players and added the dealer to the end of it, then using a for loop, I would iterate through the players to get them to play.
In Qt, I have created a widget with two buttons "Hit" and "Stand" for the player control.
"Hit" button is simple and connected the click event of the button with the hit member function of the player.
ctrl = new PlayerControl(nullptr, mainPlayer);
connect(ctrl->ui->hitButton, &QPushButton::clicked, [mainPlayer]{
mainPlayer->hit();
});
Code for iterating through the vector:
for (size_t i = 0; i < players.size(); i++)
{
if (i == playerPos - 1)
{
ctrl->setVisible(true);
//how to make the loop to pause here until the user presses the
//"Stand button", and then proceed with the rest of the loop?
}
else if (i == players.size() - 1)
dealerPlay();
else
computerPlay(players[i]);
}
I'll really appreciate any help. :)
I don't really understand the code you are showing or how it relates to the question in the title of your post. I'll just answer the question, which is:
How to make a for loop until a button is pressed
The answer is that you probably don't want to do that, because that would involve multi-threading or some kind of complicated concurrency mechanism. When you're writing a GUI, the main thread of your application usually sits in a loop waiting for event messages (like clicks and key presses) from the operating system. When it gets such a message, it is supposed to handle them quickly and then go back to waiting for the next message.
In Qt, you can handle these events by overriding functions in your QMainWindow class or by connecting Qt signals to slots.
So, instead of having a loop that iterates through each player and waits for them to make their move, you would have some long-living variables that keep track of the state of the game, and when you detect that a player has made a move (i.e. by clicking a button), you would update those variables, update any data shown on the screen, and then return from your event handler so you can handle the next event.
I am working on a project for my C++ Class and we are doing a poker program with AI and users. Using QT for the development.
What I need to do is inside of the function DECISION() if the player is not an AI, the program pauses until the user hits buttons to either fold, call, or Raise.
Basically I need to pause a program in the middle of executing a function, until the user presses a button. Then it will continue the rest of the function
if(Player[pp].ai == true){
//A bunch of code for AI decision making for folding, calling, raising.
}
else{ //If Player is NOT an AI
ENABLEUSERINPUT(true);
//Need to pause program here until the user has done something to the GUI
ENABLESERINPUT(false);
}
It's possible to wait for a user input using the QEventLoop
for example clicking on the button will exit the event loop.
//Need to pause program here until the user has done something to the GUI
QEventLoop oLoop;
// user click on button will release the event loop.
connect(pYoutrBtn , &QPushButton::clicked,
&oLoop, &QEventLoop::quit);
// wait.
oLoop.exec();
Hi I have a question concerning error-messages.
I have a window with several buttons including a OK and Cancel-button. My OK-button executes a program that moves some chart series and for doing so it needs to read in lots of data from a file and shift these values. The Cancel button cancels this operation. The calculations cannot be separated into smaller portions of code.
This works well for smaller amount of data but when I use it with large sets of data the program acts as if it crashed. Nevertheless, after some time everything is back to normal, the calculation is done.
There are 2 things I don`t like:
1) When I leave the program alone the program changes the headerline of my window to ....(keine Rückmeldung) which means no response.
After the end of the calculation the text ...(keine Rückmeldung) disappears in the header and everything is back to normal.
2) When I try to press the "cancel" button in my window while running the calculation, an additional window appears:
There again, when I leave the program alone and the calculation is finished this window disappears ( as well as the (keine Rückmeldung) in the header of my window) and and everything is back to normal.
To solve problem 2 I tried to disable my "Cancel" button but this does not help. The slot which is behnid the cancel-button gets executed anyway.
My question now is: Since I don´t want the user to see these error-messages, is there a way to prevent the program of showing them?
Thank you
Consider using a QThread for expensive computation tasks. Or better, you can use other built-in multi-threading utilities such as QConcurrentRun and QFuture.
You can then easily get the state of your background function and show a loading Window, or allow the user to perform other operations in the meantime.
I'm making a text-based game. I'm trying to have a little "health bar". When the user hit space, and when the button is pressed it will make health go up by 5, but while this is also happening I need something to be running in the background that is doing the same as if it was a AI, except I want it to subtract 1 every time and for it to only hit it once every second.
I tried getch(); the most but the problem with that is that it stops everything and waits for the user to use a input so nothing can be going on in the background that is subtracting health.
If you could use the _getch(); command in any way to accomplish this, because I already know how to use it well.
I have a stack of images on which I want to perform some operations. After processing each image, my program should pop up a dialog to prompt the user if they want to proceed with the next image or to abort. Before that, they should have an opportunity to do some manual changes either on the images or on the parameters. Anyway, they must have access to the windows of the applications, while the execution of the method that called the dialog should be blocked until the dialog is closed.
I tried to solve this with a QMessageBox, but if I open it via exec(), it blocks the entire application, and if I use show(), the execution of the program goes on without waiting for user's reaction.
Is there a convenient way to block the calling method or function with a dialog but permit the user to interact with other windows?
Thanks in advance for any hint.
You should split your method that you want to block into two parts. In the end of first part you need to show your dialog without blocking and connect "Next" button (for example) of the dialog to the slot that must contains second part of your old method. This slot will be executed only when user presses the button.
It's the right way to do it in Qt. You need posibly to change your code logic to implement this.
Also, do you really need the second dialog? You can place "Next" button to your main widget. You can also create another modal dialog that will contain some settings and "Next" button.