All pastes #417056 Raw Edit

Mine

public text v1 · immutable
#417056 ·published 2007-03-30 18:24 UTC
rendered paste body
/*
     Very simple battle game

    Copyright (C) 2007 GameDev

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


#include <string>
#include <iostream>

#define MAX_SPELLS 5

int plrHealth;
int enmHealth;

int plrPower;
int enmPower;

void enemy_turn();
void player_turn();

struct spell {
 int damage; 
 //SDL_Surface *surface; // for later
 std::string name;
};

spell spells[MAX_SPELLS];
spell enemy_spells[MAX_SPELLS];

std::string enemyName;

std::string getStr() {
 std::string str;
 std::cin>> str;
 return str;
}
int getInt() {
 int i;
 std::cin>> i;
 return i;
}

void player_turn() {
 std::cout<< "Enter Spell To Use:" <<std::endl;
 std::cout<< "[X] Melee" << std::endl;
 for(int i=0; i<MAX_SPELLS; i++) {
  std::cout<< "[" << i << "] " << spells[i].name << std::endl;
 }
 int num = getInt(); 
 spell plrSpell = spells[num];

 if(plrHealth > 0) {
  std::cout<< "**BAM** You hit " << enemyName << "for " << plrSpell.damage << " damage!!!" << std::endl;
  enmHealth -= plrSpell.damage;
  enemy_turn();
 } else {
  std::cout<< "You are too weak to continue!";
 }
}

void enemy_turn() {
  // TODO: Make this random
  spell enmSpell = enemy_spells[4];
  if(enmHealth > 0) {
   std::cout<< "**BAM** they hit you for " << enmSpell.damage << " damage!!!" << std::endl;
   plrHealth -= enmSpell.damage;
   player_turn();
  } else {
   std::cout<< "They are too weak to continue!"; }
}


 int main() {
  std::cout<< "*w00t* starting battle" << std::endl;
  spell s1;
    s1.damage = 10; s1.name = "Wind Blast"; spells[0] = s1; enemy_spells[0] = s1; 

  spell s2;
  s2.damage = 15; s2.name = "Earth Blast"; spells [2] = s2; enemy_spells[2] = s2; 

  spell s3;
   s3.damage = 20; s3.name = "Water Blast"; spells [3] = s3; enemy_spells[3] = s3; 

  spell s4;
   s4.damage = 25; s4.name = "Fire Blast"; spells [4] = s4; enemy_spells[4] = s4; 

  plrPower = 15; enmPower = 15;
  plrHealth = 100; enmHealth = 75;
  player_turn();
 }