I have a question about my battle system hp code [closed] - c++

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 3 years ago.
Improve this question
i've been coding a text based RPG pokemon battle and im trying to make a damage count of the wild pokemon. but i'm slightly stuck. i have the link to the running program so you can see what i mean.
https://repl.it/live/Ig6yy9UVHyxScw
ive tried using if the total hp of the wild pokemon is less than 90 but it still shows the first attacks damage. (damage = 20). i have the code i'm stuck on here.
if (pokemonSelect == 1 == move == 1) {//for charmander
wPhPtotal = wPhP;
wPhPtotal = wPhP - wPdamage;
}
cout<<"wild pokemon hp lost:" << red<<" "<<wPdamage<<" "<<def<< "hp:"<<green<<wPhPtotal<<endl;
NOTE: only use charmander and ember as i havent programmed the other moves yet.
is there A way to count it all up?

There's not enough information to really answer your question, but here's some stuff that might point you in the right direction.
Firstly, you can't chain ==, as you may be able to in other languages.
if (pokemonSelect == 1 == move == 1)
Should be
if (pokemonSelect == 1 && move == 1)
As a side note, you can write it the way you have it in this particular instance. However, that's mostly due to luck, and it won't work for any values
other than 1. This is because x == y returns 1 if true and 0 if false. So, for any value other than 1 in that conditional, it'll break.
Second,
wPhPtotal = wPhP;
wPhPtotal = wPhP - wPdamage;
Is redundant, since the second line will overwrite the first.

Related

How to display asterisks (***) [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 2 years ago.
Improve this question
I am trying to create an ATM application using c++ and I want to display asterisks (****) when I input the pin code. I haven't tried anything because I have no idea on how to do it.
Could someone help me?
A very small program which should help you get started for Windows would go like this:
int main(void)
{
char character = 0;
while (true)
{
character = _getch();
if (character == 13) //Enter
break;
else
{
putc('*');
//Do whatever
}
}
}
Please note that this code is off the top of my head and still requires the correct includes, but should point you in the right direction.
Please refer to https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/getch-getwch?view=msvc-160 for the documentation of _getch and http://www.asciitable.com/ for a list of control codes you might be getting.

Is it possible to create "quick time events" in C++? [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 4 years ago.
Improve this question
I have some knowledge about C++, but I stumbled upon an problem. I want the user to enter some text, but when it takes longer than X seconds, the program will go on. I guess, it is not possible, but maybe you know something about it.
It will be in the command line, without GUI.
I am not certain how the programm will look like, but it will be something like a CMD-RPG. I wanted to use Quick Time Events to make it a little bit more exciting.
I cant comment so I will just leave this here
Input with a timeout in C++
Since I cannot comment, I will simply leave this as an answer.
One possible way to solve this problem is to have 2 threads:
Input capture thread: since receiving input is a thread-blocking action, you should have a thread that simply polls for user input, placing that input into a thread-safe buffer
Quick-time function on main thread: a function that will be responsible for executing the quick-time event. Something like the following could be done (pseudo code):
clear input buffer //the buffer provided by the input capture thread
bool success = false;
while(current time < ending time)
{
if(input buffer isn't empty)
{
get contents of input buffer and send contents to cout
if (user has finished input correctly)
{
success = true;
break;
}
clear buffer
}
}
return success;
For this to work, you would need to turn off echo on the command prompt (see this page for more info)
Although Diogo's reference is excellent (and informative), I believe this answer is more applicable than since the OP has indicated that this program will be ran on Windows.

Arduino double command [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I'm trying to find a way for my Arduino to recognize some of the commands I'm attempting to send over serial (via Raspberry Pi)
I'm come as far as to detect 2 commands, but I'm stuck at my last.
To give a little bit more detail, I have my fingerprint scanner (GT-511C3) connected, and the library installed that will make it work.
That said, with the first 2 commands consist the verifying of fingerprints to ID (which works great) and the enrolling of fingerprints to new ID's (also work great) these parts of the script are triggered by the respective ASCII code "0" and "1".
My last, and problematic command "2" to remove an ID, is where I'm seeking help with.
Here's the code I'm currently working with:
if(ser == '2'){
while(val2 == 0){
char val3 = 0;
delay(10);
Serial.println("Type the ID to be deleted");
delay(2500);
fps.DeleteID(Serial.read());
val3 == Serial.read();
delay(10);
Serial.println("Deleted ID:");
Serial.print(val3);
delay(10);
val2 = 1;
}
}
I'm attempting to send the ASCII code "2" over Raspberry Pi through serial to the Arduino, followed by the ID that needs to be removed. It triggers after the command "2" is send, but refuses to read the ID and as such, I'm unable to finish it.
Any help or insight would really be appreciated.
val3 == Serial.read(); should be val3 = Serial.read();. You have an extra = which turns it into a useless comparison.

Solve maze recursively using c++, cannot handle an exceptional case [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am using an algorithm that I found online to solve a maze.
FIND-PATH(x, y)
if (x,y outside maze) return false
if (x,y is goal) return true
if (x,y not open) return false
mark x,y as part of solution path
if (FIND-PATH(North of x,y) == true) return true
if (FIND-PATH(East of x,y) == true) return true
if (FIND-PATH(South of x,y) == true) return true
if (FIND-PATH(West of x,y) == true) return true
unmark x,y as part of solution path
return false
The algorithm works good on most mazes. But it cannot handle an exception:
######
#s. #
#.## #
#.####
#...f#
######
As shown in the picture, # is a wall, empty space is available path, s is the start and f is the finish.
And the '.' dotted line is the solution path marked after running the maze solving program.
In this case, the start point blocks the path into two way, and after running the program, there is one extra dot at the right side of the start point which cannot be unmarked.
I am wondering could anyone point out that why this happens to the above algorithm. And what extra check should I add to the solve() function? Thank you!
Probably the problem is occurring because you are revisiting already visited node.
Consider you are at the extra dot you are considering at beginning of function. Now on your west side you might have missed checking if it is a start point, and considering start point as not outside maze and available path. So now the program again starts checking from start and thus giving false positive result.
Without actual code its hard to debug though.
EDIT: It suffers from exact problem is was talking about above
Do you know where start point is. If so do following
Replace
if (ch =='.' || ch == '#')
return false;
with
if (ch =='.' || ch == '#' || ch=='s')
return false;

Ncurses: movement [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have a problem with programming movement using C++ and Ncurses.
I'm programming a pacman and the main problem is, that I just want last pressed key in time period.
When I use usleep, it saves every key pressed during sleeping and then it's working with that in the order.
Thanks for ideas.
What did you try?
Something like this should work, if I understood correctly what you try to achieve:
int t = your_delay;
while (t --> 0)
{
sleep(1);
c = getch();
}
If you really need to time it down to the microsecond, this might not be the best approach, but if you can have some tolerance, this should be enough.
Are you in no-delay mode? If so, this might work:
usleep(your_delay);
last_key = ERR;
while ( (key=getch()) != ERR ) {
last_key = key;
}
// "last_key" now holds most recent key, if there was one, else ERR