Finished games

Started by
3 comments, last by pulpfist 17 years, 9 months ago
I was wondering if ppl could post any games they have made. If possible could you post the code so others can try too. also i have 1 i would like to post but i need to know how to enclose my code and not have to scroll a long way. (I think you know what i mean) thx
##########################################################You'll have time to rest when you're dead - Robert De Niro
Advertisement
If you want to post your code on these forums, post in between source tags:
[ source]
[ /source]
(Without the leading spaces.)

If you're looking for game samples, I suggest you try your friend [google].

Edit: See also, Oluseyi's post.
Quote:Original post by bxela1
I was wondering if ppl could post any games they have made.

Game Development Showcase

Quote:also i have 1 i would like to post but i need to know how to enclose my code and not have to scroll a long way.
(I think you know what i mean)

Site FAQ: Tags
#include <iostream>#include <string>#include <ctime>using namespace std;void battleOut();void battleIn();int neededEXP;int HP;int opHP;int HPFULL;int lvl;string Jore;int EXP;int opLvl;int main(){	srand(time(NULL));	int choice;	bool quit = false;	char cont;	string name;	bool contin = false;	while (contin==false)	{	    		cout << "Welcome to the world of Sanemo!!!" << endl;		cout << "What is your name?: ";		cin >> name;		cout << "In Sanemo roams creatures known as Jore" << endl;	    cout << "They are used for many things, but most commonly for Journeying" << endl;	    cout << "There are many towns in Sanemo, with many people" << endl;	    cout << "Your hometown is Zeeki" << endl;	    cout << "Well lets get started then!" << endl;		cout << "Would you like to continue? (Y/N): ";		cin >> cont;		if (cont=='Y') contin = true;	}	cout << "***********************************" << endl;	cout << "???:AHHHHHHHHHH!!! SOMEONE HELP ME!!!!" << endl;	cout << "???:ANYONE!!!!!!" << endl;	cout << "***********************************" << endl;	cout << "ACTION:YOU RUSH TO HELP" << endl;	cout << "***********************************" << endl;	cout << "" << name << ":What's wrong???" << endl;	cout << "???:I'm caught in a ditch!!!" << endl;	cout << "***********************************" << endl;	cout << "ACTION:YOU PULL THE STRANGER OUT OF THE DITCH" << endl;	cout << "***********************************" << endl;	cout << "???:Thank you I was badly hurt" << endl;	cout << "" << name << ":I haven't seen you before. What's your name?" << endl;	cout << "???:My name is Harold, I sell Jore." << endl;	cout << "Harold:Say, do you have a Jore?" << endl;	cout << "" << name << ":No." << endl;	cout << "Harold:I'll tell you what, i'll give you one of mine for saving me" << endl;	cout << "Harold:However, I have 3 so you'll have to choose" << endl;	cout << "Harold:Which would you like? wroon, prucky or pucher: ";	cin >> Jore;	if (Jore=="wroon" || Jore=="prucky" || Jore=="pucher")	{	cout << "***********************************" << endl;	cout << "YOU RECIEVED A " << Jore << "!!!!!" << endl;	cout << "***********************************" << endl;	cout << "Harold:Well, I best be off, maybe well catch up another time" << endl;	cout << "Harold:To heal you should take it to first aid" << endl;	cout << "Harold:And I suggest that you train in the warehouse before going out of town" << endl;	cout << "" << name << ":Ok, Thanks!" << endl;	cout << "***********************************" << endl;	cout << "YOUR " << Jore << " IS LVL 1" << endl;	lvl = 1;	HP = 30;	neededEXP = lvl * 100;	if (Jore=="wroon") HPFULL = 28;	else if (Jore=="prucky") HPFULL = 32;	else HPFULL = 30;	cout << "***********************************" << endl;	while (quit==false)	{		cout << "What are you going to do?" << endl;		cout << "(1) HEAL" << endl;		cout << "(2) BATTLE IN TRAINING SHED" << endl;		cout << "(3) BATTLE OUT OF ZEEKI" << endl;		cout << "(4) QUIT GAME" << endl;		cout << "ENTER (1-4): ";		cin >> choice;		switch (choice)		{		case 1:        HP = HPFULL;		break;		case 2:		battleIn();		break;		case 3:		battleOut();		break;		case 4:		cout << "GOODBYE" << endl;		quit = true;		return 0;		default:        cout << "You must enter a valid number" << endl;		cout << "*******************************" << endl;		}	}	}	return 0;}void battleIn(){	int opAttack;	int attack;	int whichAttack; 	bool win = false;	bool opWin = false;	string foe;	int whichJore = (rand() % 3) + 1;	switch (whichJore)	{	case 1:	foe = "Rofro";	opLvl = (rand() % 3) + 1;	break;	case 2:	foe = "Mussoo";    opLvl = (rand() % 4) + 1;	break;	case 3:    foe = "Cromotis";	opLvl = (rand() % 3) + 1;	break;	default:		foe = "Groke";		opLvl = (rand() % 4) + 1;        }		switch (opLvl)		{		case 1:        opHP = 20;		break;		case 2:        opHP = 29;		break;		case 3:        opHP = 38;		break;		case 4:        opHP = 46;		break;		default:		opHP = 15;		}		cout << "Your opponent is " << foe << endl;		cout << "With " << opHP << " HP" << endl;		while (win==false && opWin==false)		{						cout << "(1) bash" << endl;			cout << "(2) bite" << endl;			cout << "Choose your attack (1 or 2): ";			cin >> whichAttack;			switch (whichAttack)			{			case 1:            attack = (rand() % 8) + 1;            break;			case 2:            attack = (rand() % 9) + 1;            break;			}			cout << "You have done " << attack << " damage" << endl;			opAttack = (rand() % 10) + 1;			opHP = opHP - attack;			cout << "The opponent has " << opHP << " health left" << endl;            cout <<"The opponent has done " << opAttack << " damage" << endl;		    HP = HP - opAttack;			cout << "You have " << HP << " health left" << endl;			if (opHP<=0)			{				cout << "You have won!" << endl;				win = true;			    switch (opLvl)				{				case 1:					EXP = 40;					break;				case 2:					EXP = 70;					break;				case 3:					EXP = 110;				    break;				case 4:					EXP = 160;					break;				default :					EXP = 0;				}				neededEXP = neededEXP - EXP;			cout << "You have collected " << EXP << " EXP" << endl;			cout << "You still need " << neededEXP << " EXP" << endl;			}			else if (HP <= 0)			{				cout << "Sorry you have lost" << endl;				cout << "*********************************" << endl;				opWin = true;		}		}											if (neededEXP <= 0)				{					lvl++;					HPFULL = HPFULL + 4;					HP = HPFULL;					cout << "Congratulations!!! You are now lvl " << lvl << endl;				    neededEXP = lvl * 100;				}	}void battleOut(){	int opAttack;	int attack;	int whichAttack; 	bool win = false;	bool opWin = false;	string foe;	int whichJore = (rand() % 3) + 1;	switch (whichJore)	{	case 1:	foe = "Jubbo";	opLvl = (rand() % 5) + 2;	break;	case 2:	foe = "Frump";    opLvl = (rand() % 5) + 2;	break;	case 3:    foe = "Enomore";	opLvl = (rand() % 6) + 1;	break;        }		switch (opLvl)		{		case 1:        opHP = 20;		break;		case 2:        opHP = 29;		break;		case 3:        opHP = 38;		break;		case 4:        opHP = 46;		break;		case 5:		opHP = 55;		case 6:		opHP = 70;		}		cout << "Your opponent is " << foe << endl;		cout << "With " << opHP << " HP" << endl;		while (win==false && opWin==false)		{						cout << "(1) bash" << endl;			cout << "(2) bite" << endl;			cout << "Choose your attack (1 or 2): ";			cin >> whichAttack;			switch (whichAttack)			{			case 1:            attack = (rand() % 8) + 1;            break;			case 2:            attack = (rand() % 9) + 1;            break;			}			cout << "You have done " << attack << " damage" << endl;			opAttack = (rand() % 10) + 1;			opHP = opHP - attack;			cout << "The opponent has " << opHP << " health left" << endl;            cout <<"The opponent has done " << opAttack << " damage" << endl;		    HP = HP - opAttack;			cout << "You have " << HP << " health left" << endl;			if (opHP<=0)			{				cout << "You have won!" << endl;				win = true;			    switch (opLvl)				{				case 1:					EXP = 40;					break;				case 2:					EXP = 70;					break;				case 3:					EXP = 110;				    break;				case 4:					EXP = 160;					break;				case 5:					EXP = 220;				case 6:					EXP = 350;				default :					EXP = 0;				}				neededEXP = neededEXP - EXP;			cout << "You have collected " << EXP << " EXP" << endl;				cout << "You still need " << neededEXP << " EXP" << endl;			}			else if (HP <= 0)			{				cout << "Sorry you have lost" << endl;				cout << "*********************************" << endl;				opWin = true;		}		}											if (neededEXP <= 0)				{					lvl++;					cout << "Congratulations!!! You are now lvl " << lvl << endl;				    HPFULL = HPFULL + 4;					HP = HPFULL;					neededEXP = lvl * 100;				}	}			



Is this right?



TRY IT!
##########################################################You'll have time to rest when you're dead - Robert De Niro
Im working on a text based Master Mind.
I dont consider it finished even though it seems to work ok.
Feel free to comment on the source, or if there is any MM rules I forgot.

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#include <iostream>#include <vector>#include <string>#include <sstream>#include <cctype>#include <bitset>#include <time.h>//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~const int field_nslots = 4;const int field_ncolors = 6;const std::string field_colors = "-qwerty";class Field{	int m_slot[field_nslots];public:	Field();	int& operator [] (int index);	bool operator == (const Field &f) const;	std::string str() const;	void scramble();	bool get_user_field(std::vector<std::string> &vhistory);	bool solve_for(const Field& r, std::vector<std::string> &vhistory);};//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~int main(){		Field codemaker, codebreaker;	std::vector<std::string> history;	int max_tries = 12, ntries = 0;	srand((unsigned int)time(0));	std::cout << "\tMaster Mind\n\nThe possible color keys to choose from in this game is [qwerty]\nand is taken from the Plutonian color system...\n" << std::endl;	codemaker.scramble();		// codemaker[0] = 1; codemaker[1] = 5; codemaker[2] = 3; codemaker[3] = 1; // debug	do {		if(!codebreaker.get_user_field(history))			return 0; // user pressed x		//std::cout << codemaker.str() << std::endl; // debug	} while(++ntries < max_tries && !codebreaker.solve_for(codemaker, history));	if(ntries >= max_tries)		std::cout << "\nToo many tries\n" << std::endl;	else std::cout << "\nCongratulations. You made it in " << ntries << " attempts\n" << std::endl;	std::cout << "Here is the code: " << codemaker.str() << std::endl;	std::cout << "\nPress [return] to exit" << std::endl;	std::cin.get();	return 0;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Field::Field() { 	for(int i=0; i<field_nslots; i++)		m_slot = 0; }//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~inline int& Field::operator [] (int index){ 	return m_slot[index]; }//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~bool Field::operator == (const Field &f) const{	for(int i=0; i<field_nslots; i++)		if(m_slot != f.m_slot)			return false;	return true;	}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~std::string Field::str() const{	std::string s;	for(int i=0; i<field_nslots; i++)				s += field_colors[m_slot];			return s;	}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~void Field::scramble(){	for(int i=0; i<field_nslots; i++)		m_slot = 1 + rand() % field_ncolors;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~bool Field::get_user_field(std::vector<std::string> &vhistory){			std::string sc;	if(vhistory.size()) {		std::cout << "\nCode:\t\tPin pos.:\tPin col.:" << std::endl;		for(std::size_t i=0; i<vhistory.size(); i++)			std::cout << vhistory << std::endl;	}	do {		std::cout << "\n\nEnter " << field_nslots << " colors (x to quit) [" << field_colors << "]\n[" << vhistory.size() + 1 << "]: ";		std::getline(std::cin, sc);		if(std::tolower(sc[0]) == 'x')			return false;	} while(sc.size() < field_nslots);		std::size_t pos;	for(int i=0; i<field_nslots; i++) {		pos = field_colors.find(sc, 0);		m_slot = (pos != field_colors.npos) ? (int)pos : 0;	}	return true;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~bool Field::solve_for(const Field& r, std::vector<std::string> &vhistory){		if(*this == r)		return true;		Field cm = *this;	std::bitset<field_nslots> bp, bc;	for(int i=0; i<field_nslots; i++)			for(int j=0; j<field_nslots; j++) 				if(cm.m_slot == r.m_slot[j] && i == j)						{				bp.set(i);				cm.m_slot = 0;			}	for(int i=0; i<field_nslots; i++)			for(int j=0; j<field_nslots; j++) 				if(cm.m_slot == r.m_slot[j]) 															bc.set(i);										std::stringstream ss;	ss << this->str() << "\t\t" << bp.count() << "\t\t" << bc.count();			vhistory.push_back(ss.str());	return false;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


[Edited by - pulpfist on July 20, 2006 8:25:32 PM]

This topic is closed to new replies.

Advertisement