News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Algorithm for returning a turn.  (Read 3209 times)

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Algorithm for returning a turn.
« on: December 12, 2012, 05:37:28 pm »
So I made this algorithm for graphical reason. So I made this game and it uses a while loop and cin to stop execution until something is put in but that's not going to go well with graphical programming. You can't wait for input in graphical programming unless you use those cheesey input methods. Like inputbox() if you know what I mean. So with this algorithm, theres this function that returns what the index number is for the struct array. This can be handy for making turn based RPG in the graphics world.

Here's my code:
Code: [Select]
#include <iostream>
#include <string>
using namespace std;
struct player {
string name;
int agi; // agi - agility
int ct;
};
int findturn(struct player *players) {
while(true) {
for(int i = 0; i < 3; i++) {
if(players[i].ct >= 100) {
players[i].ct = 0;
return i;
}
players[i].ct += players[i].agi;
}
}
}
int turn;
main() {
player players[3];
players[0].name = "Edge";
players[0].agi = 3;
players[1].name = "King";
players[1].agi = 3;
players[2].name = "Jake";
players[2].agi = 3;
for(int i = 0; i < 3; i++) players[i].ct = 0;
turn = findturn(players);
cout << "The first turn is: " << players[turn].name << endl;
turn = findturn(players);
cout << "The second turn is: " << players[turn].name << endl;
}

So every time you call findturn(players) it will return what index number is. That way you don't need a while loop making the execution go crazy.

KC

  • Full Member
  • ***
  • Posts: 209
    • View Profile
Re: Algorithm for returning a turn.
« Reply #1 on: December 12, 2012, 06:07:27 pm »
While it's good that you enjoy programming... You have to realize that the problems you solve are very simple and not suitable for "real" application or games, which should involve a lot more abstraction, and pretty much anyone can come up with that while loop on their own.
If you are serious about writing a game, you should spend more time on studying programming basics instead of posting a new version of your extremely simple command line game every other week. You still have a lot to learn. That also involves having properly formatted code and using comments where necessary and appropriate.

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: Algorithm for returning a turn.
« Reply #2 on: December 12, 2012, 08:20:33 pm »
You are right in just about every way. However, me and my friend are going to work on a big project on teamviewer. Like me and him will work on it through remote desktop. Its gonna be a pain to type stuff but I suppose it can worse. I already have the foundation of it set up so hes just going to expand it with his ideas with the aid of my help. He's a beginner programmer and I want to help him since I have much more experience. My games were text based which has no touch to it so I'm going to make a graphical one with him with shops and places to explore!

Pyriel

  • Jr. Member
  • **
  • Posts: 23
    • View Profile
Re: Algorithm for returning a turn.
« Reply #3 on: December 12, 2012, 11:06:38 pm »
I think what you're ignoring is that your snippets are exceedingly simple, and not interesting or novel to anybody who comments regularly here.  I don't mean that to be an insult, it's just that I don't understand why you keep posting them.  Unless you have a question, they're not worth discussing.  If you had declared player MyPlayer and then attempted to set the agi property by MyPlayer->agi and wondered why it wouldn't compile, there might be some value to this thread.

You keep comparing yourself to some less experienced friend too, which is kind of weird.  He can't be more than a few months behind you, unless you have an extensive background in Easytrieve or something.

Pikachumanson

  • Hero Member
  • *****
  • Posts: 607
    • View Profile
Re: Algorithm for returning a turn.
« Reply #4 on: December 13, 2012, 12:30:57 am »
Pissing contest maybe?

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: Algorithm for returning a turn.
« Reply #5 on: December 13, 2012, 03:37:33 pm »
I've been programming since I was 14. Now I'm 17. I just don't feel like putting tons of effort into a game alone.

Garoth Moulinoski

  • Hero Member
  • *****
  • Posts: 6290
  • Disliking that smoke.
    • View Profile
    • My Stuff including Super Smash Karts.
Re: Algorithm for returning a turn.
« Reply #6 on: December 13, 2012, 03:46:28 pm »
Something that's been ignored:
instead of posting a new version of your extremely simple command line game every other week.

These little snippets seem like they should all just go together into the same thread. I keep looking in thinking it's about something different and then I'm like "wait... isn't this the same stuff that kid was talking about?"

Just change the name of one of your threads to "InfamousKnight talks about making an RPG" and leave your thoughts on that thread.

I mean, I do like having my memory jogged, since I barely remember C and I only wrote one program in C++, using only my C knowledge and a whole lot of google.
Who will quote me next?
Disclaimer: If it sounds wrong, I may have been posting while asleep.

Kiyoshi Aman

  • RHDN Patreon Supporter!
  • Hero Member
  • *****
  • Posts: 2262
  • Browncoat Captain
    • View Profile
    • Aerdan's Blog
Re: Algorithm for returning a turn.
« Reply #7 on: December 13, 2012, 06:10:05 pm »
Speaking as someone who's been programming off and on for over a decade...

Just write the damn game.

If you have specific questions about problems you're trying to solve, we'd be happy to answer them, but this "post a snippet to elicit opinions" shit is dumb.