Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

hai guyz i can program

Name: Anonymous 2007-11-26 22:35

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    init:
         string player_a;
         string player_b;
         int a_hp = 100;
         int b_hp = 100;
         int a_poison = 0;
         int b_poison = 0;
         int attack = 0;
         int turn = 0;
    name:
         cout << "Name PLAYER 1: ";
         cin >> player_a;
         cout << "Name PLAYER 2: ";
         cin >> player_b;
         cout << "------------------" << endl;
    disp:
         if (a_hp < 1) {
               goto b_win;  
         }
         if (b_hp < 1) {
               goto a_win;  
         }
         cout << player_a << ": " << a_hp << endl;
         cout << player_b << ": " << b_hp << endl;
         cout << "------------------" << endl;
         if (turn == 0) {
                  turn = 1;
                  goto a_turn;
         }
         if (turn == 1) {
                  turn = 0;
                  goto b_turn;        
         }
    a_turn:
           cout << player_a << "'s turn:" << endl;
           if (a_poison == 1) {
                        cout << "* * * * * * * * * * * * * *" << endl;
                        cout << "You've been hurt by poison!" << endl;
                        cout << " * * * * * * * * * * * * *" << endl;
                        a_hp -= 2;
           }
           cout << "1. Poison Strike" << endl;
           cout << "2. Fury Slash" << endl;
           cout << "Your move: ";
           cin >> attack;
           cout << "------------------" << endl;
           switch (attack) {
                  case 1: goto poison; break;
                  case 2: goto slash; break;
                  default: goto fail; break;      
           }
    b_turn:
           cout << player_b << "'s turn:" << endl;
           if (b_poison == 1) {
                        cout << "* * * * * * * * * * * * * *" << endl;
                        cout << "You've been hurt by poison!" << endl;
                        cout << " * * * * * * * * * * * * *" << endl;
                        b_hp -= 2;
           }
           cout << "1. Poison Strike" << endl;
           cout << "2. Fury Slash" << endl;
           cout << "Your selection: ";
           cin >> attack;
           cout << "------------------" << endl;
           switch (attack) {
                  case 1: goto poison; break;
                  case 2: goto slash; break;
                  default: goto fail; break;      
           }
    poison:
           if (turn == 1) {
                    b_poison = 1;       
           }
           if (turn == 0) {
                    a_poison = 1;
           }
           goto disp;
    slash:
          if (turn == 1) {
                    b_hp -= 10;       
           }
           if (turn == 0) {
                    a_hp -= 10;
           }
           goto disp;
    fail:
         cout << "lol n00b!" << endl;
         cout << "------------------" << endl;
         goto disp;
    a_win:
          cout << "*****************************" << endl;
          cout << player_a << " is victorious!!!" << endl;
          cout << "*****************************" << endl;
          system("PAUSE");
          return 0;
    b_win:
          cout << "*****************************" << endl;
          cout << player_b << " is victorious!!!" << endl;
          cout << "*****************************" << endl;
          system("PAUSE");
          return 0;
}

Name: Bacu !!DMsSxeOfR1ab7SB 2007-11-27 11:18

Spaghetti code is worse than copypasta.

use some functions, dammit.

only use goto for breaking out of a multi-level loop.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List