-
1 Attachment(s)
[C++]Goto i quess
hello,
im busy with c++ agian i did use shadow his source and did edit it a bit
now i wanna make more charachters but it wont work my script
it wont load the skill list
Code:
#include <cstdlib>
#include <iostream>
#include <iostream>
using namespace std;
int main() {
system("TITLE Wizard Fight");
system("COLOR 1F");
//txt
int playerHp = 140;
char alp = 'a';
cout << "Wizard Fight" << endl << endl;
cout << "Made by Pascal Wever" << endl;
cout << "Found a bug? To report it Please add passiew@live.nl" << endl;
cout << "To your msn or just send a mail" << endl <<endl;
cout << "(C) Shadow 2007 " << endl <<endl;
cout << "version 0.2" << endl << endl;
system("PAUSE");
newgame:
startgame:
system("CLS");
int npcHp = 0;
int lvl = 0;
// hit point variables
cout << "Choose your level" << endl << endl;
cout << "1 - (Monster Hp 100)" << endl;
cout << "2 - (Monster Hp 150)" << endl;
cout << "3 - (Monster Hp 200)" << endl;
cout << "please select a level !"<< endl;
cin >> lvl;
if (lvl = 1) {
npcHp = 100;
}
if (lvl = 2) {
npcHp = 150;
}
if (lvl = 3) {
npcHp = 200;
}
newchar:
system("CLS");
cout << "Choose your Character" << endl << endl;
cout << "1 - Wizard" << endl;
cout << "2 - Archer" << endl;
cout << "3 - Swordsman" << endl;
cout << "please select your character !"<< endl;
cin >> lvl;
if (lvl==1) {
goto wizard;
}
if (lvl==2) {
goto newchar;
}
if (lvl==3) {
goto newchar;
}
// user's weapon variables
int weapons[7];
weapons[0] = 1;
weapons[1] = 1;
weapons[2] = 1;
weapons[3] = 1;
weapons[4] = 1;
weapons[5] = 1;
weapons[6] = 1;
weapons[7] = 1;
// user's weapon input
int wepNumber;
wepNumber = 0;
// user's weapon deamage
int wDmg[7];
wDmg[0] = 0;
wDmg[1] = 0;
wDmg[2] = 0;
wDmg[3] = 0;
wDmg[4] = 0;
wDmg[5] = 0;
wDmg[6] = 0;
wDmg[7] = 0;
// enemy's weapon deamage
int ewDmg[7];
ewDmg[0] = 0;
ewDmg[1] = 0;
ewDmg[2] = 0;
ewDmg[3] = 0;
ewDmg[4] = 0;
ewDmg[5] = 0;
ewDmg[6] = 0;
ewDmg[7] = 0;
// enemy weapon variables
int eWep[7];
eWep[0] = 1;
eWep[1] = 1;
eWep[2] = 1;
eWep[3] = 1;
eWep[4] = 1;
eWep[5] = 1;
eWep[6] = 1;
eWep[7] = 1;
//replaced a gets by user (y/n)
// weapons treu or false (on / off)
// and assing damage to weapon in array wDmg
wizard:
system("CLS");
cout << "Wizard Fight" << endl << endl;
switch (weapons[0] == 1)
case 1: cout << "0 - Fireball" << endl;
wDmg[0] = (rand()%30)+5;
switch (weapons[1] == 1)
case 1: cout << "1 - Lighting" << endl;
wDmg[1] = (rand()%20)+6;
switch (weapons[2] == 1)
case 1: cout << "2 - Water Storm" << endl;
wDmg[2] = (rand()%14)+8;
switch (weapons[3] == 1)
case 1: cout << "3 - Thunder Rain" << endl;
wDmg[3] = (rand()%14)+13;
switch (weapons[4] == 1)
case 1: cout << "4 - Thunder Clap" << endl;
wDmg[4] = (rand()%19)+15;
switch (weapons[5] == 1)
case 1: cout << "5 - Light Of Deliveranc" << endl;
wDmg[5] = (rand()%30)+20;
switch (weapons[6] == 1)
case 1: cout << "6 - Shock Wave" << endl;
wDmg[6] = (rand()%33)+23;
switch (weapons[7] == 1)
case 1: cout << "7 - Ray Of Judgment" << endl;
wDmg[7] = (rand()%15)+40;
cout << endl;
// Enemy's weapon damage
// weapons treu or fales (on / off)
switch (eWep[0] == 1)
case 1: ewDmg[0] = (rand()%30)+5;
switch (eWep[1] == 1)
case 1: ewDmg[1] = (rand()%20)+6;
switch (eWep[2] == 1)
case 1: ewDmg[2] = (rand()%14)+8;
switch (eWep[3] == 1)
case 1: ewDmg[3] = (rand()%14)+13;
switch (eWep[4] == 1)
case 1: ewDmg[4] = (rand()%19)+15;
switch (eWep[5] == 1)
case 1: ewDmg[5] = (rand()%30)+20;
switch (eWep[6] == 1)
case 1: ewDmg[6] = (rand()%33)+23;
switch (eWep[7] == 1)
case 1: ewDmg[7] = (rand()%15)+40;
// User input of weapon number
cout << "Please enter the number of the weapon you would like to use" << endl;
cin >> wepNumber;
cout << endl;
// checks witch number is entered by user and run code
wepcheck:
if (wepNumber == 0 && weapons[0] == 1){
npcHp = npcHp - wDmg[0];
weapons[0] = 0;
if (npcHp < 0){
npcHp = 0;
}
cout << "Enemy lost : " << wDmg[0] << " health and has : " << npcHp << " remaining" << endl;
}
else if (wepNumber == 1 && weapons[1] == 1) {
npcHp = npcHp - wDmg[1];
weapons[1] = 0;
if (npcHp < 0){
npcHp = 0;
}
cout << "Enemy lost : " << wDmg[1] << " health and has : " << npcHp << " remaining" << endl;
}
else if (wepNumber == 2 && weapons[2] == 1) {
npcHp = npcHp - wDmg[2];
weapons[2] = 0;
if (npcHp < 0){
npcHp = 0;
}
cout << "Enemy lost : " << wDmg[2] << " health and has : " << npcHp << " remaining" << endl;
}
else if (wepNumber == 3 && weapons[3] == 1) {
npcHp = npcHp - wDmg[3];
weapons[3] = 0;
if (npcHp < 0){
npcHp = 0;
}
cout << "Enemy lost : " << wDmg[3] << " health and has : " << npcHp << " remaining" << endl;
}
else if (wepNumber == 4 && weapons[4] == 1) {
npcHp = npcHp - wDmg[4];
weapons[4] = 0;
if (npcHp < 0){
npcHp = 0;
}
cout << "Enemy lost : " << wDmg[4] << " health and has : " << npcHp << " remaining" << endl;
}
else if (wepNumber == 5 && weapons[5] == 1) {
npcHp = npcHp - wDmg[5];
weapons[5] = 0;
if (npcHp < 0){
npcHp = 0;
}
cout << "Enemy lost : " << wDmg[5] << " health and has : " << npcHp << " remaining" << endl;
}
else if (wepNumber == 6 && weapons[6] == 1) {
npcHp = npcHp - wDmg[6];
weapons[6] = 0;
if (npcHp < 0){
npcHp = 0;
}
cout << "Enemy lost : " << wDmg[6] << " health and has : " << npcHp << " remaining" << endl;
}
else if (wepNumber == 7 && weapons[7] == 1) {
npcHp = npcHp - wDmg[7];
weapons[7] = 0;
if (npcHp < 0){
npcHp = 0;
}
cout << "Enemy lost : " << wDmg[7] << " health and has : " << npcHp << " remaining" << endl;
}
else { // if a wrong number has been entered by the user
wepNumber = 0;
cout << "Wrong Number Please try again" << endl;
cin >> wepNumber;
cout << endl;
goto wepcheck;
}
// check if npc has 0 hp
// check if user stil have a weapon left to use
if (npcHp <= 0){
cout << "You Win" << endl << endl;
goto endgame;
}
else if (weapons[0] == 0 && weapons[1] == 0 && weapons[2] == 0 && weapons[3] == 0 && weapons[4] == 0 && weapons[5] == 0 && weapons[6] == 0 && weapons[7] == 0){
cout <<"Draw Game" << endl <<endl;
goto endgame;
}
else {
// end of line
cout << endl;
cout << "Enemy's turn to atack" << endl << endl;
system("COLOR 4F");
system("PAUSE");
cout << endl;
// enemy atack
if (wepNumber == 0 && eWep[0] == 1) {
playerHp = playerHp - ewDmg[6];
eWep[0] = 0;
if (playerHp < 0){
playerHp = 0;
}
cout << "You lost : " << ewDmg[0] << " health and have : " << playerHp << " health left" << endl;
}
else if (wepNumber == 1 && eWep[1] == 1) {
playerHp = playerHp - ewDmg[1];
eWep[1] = 0;
if (playerHp < 0){
playerHp = 0;
}
cout << "You lost : " << ewDmg[1]<< " health and have : " << playerHp << " health left" << endl;
}
else if (wepNumber == 2 && eWep[2] == 1) {
playerHp = playerHp - ewDmg[2];
eWep[1] = 0;
if (playerHp < 0){
playerHp = 0;
}
cout << "You lost : " << ewDmg[2]<< " health and have : " << playerHp << " health left" << endl;
}
else if (wepNumber == 3 && eWep[3] == 1) {
playerHp = playerHp - ewDmg[3];
eWep[1] = 0;
if (playerHp < 0){
playerHp = 0;
}
cout << "You lost : " << ewDmg[3]<< " health and have : " << playerHp << " health left" << endl;
}
else if (wepNumber == 4 && eWep[4] == 1) {
playerHp = playerHp - ewDmg[4];
eWep[1] = 0;
if (playerHp < 0){
playerHp = 0;
}
cout << "You lost : " << ewDmg[4]<< " health and have : " << playerHp << " health left" << endl;
}
else if (wepNumber == 5 && eWep[5] == 1) {
playerHp = playerHp - ewDmg[5];
eWep[1] = 0;
if (playerHp < 0){
playerHp = 0;
}
cout << "You lost : " << ewDmg[5]<< " health and have : " << playerHp << " health left" << endl;
}
else if(wepNumber == 6 && eWep[6] == 1) {
playerHp = playerHp - ewDmg[6];
eWep[1] = 0;
if (playerHp < 0){
playerHp = 0;
}
cout << "You lost : " << ewDmg[6]<< " health and have : " << playerHp << " health left" << endl;
}
else if(wepNumber == 7 && eWep[7] == 1) {
playerHp = playerHp - ewDmg[7];
eWep[1] = 0;
if (playerHp < 0){
playerHp = 0;
}
cout << "You lost : " << ewDmg[7]<< " health and have : " << playerHp << " health left" << endl;
}
}
// end of line
system("COLOR 1F");
cout << endl;
// Freeze console til key is entered
system("PAUSE");
// check if the player's hp is 0
if ( playerHp <= 0){
cout << "you lose" << endl;
goto endgame;
}
else {
goto startgame;
}
// endgame
endgame:
cout << "Would you like to play again? (Y)es or (N)o)" << endl;
selectexit:
cin >> alp;
if (alp == 'y') {
system("CLS");
goto newgame;
}
else if ( alp == 'Y'){
system("CLS");
goto newgame;
}
else if ( alp == 'n'){
system("CLS");
goto lastline;
}
else if ( alp == 'N'){
system("CLS");
goto lastline;
}
else {
cout << "Wrong char type y or n" << endl;
goto selectexit;
}
lastline:
return(0);
}
anyone can help ill upload the game so you can see what happen
greetz passie
-
Re: [C++]Goto i quess
nevermind mistake of me :S
but now i have a question
i wanna make multi characters and i just want the skill name to change so i think will work
menu :
Code:
cout << "Choose your Character" << endl << endl;
cout << "1 - Mage" << endl;
cout << "2 - Archer" << endl;
cout << "3 - Swordsman" << endl;
cout << "please select a char !"<< endl;
cin >> lvl;
if (lvl = 1) {
weaponName0 = "fireblast";
weaponName1 = "fireblast";
weaponName2 = "fireblast";
weaponName3 = "fireblast";
weaponName4 = "fireblast";
weaponName5 = "fireblast";
weaponName6 = "fireblast";
weaponName7 = "fireblast";
}
if (lvl = 2) {
npcHp = 150;
}
if (lvl = 3) {
npcHp = 200;
}
and at the skill i did this :
Code:
switch (weapons[0] == 1)
case 1: cout << weaponName0 = "" << endl;
wDmg[0] = (rand()%30)+5;
switch (weapons[1] == 1)
case 1: cout << weaponName1 = "" << endl;
wDmg[1] = (rand()%20)+6;
switch (weapons[2] == 1)
case 1: cout << weaponName2 = "" << endl;
wDmg[2] = (rand()%14)+8;
switch (weapons[3] == 1)
case 1: cout << weaponName3 = "" << endl;
wDmg[3] = (rand()%14)+13;
switch (weapons[4] == 1)
case 1: cout << weaponName4 = "" << endl;
wDmg[4] = (rand()%19)+15;
switch (weapons[5] == 1)
case 1: cout << weaponName5 = "" << endl;
wDmg[5] = (rand()%30)+20;
switch (weapons[6] == 1)
case 1: cout << weaponName6 = "" << endl;
wDmg[6] = (rand()%33)+23;
switch (weapons[7] == 1)
case 1: cout << weaponName7 = "" << endl;
wDmg[7] = (rand()%15)+40;
cout << endl;
why that wont explain and post solution if you can :)
-
Re: [C++]Goto i quess
Man, improve your english, I have really no idea what you talk about.
Multi-characters? Change weapon name? What do you want? What errors do you get?
-
Re: [C++]Goto i quess
i just want a variable in it so i only have to change at the menu and not at he config so not at this script :
Code:
switch (weapons[0] == 1)
case 1: cout << weaponName0 = "" << endl;
wDmg[0] = (rand()%30)+5;
switch (weapons[1] == 1)
case 1: cout << weaponName1 = "" << endl;
wDmg[1] = (rand()%20)+6;
switch (weapons[2] == 1)
case 1: cout << weaponName2 = "" << endl;
wDmg[2] = (rand()%14)+8;
switch (weapons[3] == 1)
case 1: cout << weaponName3 = "" << endl;
wDmg[3] = (rand()%14)+13;
switch (weapons[4] == 1)
case 1: cout << weaponName4 = "" << endl;
wDmg[4] = (rand()%19)+15;
switch (weapons[5] == 1)
case 1: cout << weaponName5 = "" << endl;
wDmg[5] = (rand()%30)+20;
switch (weapons[6] == 1)
case 1: cout << weaponName6 = "" << endl;
wDmg[6] = (rand()%33)+23;
switch (weapons[7] == 1)
case 1: cout << weaponName7 = "" << endl;
wDmg[7] = (rand()%15)+40;
cout << endl;
but at the menu that i do case 1 :
weaponName0 = "name i want";
weaponName1 = "name i want";
weaponName2 = "name i want";
weaponName3 = "name i want";
weaponName4 = "name i want";
weaponName5 = "name i want";
weaponName6 = "name i want";
weaponName7 = "name i want";
understand now ?
and the error is that he it is undeclared function
-
Re: [C++]Goto i quess
What is a menu?
To assign a value to a variable: [variable name] = [value];
weaponName = "Axe";
cout << weaponName << endl;
-
Re: [C++]Goto i quess
Another thing, your using comparisons in a case statement??? I dont like to tell this to people, but first go do some basic tutorials at least. And try to start from your own project. Taking someone else's code and working with it only works when you have a basic understanding.
so for simplicity sake i would have transformed this code (why is this working in any case? -> if you do say its working)
switch (weapons[0] == 1)
case 1: cout << weaponName0 = "" << endl;
wDmg[0] = (rand()%30)+5;
switch (weapons[1] == 1)
case 1: cout << weaponName1 = "" << endl;
wDmg[1] = (rand()%20)+6;
switch (weapons[2] == 1)
case 1: cout << weaponName2 = "" << endl;
wDmg[2] = (rand()%14)+8;
switch (weapons[3] == 1)
case 1: cout << weaponName3 = "" << endl;
wDmg[3] = (rand()%14)+13;
switch (weapons[4] == 1)
case 1: cout << weaponName4 = "" << endl;
wDmg[4] = (rand()%19)+15;
switch (weapons[5] == 1)
case 1: cout << weaponName5 = "" << endl;
wDmg[5] = (rand()%30)+20;
switch (weapons[6] == 1)
case 1: cout << weaponName6 = "" << endl;
wDmg[6] = (rand()%33)+23;
switch (weapons[7] == 1)
case 1: cout << weaponName7 = "" << endl;
wDmg[7] = (rand()%15)+40;
cout << endl;
and made it
for (int i = 0; i < weapons.size(); i++) /*cant remember if its size or length...to many languages xD*/
{
if (weapons[i])
{
cout << WeaponName[i] = "" << endl; //make weapon name an array so you can use it interchangebly with weapons array without all the variables
/* And what are you actually doing here? = takes precedence before << (output operand) so your setting WeaponName to nothing then printing out nothing?*/
wDmg[i] = (rand()%20)+number[i]; /*Once again instead of using set variables store them in an array. when getting to 2000+ lines of code (the max for a single code file please(
then having to search around for them is rediculous*/
}
}
cout << endl;
This is not to be rude, but this code is very sloppy. Please first go do some tuts
-
Re: [C++]Goto i quess
Its length ;), weapons.length();
-
Re: [C++]Goto i quess
i mean like this in php
PHP Code:
<?php
$wepean1 = "Dagger";
echo $wepean1;
?>
-
Re: [C++]Goto i quess
Code:
#include <iostream>
#include <string>
void main() {
string wepName[3];
wepName[1] = "Flamethrower";
wepName[2] = "Grande Launcer";
wepName[3] = "AK-47";
cout << wepName[1] << endl; // outputs Flamethrower
cout << wepName[2] << endl; // outputs Granade Launcer
cout << wepName[3] << endl; // outputs AK-47
}
-
Re: [C++]Goto i quess