I am a complete brand new coder who has had probably less than 2 weeks with c++ and taught myself a lot of if statements as well as switches.
It would be great if someone could look through this game I've been making and talk me through all the things I should and shouldn't be doing.
Note that the second trail if statement is not coded yet.
#include "MeadowGiant.h"
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
MeadowGiant::MeadowGiant()
{
int trail, caveEnter;
int fight1;
int loot;
int goblinAttack, goblinHP, HP, attack, action1, ability;
goblinAttack = 5;
goblinHP = 10;
HP = 100;
std::cout << -Insert story narrative- Choose a trail to go down.\n";
std::cin >> trail;
if(trail==1)
{
std::cout << "-Insert story narrative- Come across a cave. Do you go in?\n";
std::cin >> caveEnter;
if(caveEnter==1)
{
std::cout << "You are ambushed by a goblin. Run or fight?\n";
std::cin >> fight1;
goblinFight:
loot = rand() % 4 + 1;
srand(time(NULL));
if(fight1==1)
{
std::cout << "Your HP: " << HP << std::endl;
std::cout << "Enemy HP: " << goblinHP << std::endl;
std::cout << "What do you do?\n
<< "[1] Attack [2] Run \n";
std::cin >> action1;
}
if(goblinHP<=0)
{
std::cout << "You have slain the goblin!\n"
<< "You head towards the chest and take the spoils\n"
<< "of battle!\n";
switch(loot)
{
case 1: std::cout << "You find a bastard sword!\n"
attack = attack + 7;
goto exitCave;
case 2: std::cout << "You find an Enchanted Staff!\n"
attack = attack + 10;
goto exitCave;
case 3: std::cout << "You find an Obsidian Dagger!\n"
attack = attack + 9;
goto exitCave;
case 4: std::cout << "You find a Holy Mace!\n"
attack = attack + 10;
goto exitCave;
}
else if(action1==1)
{
std::cout << "You successfully hit the goblin!\n"
<< "He strikes back!\n";
attack = rand() % 10 + 1;
srand(time(NULL));
goblinHP = goblinHP - attack;
HP = HP - goblinAttack;
goto goblinFight;
}
else if(action==2)
{
std::cout << "You take the cowards way out and leave the cave.\n";
goto exitCave;
}
}
else if(caveEnter==2)
{
exitCave:
std::cout << "You have exited the cave.\n";
}
else
{
goto exitCave;
}
}
}
Aucun commentaire:
Enregistrer un commentaire