How would I got about doing this?

Started by
14 comments, last by Chad Smith 18 years, 8 months ago
Alright, I am programing my very first game and I have a question on how I would implent this. This game is a Text Based Wrestling Game. I got the main menu working so I want to go straight to the Match system so I can get 2 characters in their and start working on making that better. So, for 2 days straight I was thinking about ideas and everything for a match system and someone here suggested a turnbased idea. Where you type in the move you want to do and everything. Now, here is the problem. I can't figure out how to program it excatly. I know I would use loops and stuff but how would I do the moves and everything? This is going to be a simple game since I am still pretty new at C++. So, could someone please give me an eample on how I could get a quick match system working so I can build on to that? You see, you are going to pick a wrestler(not currenly in the game but going to be when match system gets in their)and then you start the match. You type in the moves and stuff you know. So how coud I go about doing this? All help is appreciated. Thanks, Chad PS:I AM USING C++ IF YOU DIDN'T SEE THAT IN THE POST.
Advertisement
You could use a select case on a couple different keys on the keyboard. Maybe have g for grab, p for punch, and k for kick. When you press p it could go into a function that picks a random number for damage maybe based on how strong the current wrestlers are. Is that what you were looking for?
Here is some generic psuedo-code:

// assuming you have picked your wrestler....char moveNames[4][] = { "figure these out on your own", "yeah", "ok", "you should probably use <cstring> if you know how..." };while( yourWrestlerIsNotDead && theOpponentIsNotDead){cout << "choose your move: " for int i = 0; i < 4; i++{cout << "(" << i << "). " << moveNames << endl; }cin >> move; // note: use something better than cin like cin.get or whatever (i dont do a lot of console so i dont know)switch move:case 1: calculate damage....}// end switch//Do the same for the computer...}


Yeah... any questions (that looks like a bunch of crap that I just posted)
Seems like a fun idea. Perhaps you could implement a character system that has a semi-random strength power. Then, after selecting a move to do to an opponet, the different moves would do damage based on both your strength and the strength of the opponent. simple example:

Strength: 25 points, and you select "flying butt tweezers" which deals damage according to the function of: .0325 * strength + (random number between 1-6).


To make it interesting, other moves could have a higher multiplier of your strength, but a smaller random addition of damage, so like: .0412 * strength + (ramdom number between 1-3).

Maybe this sounds stupid and impossible to implement, after all, it is 12:46a.m. here. But it seems like something that would give the game a little complexity and not too terribly hard to do.
Quote:Original post by Chad Smith
Alright,
I am programing my very first game and I have a question on how I would implent this. This game is a Text Based Wrestling Game. I got the main menu working so I want to go straight to the Match system so I can get 2 characters in their and start working on making that better. So, for 2 days straight I was thinking about ideas and everything for a match system and someone here suggested a turnbased idea. Where you type in the move you want to do and everything. Now, here is the problem. I can't figure out how to program it excatly. I know I would use loops and stuff but how would I do the moves and everything? This is going to be a simple game since I am still pretty new at C++. So, could someone please give me an eample on how I could get a quick match system working so I can build on to that? You see, you are going to pick a wrestler(not currenly in the game but going to be when match system gets in their)and then you start the match. You type in the moves and stuff you know. So how coud I go about doing this?


All help is appreciated.

Thanks,
Chad

PS:I AM USING C++ IF YOU DIDN'T SEE THAT IN THE POST.



I would start looking at RPG battle systems they have formulas they use to compute the damage done by a given attack. It probably wouldn't be hard to come up with your own formulas. I think you're going to have develop a basic stats system for the individual wrestlers, with information about the wrestlers strength, vitality, health, and recovery rate etc. A simple formula for damage might be something like
D = Am * (S/100)-V (not a good formula just an example), were:
D = damage done to the other player which would be subtract from their health
Am = is the attack multiplier
S = is the players strength out of 100
V = is the other players vitality

Maybe if an attack does say 60 points of damage or more the player is stunned for 30 * (R/100), R being the recovery rate, seconds.


I hope this help or at least gives you an idea how you can do it.
Patrick
WEll,
thanks for the ideas. I had a feeling I would have to implent a stats system for the wrestlers.


Also,
could someone show me some more code on how to do it? I am basically a code learner really when I read about getting something to work or w/e. Also, if you could make it kind of simple. lol.

Also,
if you didn't know this game will be for a DOS console so if that helps any.

Thanks,
Chad


Also,
I am hoping to have a beta build out before the end of the month. I have lots of work to do so I can get the stuff implented. So everyone, only really have like 5 days to let me see something with code. lol(not an order. sounds like one though.)

Are you going to have the "match" represented on screen somehow maybe something like:

Ring:
---------------------|                   ||     H             ||                   ||           C       ||                   ||                   ||                   ||                   |---------------------

Commentary:

"Player H as just smashed C's head into the ground"

Where H is the human play and C is the Computer.

If so then you'll need either a 2D array, a 1D array or a std:vector<> to represent the ring. The commentary can just be done based on game state and last move..maybe.

Now the classes well I pesonally might have a abstract Interface class for all display type objects and then 1 derived class for the ring and a 3 classes for the players (1 base, 1 human and 1 computer), giving a class structure somethign like:
                      ------------                      | IDisplay |                      ------------                       |       |                 -------       --------                 |                    |            ----------           -----------            |  Ring  |           | BPlayer |            ----------           -----------                                                           |                            ---------------------                            |                   |                        ----------         ------------                        |  Human |         | Computer |                        ----------         ------------  


Using something like the above would give you the ability to "plug-in" new display object types later on if needed.

The Classes might look something like
class IDisplay{    public:        /* All virtual function need to  */        /* have an are derived virtual   */        /* and need to have an         /* implementation in ALL derived */        /* Classes                       */        virtual void update()=0;        virtual void draw()=0;        /* Other pure virtual functions  */        };Class Ring : public IDisplay{   public:     Ring()     ~Ring();     void update(BasePlayer* currPlayer); /* derived as virtual - implementation MUST be given */     void draw(); /* as above */     /* Another derived virtuals - implmentations MUST be provided */     void displayCommentary();     /* Copy constructor - should be included if using heap */     /* Otherwise compiler will provide one if required - and */     /* migth not be the best idea to use e compiler generated one */     Ring(Ring&){} /* if the ring doesn't want to be copied make                      the copy constructor private so if someone tries to                      it will be caught at compile time. Also providing                       this means that the compiler won't generate it's own */     Ring& operator=(Ring& rhs) /* Same as above but for assignment */     {        if (&rhs == this)            return *this;        /* do all member vars : var1 = rhs.var1 etc... */        /* a blank implementation is all that is really needed           cause the overloaded assignment operater is private           so can never be called from outside the class - just           included if you were wonderign what it might look like */     }   private:          char* XDELIM = '-'; /* Use to define boundaries of ring */     char* YDELIM = '|'; /* Use to define boundaries of ring */     char* thisRing[MAXWIDTH][MAXHEIGHT];};


Now the Player classes might look something like:
class BasePlayer : public IDisplay{    protected:      /* Vars for All BasePlayer & Derived classes */      /* player state stuff */      enum playerState{OK, HIT, JUMPING, ....other states};      enum healthState(HARD,FINE,NOTBAD,SORE,HURT,VERYBAD,...etc);      playerState m_currState;      bool isCurrPlayer;    public:      BasePlayer();      virtual ~BasePlayer(); /* provide implementaion as it will be called from                                 derived classes, will not compile is missed                                 - even                                 BasePlayer::~BasePlayer(){} will do */          /* copy and assignment constructor and overloaded function if needed     */     /* As this is turned based possibly not as we can utilise shallow        */     /* pointer to class copying in game (usually try to avoid shallow copys) */     bool update(Ring* aRing); /* Implementation MUST be provided - even a blank one as                        with the destructor above */     void draw();   /* as above */     playerState m_getState(){return currState;}     void m_setState(playerState aState){m_currState = aState;}     void m_setHealth(int aDamagePoints){/* Set state accroding to current state + aDamagePoints*/}     /* Positional stuff */      typedef       struct Position      {        int x;        int y;      } position;     int m_getX(){return m_Position.x;}     int m_getY(){return m_position.y;}     struct Position& m_GetPos(){return m_Position;}     void m_setX(int aX){m_Position.x = aX;}     void m_setY(int aY){m_Position.y = aY;}     void m_setPos(struct position& aPos)     {        m_Position.x = aPos.x;        m_Position.y = aPos.y;     }     bool m_isCurrPlayer(){return isCurrPlayer == true;}     void m_setCurrPlayer(bool playFlag){isCurrPlayer = playFlag;}   protected: /* NOT private as derived classes will use it */     position m_Position;          /* BasePlayer player private vars */}/* Human and Computer inherit all the state and positional stuff */class Human : public BasePlayer{   public:     Human();     ~Human();     bool update(Ring* aRing); /* Inherited virtual */     void draw();   /* as above */}class Computer : public BasePlayer{   public:     Computer();     ~Computer();     bool void update(Ring* aRing, Human* aHuman); /* Inherited virtual */     void draw();        /* as above */}


Right so now you have your basic structures. The draw functions (in the the Player classes) will simply update the array/vector of the Ring Class's thisRing array with the players current position (so passing the thisRing array into these might be an option).

The displayCommentary Ring class could display texted based on the current state of the current player class or game OR ring - depends how you would like to implement that.

The update function in the Ring class will call the draw function, along with some other bits and pieces I'm sure that you'd like to include.

The update functions within the player classes will be significantly different to one another. Both will need to calculate the damage caused by the last move of the opponent and set health state according to this. The interesting bit will be the AI. The Human update function will check the current state of the player...and end the match if his health is too low...otherwise it'll just take input from the user (maybe look at conio for this - can give you examples if you like?) and set the state of the player accordingly, setting positional values as well.

The Computer update function will be some AI the takes into account his own healh, the human players health and state and pick his next move accordingly, setting x and y positions as well.

So in order to implement this in you loop you could do something like:

notEnd = false;/* These will actually be set dependant on what the user   chooses at the menu...but lets keep it simple */Player* Player1 = new Human();Player1->m_SetCurrPlayer = true;Player* Player2 = new Computer();Player* currPlayer = Player1;Ring* aRing = new Ring();/* as console game not concerned with frame rates */while(notEnd){   currPlayer->Update(aRing);   notEnd = aRing->update(currPlayer);   /* Other stuff.....*/   /* Change players */   if (Player1.m_isCurrPlayer())   {      Player1.m_SetCurrPlayer(false);      Player1.m_SetCurrPlayer(true);      currPlayer = Player2;   }   else   {      Player2.m_SetCurrPlayer(false);      Player2.m_SetCurrPlayer(true);      currPlayer = Player1;   }}delete Player1;delete Player2;delete aRing;/* Nothing dangling */Player1=0;Player2=0;aRing=0


WOW - just realised how much I've typed. Didn't mean to design your game..Ooops Sorry. There is still alot missing and I'm sorry if this reply is a bit vague in places and I think I've not shown complete function declarations in some of the classes, am typing as I'm getting ready for work, but am sure you can work out what I'm getting at.

As an aside. You could have a BaseDisplayClass that inherits directly from the abstract interface and is the base for all the other display classes. That way you could have a std::vector<BaseDiaplayClass*> and use it inside the game loop. Just need to run thru it calling the update functions of the classes...(*it)->update(). BTW...the stuff above is a VERY rough sketch...it WONT compile...is just for ideas..:)

Anyhow Hope some of this helped. If you're new to C++ then some of the concepts (Abstract interfaces etc) might give you something to investigate.

Good luck...am looking forward to playing your game when it's finished..:)

[Edited by - garyfletcher on July 21, 2005 7:31:46 AM]
Gary.Goodbye, and thanks for all the fish.
Quote:Original post by CoderGuy
You could use a select case on a couple different keys on the keyboard. Maybe have g for grab, p for punch, and k for kick. When you press p it could go into a function that picks a random number for damage maybe based on how strong the current wrestlers are. Is that what you were looking for?



Alright,
I was looking through all of them and since I do want to keep this simple and not get it where I run away from Game Development forever I am really thinking about this guys idea.

I could do it where when you choose "g" for grab or grappel then it says "Please type in a move." That means I would have to check to see if they typed in that type of move. So they don't say like Leg Drop from a punch.



I think I see how I could get that in their, but maybe could someone give me a little example on how that could look and work in code? Thanks!


Also,
I am don't know how to do seperate header files yet(or w/e they are called)so I am sorry that is not an option,

Chad.


Okay.

This is some menu type stuff I did for a console TTT a while ago.

I've removed any #include's

enum playMode {DEMO,HVC,HVH,INST,QUIT,NONE};int menu();void instructions();int main(int argc, char *argv[]){	int mode = 0;		while (mode != QUIT)	{		mode = menu();				switch (mode)		{			case QUIT:			{					char quitYN = ' ';									while(quitYN != 'Y' && quitYN != 'y' && quitYN != 'N' && quitYN != 'n')				{					cout << "\t\tAre you sure? (Y/N): ";					cin >> quitYN;				}									if (quitYN == 'N' || quitYN == 'n')				{					mode = NONE;									}					}					break;			case INST:								instructions();									break;				default:			{				GameEngine *Game = new GameEngine(mode);								Game->Play();								delete Game;				Game=0;			}			break;		}			}	    return EXIT_SUCCESS;}int menu(){	int mode = 0;		CLRSCRN		cout << "\n\t\tMAIN MENU\n";	cout << "\t\t==========\n";	cout << "\n\t1. DEMO - Computer Versus Computer\n";	cout << "\t2. HVC - Human Versus Computer\n";	cout << "\t3. HVH - Human Versus Human\n";	cout << "\t4. Instructions\n";	cout << "\t5. Quit\n";		while (mode < DEMO+1 || mode > QUIT+1)	{		cout << "\n\t\tChoose from option 1-5: ";		cin >> mode;	}		return mode-1;}void instructions(){	cout << "\n\tWelcome to TIC_TAC_TOE\n";	cout << "\n\tMake your move known by entering 1 - 9. The number\n";	cout << "\tcorresponds to the desired board position, as illustrated:\n\n";		cout << "\t1|2|3\n";	cout << "\t-----\n";	cout << "\t4|5|6\n";	cout << "\t-----\n";	cout << "\t7|8|9\n";		cout << "\n\tYou can choose several ways to play from the MAIN MENU or watch a demo\n";	cout << "\tHave a nice game\n";	return;	}


When I did a console tetris I used kbhit(), <conio.h>, to test for the keyboard interrupts and then got the input with ch = getch() as that way you don't have a cursor flashing and it doesn't break up the output.

This is what I did when the game was paused:
#include <conio.h>while (paused){   char key;   if (!kbhit())   {       key = tolower(getch());						      if (key == 'p')      {          paused = false;      }					   }}


If you want a switch statement for the above:
#include <conio.h>while(paused){  char key;    if (!kbhit())  {      switch(key)      {         case 'p':         {            paused = false;         }         break;        default:        {           paused = true;        }        break;      }  }}


You would have multiple case(s) to test for each of the possible moves available and call the appropriate function.

Hope that helps..:)

[Edited by - garyfletcher on July 21, 2005 2:16:33 PM]
Gary.Goodbye, and thanks for all the fish.
MM,
I think I see. But I am not really sure again. lol. Umm, I think I could get a simple one made.

Now, I understand the code but how would I put that in my source code I have right now?

Here is the source code:
<code>
//My First Game!
//A Text Based Wrestling Game called Wrestlewars!

#include <iostream>

using namespace std;

void Exit_Game(bool &done)
{
int exit_game;
bool done2=false; //for escaping the loop below

while(!done2)
{
system("cls");
cout<<"Are you sure you want to exit Wrestlewars?"<<endl;
cout<<"1.Yes"<<endl;
cout<<"2.No"<<endl;
cin>> exit_game;
if(exit_game == 1)
{
system("cls");
done=true;
done2=true;
}
if(exit_game == 2)
{
done2=false;
done=false; //Un-needed, but clarify things
system("cls");
}
}
}

void Play_Game()
{
cout<<"Alright! You are going to play my first game!"<<endl;
}

void View_Credits()
{
int credit_exit;
bool done=false; //not releated to the one in main

while(!done)
{
cout<<"Designer:Chad Smith"<<endl;
cout<<"Programer:Chad Smith"<<endl;
cout<<"To go back to the Main Menu, then just press 1"<<endl;
cin>>credit_exit;
if(credit_exit == 1)
{
system("cls");
done=true;
}
}
}

int main()

{
//start of game
cout<<"Wrestlewars!"<<endl;
cout<<"A Text Based Wrestling Game!"<<endl;
//Start a loop where they choose favorite show
//this is a do..while loop
int show_pick;
bool done=false;

do {
cout<<"Which is you favorite Show?"<<endl;
cout<<"1.Raw"<<endl;
cout<<"2.Smackdown"<<endl;
cout<<"Press one for Raw and 2 for Smackdown"<<endl;
cin>> show_pick;
if(show_pick == 1) {

cout<<"Yes, Raw Rocks!"<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<"Press Enter to go to the Main Menu"<<endl;
done=true;
}
if(show_pick == 2)
{
cout<<"I really don't like Smackdown That much, but who cares."<<endl;
done=true;
}
} while(!done);
system("pause");
system("cls");

//The Main Menu
done = false;
int main_menu_choice;

do {
cout<<"What do You want to do"<<endl;
cout<<"1.Play Game"<<endl;
cout<<"2.View Credits"<<endl;
cout<<"3.Exit"<<endl;
//below is a switch case
cin>>main_menu_choice;
switch(main_menu_choice)
{
case 1:
Play_Game();
done=true;
break;
case 2:
View_Credits();
break;
case 3:
Exit_Game(done);
break;
default: {
system("cls");

}
}
}
while (!done);

return EXIT_SUCCESS;
</code>

Now, I know the code design is bad but that should be fixed later on. Where would I put that? I am asking this because I want to make sure I do some stuff correctly and I don't don't take the long way around by doing lots and lots and lots of if's. lol.

Couldn't I do a switch case to get the weather that want to do a "g, p, k, f"(teh f means fly. Like fly off top rope.) Sorry to ask some many questions


}

This topic is closed to new replies.

Advertisement