🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

c++ how to have the cpu keep choosing a play from a menu

Started by
2 comments, last by Zakwayda 5 years, 7 months ago

I am trying to write a function for the CPU to keep calling a play in a do while loop (which I am assuming is correct) with a pause in between and for the menu to be brought up to the user after each selection from the playbook function that contains the playbook menu. I am not an expert with the cin operator, but my playbook function works perfectly when the user is entering the plays but the cursor hangs when it is calling the function_cpu for the cpu to make the selection. I am sure I am missing something in the code here. I put some notes in the code below.

 

image.thumb.png.6781ce2abd0060a6b4325f16a1f307d1.png

Advertisement

Look at the while condition to keep it in the loop.

It says the condition is that player must still be the second one and down must be less than four.

But inside the loop you never change any of these variables so the loop never ends.

If the second player must just make one movement then you need to change to control to one before the loop ends.

If down means how much times the second player moves then you must change as well.

I'll mention a couple other things in addition to the above post.

- You might double-check the documentation for srand(), as you seem to be misusing it here.

- Maybe you're modifying all those arguments for the benefit of the caller somewhere, but keep in mind that if that's not the case, they don't need to be non-constant references (or references at all).

- In the 'while' conditional, you have an assignment ('player_control = 2') rather than a comparison.

- The return statement probably isn't doing what you expect (look into the C++ comma operator for info on that).

Also, for what it's worth it might be a little easier to comment if you just include the code directly into your post rather than via image (that way readers can easily search it, copy-and-paste, and so on).

This topic is closed to new replies.

Advertisement