Skip to content

Instantly share code, notes, and snippets.

@vyruz
Last active December 16, 2015 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vyruz/5457541 to your computer and use it in GitHub Desktop.
Save vyruz/5457541 to your computer and use it in GitHub Desktop.
#include "game.hpp"
#include <iostream>
#include <cstdlib>
using namespace std;
void output(player player1, player player2);
int main(){
int turn; //1 = player1, 2 = player2
cout << "this is a very basic pokemon type game. This is only the battle sequence" << endl;
cout << "this is 1 player vs the computer" << "\n \n" << endl;
player player1; //player
player player2; //computer
player1.set_defaults();
player2.set_defaults();
if(player1.get_speed() > player2.get_speed()){
turn = 1;
}else{
turn = 2;
}
output(player1, player2);
take_turn(player1, player2, turn);
while(player1.get_health() != 0 && player2.get_health() != 0){
take_turn(player1, player2, turn);
output(player1, player2);
}
if(player1.get_health() == 0){
cout << "LOSSER" << endl;
}else{
cout << "WINNER" << endl;
}
}
void output(player player1, player player2){
cout << "--------------------------------------------------------------------" << endl;
cout << "Player 2:" << endl;
cout << "Health: " << player2.get_health() << " Defense: " << player2.get_defense() << endl;
cout << "\n" << "\n" << "\n" << endl;
cout << "Player 1:" << endl;
cout << "Health: " << player1.get_health() << " Defense: " << player1.get_defense() << endl;
cout << "1:attack 2:defend" << "\n" << "3:heal 4:stun" << endl;
}
void take_turn(player& player1, player& player2, int &turn){
bool stun_man;
if(turn == 1){ //player1's turn
if(player1.is_stun() == true){
stun_man = false;
player1.set_stun(stun_man);
return;
}
else{
int move;
turn = 2;
cout << "Enter the number of the move you wish to make" << endl;
cin >> move;
if(move == 1){
player1.attack(player2);
return;
}
if(move == 2) {
player1.defend();
return;
}
if(move == 3) {
player1.heal();
return;
}
if(move == 4) {
player1.stun(player2);
return;
}
else{
cout << "enter a valid move number (1-4)" << endl;
cin >> move;
}
}
}else{ //player 2's turn
turn = 1;
if(player2.is_stun() == true){
stun_man = false;
player2.set_stun(stun_man);
return;
}else{
comp_move(player1, player2);
return;
}
}
}
void comp_move(player& player1, player& player2){
if(player1.get_health() >= player2.get_health()){
if((2*(player2.get_health())) <= player1.get_health()){ //if health * 2 is less that player 1 then heal
player2.heal();
}else if(player1.get_health() <= 30){
player2.attack(player1);
}
else{
player2.defend();
}
}else{
if(player2.get_health() >= 70){
player2.stun(player1);
}else{
player2.attack(player1);
}
}
}
void player::set_defaults(){
max_health = 100;
current_health = 100;
defense = 50;
speed = rand() %50 + 50;
is_stunned = false;
return;
}
void player::change_health(int change){
current_health = current_health + change;
return;
}
void player::change_speed(int change){
speed = speed + change;
return;
}
void player::change_defense(int change){
defense = defense + change;
return;
}
int player::get_health(){
return current_health;
}
int player::get_speed(){
return speed;
}
int player::get_defense(){
return defense;
}
void player::set_stun(bool stun){
is_stunned = stun;
}
void player::attack(player& target){
//to be done
int damage;
damage = rand()%11;
damage = damage - (target.get_defense()/10);
damage = -damage;
target.change_health(damage);
target.change_defense((-2));
return;
}
int player::defend(){
//to be done
int def = rand() % 10 + 1;
return def;
}
int player::heal(){
//to be done
int healz = rand() % 5 + 5;
return healz;
}
void player::stun(player& target){
//to be done
bool what = true;
target.set_stun(true);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment