Important alert: (current site time 5/24/2013 5:29:50 AM EDT)
 

VB icon

All out Brawling

Email
Submitted on: 8/1/2012 4:29:37 PM
By: Matthew Booley  
Level: Intermediate
User Rating: Unrated
Compatibility: Microsoft Visual C++
Views: 1029
 
     Don't try multi-player yet
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: All out Brawling
// Description:Don't try multi-player yet
// By: Matthew Booley
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=13811&lngWId=3//for details.//**************************************

[code]// All out brawling.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <time.h>
#include <random>
#include <vector>
using namespace std;
ifstream played;
string multi_name;
void turn_player();
void turn_player2();
int rand1(int random, int limit, int limit2)
{
	srand(time(NULL));
	random = rand() % (limit - limit2 + 1);
	random += limit2;
	return random;
}
bool rand2(float knock_percent)
{
	srand(time(NULL));
	float random = rand() % 100 + 1;
	float percentage = random / 100.0;
	percentage *=100;
	if(percentage <= knock_percent)
	{
		return false;
	}
	else if(percentage > knock_percent)
	{
		return true;
	}
}
class fighter
{
public:
	string name;
	int stamina;
	bool alive;
	bool mark;
	bool turn;
	fighter()
	{
		stamina=0;
		alive=true;
		mark=false;
		turn=false;
	}
}player, player_2;
vector <fighter> players;
int kick(int enemyStamina)
{
	enemyStamina =0;
	int kicker=0;
	int limit = 6;
	int limit2 =4;
	kicker = rand1(kicker, limit, limit2);
	enemyStamina+=kicker;
	return enemyStamina;
}
int punch(int enemyStamina)
{
	enemyStamina = 0;
	int puncher=0;
	int limit=12;
	int limit2= 8;
	puncher = rand1(puncher, limit, limit2);
	enemyStamina+=puncher;
	return enemyStamina;
}
bool knock_out(int enemyStamina)
{
	bool decide;
	decide = rand2(enemyStamina);
	if(decide==true)
	{
		return true;
	}
	else if(decide==false)
	{
		return false;
	}
}
	void player_data()
	{
		cout<<"First you have to name Player 1."<<endl;
		getline(cin, player.name);
		system("cls");
		cout<<"Now for Player 2"<<endl;
		getline(cin, player_2.name);
	}
	void fight()
	{
		system("cls");
		cout<<player.name<<" vs "<<player_2.name<<endl;
		system("pause");
		system("cls");
		cout<<"Commence Fight!"<<endl;
		player.stamina=0;
		player_2.stamina=0;
		player.alive=true;
		player_2.alive=true;
		system("pause");
		system("cls");
		while(true)
		{
			if(player.alive ==true)
			{
				turn_player();
				system("pause");
				system("cls");
			}
			if(player_2.alive==false)
			{
				cout<<"Player 2 died. Player 1 WINS"<<endl;
				break;
			}
			if(player_2.alive ==true)
			{
				turn_player2();
				system("pause");
				system("cls");
			}
			if(player.alive==false)
			{
				cout<<"Player 1 died. Player 2 WINS"<<endl;
				break;
			}
		}
	}
	void turn_player()
	{
		string knock;
		cout<<"It is "<<player.name<<"'s turn!"<<endl;
		system("pause");
		system("cls");
		while(true){
			cout<<"Do you want to kick, punch, or knock out "<<player_2.name<<"?"<<endl;
			cout<<"You can also type in 'stats' to see your stamina, or 'enemy stats'"<<endl;
			getline(cin, knock);
			if(knock=="kick")
			{
				int output_kick;
				output_kick = kick(player_2.stamina);
				player_2.stamina +=output_kick;
				system("cls");
				cout<<"You did "<<output_kick<<" damage, so "<<player_2.name<<"'s stamina is now at "<<player_2.stamina<<"%."<<endl;
				output_kick=0;
				break;
			}
			else if(knock=="punch")
			{
				int output_punch;
				int self;
				output_punch = punch(player_2.stamina);
				player_2.stamina +=output_punch;
				self = kick(player.stamina);
				player.stamina += self;
				system("cls");
				cout<<"You did "<<output_punch<<" damage, so "<<player_2.name<<"'s stamina is now at "<<player_2.stamina<<"%."<<endl;
				cout<<"You also did "<<self<<" damage to yourself, which makes your stamina "<<player.stamina<<"%."<<endl;
				output_punch=0;
				break;
			}
			else if(knock=="knock out" || knock=="knockout")
			{
				player_2.alive = knock_out(player_2.stamina);
				if(player_2.alive==true)
				{
					system("cls");
					cout<<"FAILED!!"<<endl;
				}
				break;
			}
			else if(knock=="stats")
			{
				system("cls");
				cout<<"Your stamina is at "<<player.stamina<<"%"<<endl;
				system("pause");
				system("cls");
			}
			else if(knock=="enemy stats"|| knock=="enemystats")
			{
				system("cls");
				cout<<player_2.name<<"'s stamina is at "<<player_2.stamina<<"%."<<endl;
				system("pause");
				system("cls");
			}
			else
			{
				system("cls");
			}
		}
	}
	void turn_player2()
	{
		string knock;
		cout<<"It is "<<player_2.name<<"'s turn!"<<endl;
		system("pause");
		system("cls");
		while(true){
			cout<<"Do you want to kick, punch, or knock out "<<player.name<<"?"<<endl;
			cout<<"You can also type in 'stats' to see your stamina, or 'enemy stats'"<<endl;
			getline(cin, knock);
			if(knock=="kick")
			{
				int output_kick;
				output_kick = kick(player.stamina);	
				player.stamina +=output_kick;
				system("cls");
				cout<<"You did "<<output_kick<<" damage, so "<<player.name<<"'s stamina is now at "<<player.stamina<<"%."<<endl;
				output_kick=0;
				break;
			}
			else if(knock=="punch")
			{
				int output_punch;
				int self;
				output_punch = punch(player.stamina);
				player.stamina +=output_punch;
				self = kick(player_2.stamina);
				player_2.stamina += self;
				system("cls");
				cout<<"You did "<<output_punch<<" damage, so "<<player.name<<"'s stamina is now at "<<player.stamina<<"%."<<endl;
				cout<<"You also did "<<self<<" damage to yourself, which makes your stamina "<<player_2.stamina<<"%."<<endl;
				output_punch=0;
				break;
			}
			else if(knock=="knock out" || knock=="knockout")
			{
				player.alive = knock_out(player.stamina);
				if(player.alive ==true)
				{
					system("cls");
					cout<<"FAILED!!"<<endl;
				}
				break;
			}
			else if(knock=="stats")
			{
				cout<<"Your stamina is at "<<player_2.stamina<<"%"<<endl;
				system("pause");
				system("cls");
			}
			else if(knock=="enemy stats"|| knock=="enemystats")
			{
				system("cls");
				cout<<player.name<<"'s stamina is at "<<player.stamina<<"."<<endl;
				system("pause");
				system("cls");
			}
			else
			{
				system("cls");
			}
		}
	}
	void one_AI()
	{
	}
	void multi_data()
	{
		int num_players;
		while(true){
		system("cls");
		cout<<"How many people will be playing?"<<endl;
		cin>>num_players;
		if(num_players==1)
		{
			cout<<"You can't choose only 1 player in Multi-Player"<<endl;
			system("pause");
			system("cls");
		}
		else
		{
			break;
		}
		}
		for(int i=0; i<num_players; i++)
		{
			players.push_back(fighter());
		}
		cin.ignore();
		system("cls");
		for(int i=0; i<players.size();i++)
		{
			cout<<"Please enter in the names of the players"<<endl;
			getline(cin, players[i].name);
			system("cls");
		}
	}
	void multi_fight()
	{
		for(int a=0; a<players.size(); a++)
		{
			
			cout<<players[a].name;
			
			if(a<players.size()-1)
			{
				cout<<" vs ";
			}
		}
		system("pause");
		system("cls");
		cout<<"Commence fight!"<<endl;
		system("pause");
		system("cls");
	}
	string who_fight()
	{
		string fighting;
		
		for(int a=0; a<players.size(); a++)
		{
			
		}
		
		while(true)
			{
		cout<<"Who do you want to take action against?"<<endl;
		getline(cin, fighting);
			for(int a=0; a<players.size();a++)
			{
				if(fighting==players[a].name)
				{
					cout<<"bombs. away!"<<endl;
					players[a].mark=true;
					break;
				}
				else if(fighting!=players[a].name)
				{
					cout<<"That isn't anyone's name."<<endl;
				}
			}
			break;
			
		}
		return fighting;
	}
	void multi_turn()
	{
		string target;
		target == who_fight();
		for(int a=0;a<players.size();a++)
		{
			if(players[a].mark==true)
			{
				cout<<"Hi, Mom"<<endl;
			}
			else if(players[a].mark==false)
			{
				cout<<"Skipped!"<<endl;
			}
		}
	}
	void round_1()
	{
		cout<<"I hope you are ready for an ALL OUT BRAWL because this is the first round."<<endl;
		cout<<"Your opponant is Justin"<<endl;
	}
	int start_game()
	{
		system("cls");
		string answer;
		while(true)
		{
			cout<<"It's time for an ALL OUT BRAWL!!"<<endl;
			cout<<"Multi-Player\nTwo Player\nTutorial\nExit\n";
			cout<<"Type in a game mode to play it"<<endl;
			getline(cin, answer);
			
			if(answer=="multi player"|| answer=="multi-player"||answer=="Multi Player"|| answer=="Multi-Player" ||answer=="MULTI PLAYER" ||answer=="multiplayer"||answer=="multi")
			{
				return 0;
			}
			else if(answer=="Two Player"||answer=="two player"||answer=="twoplayer"||answer=="TWO PLAYER"||answer=="two" ||answer=="2 player")
			{
				return 1;
			}
			else if(answer=="Tutorial"||answer=="tutorial"||answer=="TUTORIAL")
			{
				return 2;
			}
			else if(answer=="Exit" || answer=="exit")
			{
				return 3;
			}
			else
			{
				cout<<"Not a valid answer"<<endl;
				system("pause");
				system("cls");
			}
		}
	}
	void tutorial()
	{
		system("cls");
		cout<<"Welcome to the tutorial level!"<<endl;
		cout<<"Oh no, here comes the tutorial monster, Miss Pacman!"<<endl;
		cout<<"If you kick, it does 4-6 damage to Miss Pacman."<<endl<<"If you punch, it does 8-12 damage to her, but 4-6 damage to you!"<<endl;
		system("pause");
		system("cls");
		cout<<"You decide to kick her for 6 damage"<<endl;
		cout<<"This means that her stamina is now at 6%"<<endl;
		cout<<"You can choose to knock out Miss Pacman, but that probably won't work because there is only a 6% of her getting knocked out"<<endl;
		cout<<"There is no maximum stamina"<<endl;
		system("pause");
		system("cls");
		cout<<"*Some fighting later...."<<endl;
		cout<<"Miss Pacman has 75% stamina. This means you have a 75% chance of knocking her out!"<<endl;
		cout<<"You decide to knock her out and..."<<endl;
		system("pause");
		system("cls");
		cout<<"...SUCCESS!! Thank you for playing the tutorail."<<endl;
	}
	int _tmain(int argc, _TCHAR* argv[])
	{	
		while(true)
		{
			int answer = start_game();
			if(answer==1)
			{
				system("cls");
				player_data();
				fight();
				system("pause");
			}
			else if(answer==2)
			{
				system("cls");
				tutorial();
				system("pause");
			}
			else if(answer==3)
			{
				return 0;
			}
			else if(answer==0)
			{
				multi_data();
				multi_fight();
				multi_turn();
				//who_fight();
				system("pause");
				system("cls");
			}
		}
		return 0;
	}
[/code]


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.