Thursday, December 23, 2010

inputstring.cpp

I was wondering about this problem. And somehow, so curious as to how to solve it. So, um, I think I solved it my way. Wonder if that user accidentally click my signature link and read this? haha

inputch.cpp

It is a simple thing. Yeah. But I found out about characters can be changed using add operator. Well, just kinda happy to find it on my own while trying to help others.

The Beginning of my Java Adventure

Hello World!

Hehe. It took me quite a while to find out how to compile without using eclipse IDE and understand how to getting started. I don't want to use eclipse IDE first because to just click and click to get the auto-generated class name and main class is not a good learning process. Anyway, I accidentally found out how to make new line of text output when I just want to modified the code a bit.

Saturday, December 18, 2010

FizzBuzz Problem

I was reading some threads in Dream.In.Code when I crossed this link. Interesting enough, it takes about 2 minutes for me to solve it. It supposed to be 1 minute, but I changed my mind about my code design when I realized there is a special specification of it that make it so simple. The FizzBuzz.

Thursday, December 16, 2010

C++ Coding Challenge #1

It is a challenge in Dream.In.Code. My program isn't like the expected because of my lack of knowledge, so it is really simple compared to others. But at least, I can practically use part of < algortihm > members now.

Wednesday, December 15, 2010

Row Reduction(Corrected)

It was simply I forgot to change float to double for type temp in function swaprow(). I should have known. Thanks to those that helps in Dream.In.Code.

Monday, December 13, 2010

Row Reduction

I was trying to help someone here. And I got curious, as I didn't have experience of writing this program. So this is my try. I stuck when I try input of this matrix.

0 1 2
3 4 5
6 7 8

For some reason, when it reach

1 4/3 4/5
0 1 2
0 -1 -2

It becomes

1 4/3 4/5
0 1 2
0 0 -1.33227e-015

Where it supposed to be 0 instead. = =" I will take a look at it again. Maybe something to do with my algorithm.

Tuesday, November 30, 2010

Castle age calculator

I am quite fond with the game Castle Age in Facebook. From time to time, I google about it to learn a bit more. Then I found these formula of BSI and LSI. Lazy to use a calculator, I use a computer instead. :) I have an executable if you want. :P

[Edit:] Oh, somehow old link is gone? Well, it is quite outdated though. New link

Saturday, November 27, 2010

1. Define an enumeration type named SHAPE containing values including sphere, rectangle, square, triangle and polygon.
2. Define an enumeration type OPTION which contains first, second and third.
3. Use OPTION and SHAPE as row and column respectively and print the values in a matrix format for an array MATRIX

#include <iostream>
using namespace std;

int main()
{
/*Define an enumeration type named SHAPE containing values including 
sphere, rectangle, square, triangle and polygon.*/
enum SHAPE {sphere,rectangle,square,triangle,polygon};
//Define an enumeration type OPTION which contains first, second and third.
enum OPTION {first,second,third};
/*Use OPTION and SHAPE as row and column respectively and 
print the values in a matrix format for an array MATRIX*/
int MATRIX[OPTION][SHAPE];
//incomplete

cin.get();
return 0;
}

Sunday, November 14, 2010

Exploring internet: Some of the things I found

I am taking a little break from trying to solve Euler's Problem. It seems if I learn Java, it will be easier. C++ has limit to the largest int it can use. Beside, I think it might be easier. So I surf around instead. :)

A computer science student should learn more than programming.

I like photoshopping, but I am limited to simple forum avatar and signature. Usually I take anime or game render. Luckily, I found a site that quite nice without any annoying requirement. ;)

I was wondering, if Mozilla Firefox have add-ons, what Google Chrome have? Extension.

Next semester, I am going to learn programming II(focus on Java, yay new language), Multimedia(yay my photoshop skill will come in handy), economy(oh my God), calculus II(oh, another math), English Preparation for Muet(need to read -.- ) and CTU(learning the way of life on paper).

Saturday, November 6, 2010

Quiz 2

Question:
Every student's record must consist of Age, ID Number and Mark.
a)  Declare a struct named PELAJAR which consists of the above component.
b)  In the main function, declare a student array which consists of 20 students.
c)  Create a function to read in the data for 20 students by using the student array and maximum number of students as parameters.
d)  Create a function to display the data for all students by using the student array and maximum number of students as parameters.
e)  Create a function to find a student with the highest mark.
f)   Complete the program by creating the main function:
     (i) Initialize the student array to dummy values.
     (ii) Create appropriate function calls to call functions in c), d) and e).
My answer:
#include <iostream>
#include <string>
using namespace std;
const int size = 20; int i;

struct PELAJAR
{
       int Age;
       string ID_Number;
       float Mark;
}students[size];

void read(PELAJAR students[size],int size)
{
     for (i=0;i<size;i++)
     {
         cout << (i+1) << ": " << endl;
         cout << "\tAge: ";
         cin  >> students[i].Age;
         cout << "\tID Number: ";
         cin  >> students[i].ID_Number;
         cout << "\tMark: ";
         cin  >> students[i].Mark;
         cout <<endl;
     }//for
}//Read

void display(PELAJAR students[size],int size)
{
     cout << endl;
     cout << "No\tAge\tID Number\tMark" << endl;
     for (i=0;i<size;i++)
     {
         cout << (i+1) << "\t" << students[i].Age << "\t" << students[i].ID_Number
                       << "\t" << students[i].Mark << endl;
     }
}//display

void highest (void)
{
     float highest = students[0].Mark;
     int high=0;
     for (i=1;i<size;i++)
     {
         if (students[i].Mark>highest)
         {
            highest=students[i].Mark;
            high=i;
         }
     }
     cout << endl;
     cout << "Student with highest mark is student " << (high+1)
          << " ID Number: " << students[high].ID_Number
          << " with Mark: " << students[high].Mark;
     cout << endl;
}

int main()
{
     for (i=0;i<size;i++)
     {
         students[i].Age=0;
         students[i].ID_Number="0";
         students[i].Mark=0.0;
     }
     read(students,size);
     display (students,size);
     highest();
  
     cin.ignore();
     cin.get();
     return 0;
}

Monday, October 18, 2010

My little palindrome program

#include <iostream>
using namespace std;

string input()
{
    string str;
    cout << "Enter Word: ";
    cin  >> str;
    cout << endl;
    return str;
}
string upperCase(string str, int size)
{//uppercase to made comparison easy
       for (size_t i = 0; i < size; i++)
           if (islower(str[i]))
              str[i] = toupper(str[i]);
       return str;
}
bool checkPalindrome(string str, int size)
{//check first[0] and last[size-1], followed by [1] and [size-1-1], [2] and [size-1-2]
     for (size_t i = 0; i < size/2; i++)//divide by two to avoid repetition comparison
         if (str[i] != str[size-i-1])//if not equal, not palindrome
            return false;
     return true;
}

int main(void)
{
    string word=" "; char cont, counter;
    int word_size;
    do
    {
    counter = 1;
    cout << "This is a program to detect palindrome word." << endl;
    //input word
    word=input();
  
    //check length
    word_size=word.size();
    cout << "word size: " << word_size << endl;
  
    //upper case word
    string uppercased=upperCase(word,word_size);
  
    //checkpalindrome()
    cout << word << " is";
    if (checkPalindrome(uppercased,word_size))
        cout << " ";
    else
        cout << " not ";
    cout << "a Palindrome." << endl;
    //continue program?
    while (counter)
    {
          cout << "Do you want to continue?[Y/N]: ";
          cin  >> cont;
          switch (cont)
          {
           case 'Y': case 'y':
           case 'N': case 'n':
            counter=0; break;
           default:
            cout << "Wrong input.\n";
           }//switch(cont)
    }//while(counter)
  
    }while (cont=='Y'||cont=='y');//do-while(cont)
    cout << endl << "Thank you for using this program.";
    cin.get();
    cin.ignore(1000,'\n');
    return 0;
}

Tuesday, October 12, 2010

Problem 1: natural number

At dreamincode.net/forums/ I found a thread regarding a list of sites that can help in learning C++, or programming at general. One of them is projecteuler.net. Interesting, as I have hard time since the first problem. I like solving problem especially when it is challenging. :)


/*
If we list all the natural number below 10 that are multiples of 3 or 5, we get 3,5,6, and 9.
The sum of these multiples is 23. find below 1000.
*/
#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int number, sum, max=1000;
    for (number=0,sum=0;number<max;number++)
    {
    if (((number%3)==0)||((number%5)==0))
       sum+=number;
       cout << number <<'+';
    }
    cout << endl;
    cout <<"The sum of natural number below "<< max <<" is:" << sum;
    getch();
}

Friday, October 8, 2010

Space Adventure Game- Complete

Well, that what I want to say, but it only good enough to be sent to lecturer as our assignment. I am going to learn how to use graphic interface in C++ and integrate that skill into this game too. But I am very thankful to God, and support from everyone especially my partner. He is good in user-friendly game interface.


Sunday, October 3, 2010

Multiplayer mode completed.

the following are prototype program for applying multiplayer mode in our game. The design is not well-structured because I just editing the important working original code to become multiplayer in 2 hour until 12 pm 03/OCT/2010 that is last night. I am crazy to think that I can complete it simply by turning on techno song and expect ideas to flow in while writing it. Well, a miracle happened that it worked somehow. The question trivia is still in progress, as i still want 70 questions in the program to ensure better randomness.

//Trying for multiplayer
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>
//#define MAX 100 //using 100 is wasting resources
using namespace std;

struct GAME
{                            //struct definition
char menu[15];
};
//global variables
const int row=9,col=8;
int i,j,current_i,current_j,step;
GAME advGame[4];
int no_menu;
int hp=20, mp=20, ehp=30, move, emove;
const int size_question=40;//to make it really random, try to get around 70 questions
int LimitBattle=35; //limiting battle to only 35
int LimitRest = 20; //limiting resting to only 20

struct WORLD                                       //world of the game
{
    char* board[row][col];                         //the board, or the playing field
    int game_element[row][col];                    //1 resting,2 question,3 portal/jump,4 battle
}world;                                            //note: make game_element at [0][0],[row-1][col-1] = 0

struct QUESTIONS
{
string q;
char ans;
int status; //keep status of being answer or not. if already use, value 1
}questions[size_question];

//function prototypes
int dice(void);
void intBoard(void);
void intgame_element(void);
void displayBoard(void);
//void initialMenu(GAME advGame[4]);
void GameStart(int player);
//void S_player(void);
//void M_player(void);                            
//void newGame(void);
//void guideline(void);
//void credit(void);
//void selectMenu(int no_menu);
//void displayMenu(GAME advGame[]);
void wait(float seconds);
void win(void);
int question(void);
void initializeQuestion (void);
void initializeStatus (void);

void slowstepsBoard2(int step);
int hp2=20, mp2=20;
void rest(int turn);
void portal(int turn);
int battle (int turn);
int player;
void lose(int turn);
void slowstepsBoard(int step);
int current_i2,current_j2;

main ()
{
     player=2;
     GameStart(player);
     system("PAUSE");
}

void GameStart(int player)
{
int no_menu,turn;
intBoard();
intgame_element();
initializeQuestion ();
   system("cls");
   cout<<"\n GAME START !!!...GOOD LUCK"<<endl;                                 //initialize board
   displayBoard();
   if (player==2)
   {
   turn=1;
   current_i2=0,current_j2=0;
   while (strcmp(world.board[8][7],"  P 1  ")!=0||strcmp(world.board[8][7],"  P 2  ")!=0)
   {
      if (turn==1)
         {goto labelsingle;}
      else if (turn ==2)
      {cout<<" Press any key to roll the dice.";
      getch();                                                     //display board
      step=dice();                               //get dice value and save as step
      system("cls");
      slowstepsBoard2(step);
      cout<<endl<<" Your dice value: "<<step<<endl;
      switch (world.game_element[current_i2][current_j2])
      {
             case 1:
                  cout<<endl<<"Resting Place"<<endl;
                  rest(turn);
                  break;
             case 2:
                  cout<<endl<<"Question"<<endl;
                  question();
                  break;
             case 3:
                  cout<<endl<<"Portal"<<endl;
                  portal(turn);
                  break;
             case 4:
                  cout<<endl<<"Battle"<<endl;
                  battle(turn);
                  world.board[(current_i2)][(current_j2)]="  P 2  ";
                  cout << endl;
                  displayBoard();
                  break;
      }
      world.board[current_i][current_j]="  P 1  ";
      world.board[current_i2][current_j2]="  P 2  ";
      displayBoard();}
      labelreturn:
      if (turn==1)
       turn =2;
      else if (turn==2)
       turn=1;
   }              
   }
   else
   { turn = 0;
   while(strcmp(world.board[8][7],"  P 1  ")!=0)
   {
      labelsingle:
      cout<<" Press any key to roll the dice.";
      getch();                                                     //display board
      step=dice();                               //get dice value and save as step
      system("cls");
      slowstepsBoard(step);                          //move P1 on board according to the step
      //display dice value
     cout<<endl<<" Your dice value: "<<step<<endl;
      switch (world.game_element[current_i][current_j])
      {
             case 1:
                  cout<<endl<<"Resting Place"<<endl;
                  rest(turn);
                  break;
             case 2:
                  cout<<endl<<"Question"<<endl;
                  question();
                  break;
             case 3:
                  cout<<endl<<"Portal"<<endl;
                  portal(turn);
                  break;
             case 4:
                  cout<<endl<<"Battle"<<endl;
                  battle(turn);
                  world.board[(current_i)][(current_j)]="  P 1  ";
                  if((player==2))
                  {world.board[current_i2][current_j2]="  P 2  ";}
                  cout << endl;
                  displayBoard();
                  break;
      }
      if(turn == 1) {goto labelreturn;}
   }
  
   win();
   cout<<" Congratulation !!!..You Finish The Game..."<<endl
       <<" See You Again..Thank You."<<endl<<" Back to Game Menu "<<endl;
   }//else
   system("PAUSE");
   system("cls");
   //displayMenu(advGame);
   //cout<<"\n Enter Number: ";             //choose menu
   //cin>>no_menu;
   //system("cls");
   //selectMenu(no_menu);
}

//======================================================================================================
//stepping around board player 2
void slowstepsBoard2(int step)
{
     //new code
     world.board[current_i2][current_j2]="       ";
     for (int count=0;count<=step;count++,current_j2++)
     {
        
         system("cls");
         if (current_i2==row||(current_i2==row&&current_j2==col))//when reach destination or over it, assign to
         {
         world.board[current_i2][current_j2]="       ";
         world.board[8][7]="  P 2  ";   //last destination and break out of loop
         if((player==2))
                  {world.board[current_i][current_j]="  P 1  ";}
         displayBoard();
         break;
         }
         if (current_j2>=col)
         {
current_j2=current_j2-col;
     current_i2++;
         }
         world.board[current_i2][current_j2]="  P 2  ";
         if((player==2))
                  {world.board[current_i][current_j]="  P 1  ";}
         displayBoard();
         world.board[current_i2][current_j2]="       ";
         wait(0.2);
     }//for
     current_j2--;
}

//======================================================================================================
//initialize board
void intBoard(void)
{
    for(i=0;i<row;i++)
     for(j=0;j<col;j++)
       world.board[i][j]    ="       ";
    world.board[0][0]        =" START ";
    world.board[row-1][col-1]="  END  ";
    current_i=0; current_j=0;
}
//======================================================================================================
//initialize game_element
void intgame_element(void)
{
     for (i=0;i<row;i++)
         for (j=0;j<col;j++)
       {
             int countLimitBattle=0;
             int countLimitRest=0;
             world.game_element[i][j]=rand() % 4 + 1;
             label4:
             if (world.game_element[i][j]==1)
             {
             if (countLimitRest==LimitRest)
                {world.game_element[i][j]=rand() % 4 + 1;
                goto label4;}
             else
              countLimitRest++;
             }
             label3:
             if (world.game_element[i][j]==4)
             {
             if (countLimitBattle==LimitBattle)
                {world.game_element[i][j]=rand() % 4 + 1;
                goto label3;}
             else
              countLimitBattle++;
             }
         }
world.game_element[row][col]=0; world.game_element[0][0]=0;
}
//======================================================================================================
//show game board
void displayBoard(void)
{
   world.board[0][0]=" START ";
   wait(0.2);
for(i=0;i<row;i++)
   { cout<<endl;
     for(j=0;j<(col);j++)
         cout<<"========";
      cout<<endl<<'|';
      if (i%2==1)
       for(j=(col-1);j>=0;j--)
         cout<<world.board[i][j]<<'|';
      else
       for(j=0;j<col;j++)
          cout<<world.board[i][j]<<'|';
   }
   cout<<endl;
   for(j=0;j<(col);j++)
         cout<<"========";
     cout<<endl;
}
//======================================================================================================
//======================================================================================================
//to slow down the display of the board
void wait(float seconds)
{
     //error converting clock_t from float
     //error didn't seems to affect gameplay
  clock_t endwait;
  endwait=clock()+seconds*CLOCKS_PER_SEC;
  while(clock()<endwait){}   // jarak antara nombor yang akan dipaparkan
}
//======================================================================================================
//resting function
void rest(int turn)
{
     //random comments in resting place element
     int randRest = (rand() % 2 + 1);
     switch (randRest)
     {
            case 1:
            cout << "You found a space cafe and decided to have a tea before proceed with your adventure."<<endl;
            break;
            case 2:
            cout << "You gazes at the beautiful starry scene in front of you before continuing your journey." <<endl;
            break;
     }
    
     if (turn==2)
     {
     hp2+=10; //resting increase hp
     if (hp2>100)
        hp2=100;
     cout << "Increase hp by 10.\nCurrent hp2: " << hp2 << endl;
     }//if
     else if (turn==1||turn==0)
     {
     hp+=10; //resting increase hp
     if (hp>100)
        hp=100;
     cout << "Increase hp by 10.\nCurrent hp: " << hp << endl;
     }//else
}
//======================================================================================================
//portal function
void portal(int turn)
{
     cout << "You are unlucky enough to get sucked in into a wormhole." << endl
          << "It sends you somewhere around the universe." << endl;
        
     int polarity=(rand() % 2 + 1);
     if (polarity==2)
          step=dice();
     else
          step=(-1)*dice();
        
     system("PAUSE");
     system("cls");
     if (turn==2)
     {
   world.board[(current_i2)][(current_j2)]="       ";
   current_j2=current_j2+step;
   if (current_j2>=col)
   {
current_j2=current_j2-col;
     current_i2++;
   }
   world.board[(current_i2)][(current_j2)]="  P 2  ";}
     else
     {
   world.board[(current_i)][(current_j)]="       ";
   current_j=current_j+step;
   if (current_j>=col)
   {
current_j=current_j-col;
     current_i++;
   }
   world.board[(current_i)][(current_j)]="  P 1  ";
   }
   displayBoard();
}
//======================================================================================================
//battle mode = battle()+win()+lose()
int battle(int turn)
{
    if (turn==2)
    {hp2+=1; //for first battle, hp will be 20. every next battle, hp increase by 1 simulating hp regeneration
    ehp=30;
    labelbattle2:
    mp2++; //mp regeneration
    cout << "Enemy HP: " << ehp << endl;
    cout << "Your  HP2: " <<  hp2 << endl;
    cout << "Your  MP2: " <<  mp2 << endl;
    cout << "(1) Attack" << endl;
    cout << "(2) Use Force[10MP]" << endl;
    cout << "(3) Heal[2MP]"<< endl;
  
    cin >> move;
    system("cls");
    if (move>=1&&move<=3)
    { cout << "Status:" << endl; wait(0.2);
        switch (move)
        {
            case 1:
                if ((rand() % 3 + 1)==1)
                   {cout<<"You managed to come close enough to punched him in the face.[ehp-1]"<<endl; ehp-=1;}
                else if ((rand() % 3 + 1)==2)        
                   {cout<<"You shot him from distance using your rifle.[ehp-2]"<<endl; ehp-=2;}
                else
                   {cout<<"You sliced him skillfully with your sword.[ehp-3]"<<endl; ehp-=3;}
                break;
            case 2:
                if (mp2>=10)
                {
                  int a=(rand() % 5 + 1);
                   cout<<"You used your force and pushed him back, hurting him in the process.[ehp-"<<a<<",mp2-10]"<<endl;
                   ehp-=a;
                   mp2-=10;
                }
                else
                {
                    cout<<"You don't have enough mp to use your force ability."<<endl;
                }
                break;
            case 3:
                if (mp2>=2)
                {
                cout<<"You patched yourself quickly in the midst of battle.[hp2+4,mp2-2]"<<endl;
                hp2+=4;
                mp2-=2;
                    if (hp2>100)
                       hp2=100;
                }
                else
                {
                    cout<<"You don't have enough mp to heal yourself."<<endl;
                }
            }//switch(move)
            wait(0.2);
        if (ehp<=0)
         {   win(); return 1;}
        else
        {
             emove=(rand() % 3 + 1);
             wait(0.2);
             if (emove==1)
             {   cout << "The enemy shot you using his laser rifle.[hp2-1]" << endl; hp2-=1;}
             else if (emove==2)        
             {   cout << "The enemy charged at you and pushed you onto the walls.[hp2-2]" <<endl; hp2-=2;}
             else if (emove==3)
             {   cout << "The enemy healed himself.[ehp+2]"<<endl; ehp+=2;}
             wait(0.2);
        }
    if (hp2<=0)
    {   lose(turn);
        return 0;}
    }//if (1<move<3
    else
    {
        cin.clear(); // reset the state bits back to goodbit so we can use ignore()
        cin.ignore(1000, '\n'); // clear out the bad input from the stream

        cerr<<"Wrong input. Enter 1,2 or 3."<<endl;
        wait(0.2);
       system("PAUSE");cout<<endl;
       system("cls");}
    goto labelbattle2;}//if
    else{
    hp+=1; //for first battle, hp will be 20. every next battle, hp increase by 1 simulating hp regeneration
    ehp=30;
    label:
    mp++; //mp regeneration
    cout << "Enemy HP: " << ehp << endl;
    cout << "Your  HP: " <<  hp << endl;
    cout << "Your  MP: " <<  mp << endl;
    cout << "(1) Attack" << endl;
    cout << "(2) Use Force[10MP]" << endl;
    cout << "(3) Heal[2MP]"<< endl;
  
    cin >> move;
    system("cls");
    if (move>=1&&move<=3)
    { cout << "Status:" << endl; wait(0.2);
        switch (move)
        {
            case 1:
                if ((rand() % 3 + 1)==1)
                   {cout<<"You managed to come close enough to punched him in the face.[ehp-1]"<<endl; ehp-=1;}
                else if ((rand() % 3 + 1)==2)        
                   {cout<<"You shot him from distance using your rifle.[ehp-2]"<<endl; ehp-=2;}
                else
                   {cout<<"You sliced him skillfully with your sword.[ehp-3]"<<endl; ehp-=3;}
                break;
            case 2:
                if (mp>=10)
                {
                  int a=(rand() % 5 + 1);
                   cout<<"You used your force and pushed him back, hurting him in the process.[ehp-"<<a<<",mp-10]"<<endl;
                   ehp-=a;
                   mp-=10;
                }
                else
                {
                    cout<<"You don't have enough mp to use your force ability."<<endl;
                }
                break;
            case 3:
                if (mp>=2)
                {
                cout<<"You patched yourself quickly in the midst of battle.[hp+4,mp-2]"<<endl;
                hp+=4;
                mp-=2;
                    if (hp>100)
                       hp=100;
                }
                else
                {
                    cout<<"You don't have enough mp to heal yourself."<<endl;
                }
            }//switch(move)
            wait(0.2);
        if (ehp<=0)
         {   win(); return 1;}
        else
        {
             emove=(rand() % 3 + 1);
             wait(0.2);
             if (emove==1)
             {   cout << "The enemy shot you using his laser rifle.[hp-1]" << endl; hp-=1;}
             else if (emove==2)        
             {   cout << "The enemy charged at you and pushed you onto the walls.[hp-2]" <<endl; hp-=2;}
             else if (emove==3)
             {   cout << "The enemy healed himself.[ehp+2]"<<endl; ehp+=2;}
             wait(0.2);
        }
    if (hp<=0)
    {   lose(turn);
        return 0;}
    }//if (1<move<3
    else
    {
        cin.clear(); // reset the state bits back to goodbit so we can use ignore()
        cin.ignore(1000, '\n'); // clear out the bad input from the stream

        cerr<<"Wrong input. Enter 1,2 or 3."<<endl;
        wait(0.2);
       system("PAUSE");cout<<endl;
       system("cls");}
    goto label;
    }//else
    }
//======================================================================================================
//win()
void win(void)
{
     cout<<endl<<"You win!" << endl;
     system("PAUSE");
}
//======================================================================================================
//lose()
void lose(int turn)
{
     cout<<endl<<"You lost...\nGAME OVER" << endl;
     if (player=2)
     {
        switch(turn)
        {case 2: cout<<"Player 1 Win,Player 2 Lose";break;
        case 1: cout<<"Player 2 Win,Player 1 Lose"; break;
        }
     }
        cout << endl;
          system("PAUSE");
          system("cls");
          main();
}
//======================================================================================================
//question functions-question(),initializeQuestion(),initializeStatus()
int question (void)
{
    while(1){
//label2:
int randomQuestion=( (rand()) % size_question); //randomize the questions
if (questions[randomQuestion].status==1)
  continue;//goto label2;
char answer;
cout<<questions[randomQuestion].q<<endl;
cout<<"Your answer: ";
cin>>answer;
answer=toupper(answer);
if (answer == questions[randomQuestion].ans)//...
{ cout<<endl<<"That's correct!"<<endl; questions[randomQuestion].status=1;
    return 1;
    }
else
cout<<endl<<"That's wrong..."<<endl;
system("Pause");
system("cls");}
//goto label2;
}
//=================
//list of questions
void initializeQuestion (void)
{
questions[0].q="There are many theories about the birth of our solar system. Which theory involves a passing star pulling dust and debris from the forming sun?\n\tA: Nebular Hypothesis\n\tB: Tidal Theory\n\tC: Collision Theory\n\tD: Protoplanet Hypothesis";
questions[0].ans='B';
questions[1].q="The planets make up what percentage of the mass in our solar system?\n\tA: 0.0135 %\n\tB: 0.135 %\n\tC: 1.35 %\n\tD: 13.5 %";
questions[1].ans='B';
  questions[2].q="What are the only two planets in our solar system without moons?\n\tA: Mercury & Venus\n\tB: Venus & Mars\n\tC: Uranus & Neptune\n\tD: Neptune & Pluto";
questions[2].ans='A';
questions[3].q="What is the name of Pluto's moon?\n\tA: Charon\n\tB: Phobus\n\tC: Pandora\n\tD: Nereid";
questions[3].ans='A';
questions[4].q="The three main parts of a comet are the nucleus, the tail, and the _____?\n\tA: Zenith\n\tB: Umbra\n\tC: Radiant\n\tD: Coma";
questions[4].ans='D';
questions[5].q="What year boasted the first woman in space?\n\tA: 1963\n\tB: 1968\n\tC: 1973\n\tD: 1983";
questions[5].ans='A';
questions[6].q="What is the term for the condition when three celestial bodies are arranged in a straight line?\n\tA: Occultation\n\tB: Parallax\n\tC: Syzygy\n\tD: Triple Transit";
questions[6].ans='C';
questions[7].q="Which of the following was discovered in 2002?\n\tA: Nereid\n\tB: Varuna\n\tC: Titan\n\tD: Quaoar";
questions[7].ans='D';
questions[8].q="What manned U.S. space program eventually put 12 men on the Moon?\n\tA: Apollo\n\tB: Gemini\n\tC: Mercury\n\tD: Voyager";
questions[8].ans='A';
questions[9].q="From 1978 to 1999, which planet was farthest from the Sun?\n\tA: Pluto\n\tB: Neptune\n\tC: Uranus\n\tD: Saturn";
questions[9].ans='B';
questions[10].q="What was the very first personal computer?\n\tA: TRS-80\n\tB: Commodore PET\n\tC: Kenbak-1\n\tD: Apple I";
questions[10].ans='C';
questions[11].q="What year was the word \"computer\" first used to describe a mechanical calculating device?\n\tA: 1897\n\tB: 1912\n\tC: 1926\n\tD: 1942";
    questions[11].ans='A';
questions[12].q="What was the first portable computer?\n\tA: Epson HX-20\n\tB: Cray I\n\tC: Osborne I\n\tD: IBM 5155";
    questions[12].ans='C';
questions[13].q="During the 1970s computer engineers at various research institutions began to utilize telecommunications technologies to link their computers together. This effort, the forefather of the modern Internet, was known as the ...\n\tA: INSTANET\n\tB: ARPANET\n\tC: ORDONET\n\tD: BAYONET";
    questions[13].ans='B';
questions[14].q="What was the first computer to defeat a world champion chess player?\n\tA: Chinook\n\tB: X3D Fritz\n\tC: Deep Blue\n\tD: A.L.I.C.E.";
    questions[14].ans='C';
questions[15].q="What computer device did Douglas Engelbart invent in 1963?\n\tA: Modem\n\tB: Mouse\n\tC: Floppy disk\n\tD: Microchip";
    questions[15].ans='B';
questions[16].q="What \"law\" describes the fact that, on average, computers have doubled in capacity every 18 to 24 months since 1900?\n\tA: Anderson's Law\n\tB: Moore's Law\n\tC: Jefferson's Law\n\tD: Bohr's Law";
    questions[16].ans='B';
questions[17].q="How many lines of code did the Windows 98 operating system contain?\n\tA: 4 million\n\tB: 9 million\n\tC: 18 million\n\tD: 40 million";
    questions[17].ans='C';
questions[18].q="What was the first commercially successful vector processor?\n\tA: Cray I\n\tB: HP-2115\n\tC: Altair 8800\n\tD: Apple I";
    questions[18].ans='A';
questions[19].q="What new product did Apple Computer launch with a $1.5 million commercial during the 1984 Super Bowl?\n\tA: Apple I\n\tB: Apple IIe\n\tC: Apple IIc\n\tD: Macintosh";
    questions[19].ans='D';
questions[20].q="Mt. Fuji is the highest point in what Asian country?\n\tA: Bangladesh\n\tB: Burma\n\tC: China\n\tD: Japan";
    questions[20].ans='D';
questions[21].q="What is western Asia's longest river?\n\tA: Tigris\n\tB: Euphrates\n\tC: Xi Jiang\n\tD: Kurobe";
    questions[21].ans='B';
questions[22].q="What tiny country, known to its inhabitants as Druk Yul (Land of the Thunder Dragon), is sandwiched between China and India?\n\tA: Bhutan\n\tB: Bangladesh\n\tC: Mongolia\n\tD: Burma";
    questions[22].ans='A';
questions[23].q="What mountain range runs along the northern border of India?\n\tA: Urul Mountains\n\tB: Tatra Mountains\n\tC: Xiao Hinggan Ling Mountains\n\tD: Himalayan Mountains";
    questions[23].ans='D';
questions[24].q="Korea is separated from Japan by what strait?\n\tA: Cheju\n\tB: Tsushima\n\tC: Gibraltar\n\tD: Bungo";
    questions[24].ans='B';
questions[25].q="What Chinese city is situated at the mouth of the Chang Jiang (Yangtze) River?\n\tA: Shanghai\n\tB: Beijing\n\tC: Taipei\n\tD: Changchun";
    questions[25].ans='A';
questions[26].q="What is the tallest mountain in Asia?\n\tA: Qogir\n\tB: Kangchenjunga\n\tC: Cho Oyu\n\tD: Mount Everest";
    questions[26].ans='D';
questions[27].q="Iran is slightly larger than what U.S. state?\n\tA: Rhode Island\n\tB: Montana\n\tC: Texas\n\tD: Alaska";
    questions[27].ans='D';
questions[28].q="What Japanese city is the site of the Peace Memorial Park and the eternal Peace Flame which is never to be extinguished until all nuclear weapons are dismantled?\n\tA: Hiroshima\n\tB: Nagasaki\n\tC: Tokyo\n\tD: Kyoto";
    questions[28].ans='A';
questions[29].q="What is the capital of Afghanistan?\n\tA: Teheran\n\tB: Kandahar\n\tC: Baghdad\n\tD: Kabul";
    questions[29].ans='D';
    questions[30].q="When was the idea of the atom first introduced?\n\tA: 450 B.C.\n\tB: 1050\n\tC: 1791\n\tD: 1942";
    questions[30].ans='A';
    questions[31].q="In 2004, what was discovered on the island of Flores in Indonesia?\n\tA: A living dinosaur\n\tB: Remains of a hobbit-sized human species\n\tC: A tribe whose members commonly live over 150 years\n\tD: A plant with a mammal-like brain";
    questions[31].ans='B';
    questions[32].q="An earthquake that measures 8 on the Richter Scale would be how many times stronger than an earthquake that measures 4 on the same scale?\n\tA: 2 times stronger\n\tB: 4 times stronger\n\tC: 1000 times stronger\n\tD: 10,000 times stronger";
    questions[32].ans='D';
    questions[33].q="What is the gestation period of an Hippopotamus?\n\tA: 4 months\n\tB: 8 months\n\tC: 12 months\n\tD: 16 months";
    questions[33].ans='B';
    questions[34].q="What physicist discovered that a wave's frequency changes when the source and the observer are in motion relative to one another?\n\tA: Max Planck\n\tB: Christian Doppler\n\tC: Enrico Fermi\n\tD: Albert Einstein";
    questions[34].ans='B';
    questions[35].q="In what type of matter are atoms most tightly packed?\n\tA: Solids\n\tB: Liquids\n\tC: Gases\n\tD: All are the same";
    questions[35].ans='A';
    questions[36].q="Which of the following means \"rain\" when added to a cloud's name?\n\tA: Alto\n\tB: Nimbus\n\tC: Strato\n\tD: Cirrus";
    questions[36].ans='B';
    questions[37].q="What is the longest river in the world?\n\tA: Amazon\n\tB: Nile\n\tC: Congo\n\tD: Chang Jiang";
    questions[37].ans='B';
    questions[38].q="How many brains did a Stegosaurus have?\n\tA: One\n\tB: Two\n\tC: Three\n\tD: None";
    questions[38].ans='A';
    questions[39].q="What instrument is used to measure wind speed?\n\tA: Anemometer\n\tB: Barometer\n\tC: Altimeter\n\tD: Fanometer";
    questions[39].ans='A';

    initializeStatus ();
}

void initializeStatus (void)
{
     for ( i=0; i<size_question; i++)
   questions[i].status=0;
}
//======================================================================================================
//dice function
int dice(void)
{
    return rand() % 6 + 1;
}
//stepping around board-slow motion
void slowstepsBoard(int step)
{
     //new code
     world.board[current_i][current_j]="       ";
     for (int count=0;count<=step;count++,current_j++)
     {
         system("cls");
         if (current_i==row||(current_i==row&&current_j==col))//when reach destination or over it, assign to
         {
         world.board[current_i][current_j]="       ";
         world.board[8][7]="  P 1  ";   //last destination and break out of loop
         if((player==2))
                  {world.board[current_i2][current_j2]="  P 2  ";}
         displayBoard();
         break;
         }
         if (current_j>=col)
         {
current_j=current_j-col;
     current_i++;
         }
         world.board[current_i][current_j]="  P 1  ";
         if((player==2))
                  {world.board[current_i2][current_j2]="  P 2  ";}
         displayBoard();
         world.board[current_i][current_j]="       ";
         wait(0.2);
     }//for
     current_j--;
}

Saturday, October 2, 2010

start working as programmer

I have been learning programming C++ for a year now. I feel that I have sufficient basic knowledge to write code, but restricted to lab assignment given to me by lecturer may not enough. Or rather, I want to start writing programs not for university works. I want to gain more experience now, as part of my wish to be a hacker.

Maybe I should be volunteering for open source project. But I wonder if I am able to? And I don't know where.

>.>

Google. I will google it. damnit, why did I forget that?

Multiplayer?

I finally code the slowstepmotion to work correctly. Currently, the game is quite complete, with questions finally added. I used trivia for questions from fields of astronomy, computer and asian geographic for now. The questions give 4 choices of answer, player answer by giving input of A, B, C or D.

The main problem now is Multiplayer mode. We were focusing on single player too much, I have a hard time figuring how to make it work for multiplayer mode. Putting string "   P 1   " is a bad idea as I thought.

Anyway, I will be researching a bit about turn-based game involving two players and a board. Like chess.

/*
**GAME TITLE: GameAdv
**A Game For Windows
**Copyright 2010 [@zri & ZomBiedy]
*/
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX 100
using namespace std;

struct GAME
{                            //struct definition
char menu[15];
};

const int row=9,col=8;
int i,j,current_i,current_j,step;                  //global variables
GAME advGame[MAX];
int no_menu;
int hp=20, mp=20, ehp=30, move, emove;
const int size_question=30;//to make it really random, try to get around 70 questions
int LimitBattle=35; //limiting battle to only 35
int LimitRest = 20; //limiting resting to only 20

struct WORLD                                       //world of the game
{
    char* board[row][col];                         //the board, or the playing field
    int game_element[row][col];                    //1 resting,2 question,3 portal/jump,4 battle
}world;                                            //note: make game_element at [0][0],[row-1][col-1]

struct QUESTIONS
{
string q;
char ans;
int status; //keep status of being answer or not. if already use, value 1
}questions[size_question];

//function prototypes
int dice(void);
void intBoard(void);
void intgame_element(void);
void displayBoard(void);
void slowstepsBoard(int step);
void initialMenu(GAME advGame[MAX]);
void GameStart(int player);
void S_player(void);
void M_player(void);                            
void newGame(void);
void guideline(void);
void credit(void);
void selectMenu(int no_menu);
void displayMenu(GAME advGame[]);
void wait(float seconds);
void rest(void);
void portal(void);
int battle (void);
void win(void);
void lose(void);
int question(void);
void initializeQuestion (void);
void initializeStatus (void);

//======================================================================================================

//PRIMARY MAIN FUNCTION
int main(void)
{
   //WORLD world;
   srand(time(NULL)) ;             //set rand to use time as seed
  
   initialMenu(advGame);
   displayMenu(advGame);    //display game menu
   cout<<"\n Enter Number: ";             //choose menu
   cin>>no_menu;
   system("cls");
   selectMenu(no_menu);
   getch();
}
//======================================================================================================
//create game menu function (initialize)
void initialMenu(GAME advGame[MAX])
{
   strcpy(advGame[0].menu,". NEW GAME");
   strcpy(advGame[1].menu,". GUIDELINE");
   strcpy(advGame[2].menu,". ABOUT");
   strcpy(advGame[3].menu,". EXIT");
}
//======================================================================================================
//display game menu
void displayMenu(GAME advGame[MAX])
{
cout<<"\n Game Title : "<<endl<<" Team : Mytho (Legend) "    <<endl<<" By : @zrI & ZomBiedy "<<endl<<"\n GAME MENU:"<<endl;
   for(int i=0;i<4;i++)
   cout<<"\t"<<(i+1)<<advGame[i].menu<<endl;
}
//======================================================================================================
void selectMenu(int no_menu)
{
  if(no_menu==1)
   newGame();
   else if(no_menu==2)
   guideline();
   else if(no_menu==3)
   credit();
   else if(no_menu==4)
      cout<<" EXIT "<<endl;
   else
      cout<<" Wrong number entered"<<endl;
}
//======================================================================================================
void newGame()
{
int mode;
   system("cls");
  cout<<"\n SELECT M0DE:"<<endl<<"\t1) Single Player "<<endl<<"\t2) Multi Player "<<endl;
   cout<<" Enter Mode: ";
   cin>>mode;
   if(mode==1)
   S_player();
   else if(mode==2)
   { cout<<" Multi Player"<<endl;
   M_player();}
   else
   cout<<" Wrong mode entered"<<endl;
}
//======================================================================================================
void guideline()
{
cout << " GAME GUIDELINE:"<<endl;
cout << "This game best played when the window are maximised." << endl << endl;
cout << "There are two modes available: Single Player and Multiplayer. Multiplayer allows two players to play in the same round of the game, by taking turns." <<endl
         << "This game involves moving around the space grids using a dice. There will be 4 elements: Questions, Portal, Resting Place and Battle."<<endl << endl
         << "Questions:" <<endl
         << "Various questions will be asked and player(s) must answer the questions before continue with the journey.[there will be three chances of answering before resulting in a end game."<<endl
         << endl
         << "Portal:" <<endl
         << "Player(s) may encounter portal that will send player(s) back or forth randomly using dice number."<<endl
         << endl
         << "Resting Place:" <<endl
         << "This is a place where you can rest a bit and heal some hp." <<endl
         << endl
         << "Battle:" << endl
         << "You may encounter enemy that stops you from continuing with your journey. You can attack, use force or heal. Using force and heal require MP, so keep your MP in check before using it. Death from battle will result in game over."<<endl;

system("PAUSE");
system("cls");
   displayMenu(advGame);
   cout<<"\n Enter Number: ";             //choose menu
   cin>>no_menu;
   system("cls");
   selectMenu(no_menu);

}
//======================================================================================================
void credit()
{
cout<<" ABOUT GAME:"<<endl;
   cout<<"\n This two (2) dimensional game has been created by 2 UiTM student (Diploma"<<endl<<" in Computer Science) named; Muhammad Azri bin Jasni (@zri) and his friend,"<<endl;
   cout<<" Mohd Zabiedy bin Mohd Sulaiman (ZomBiedy)."<<endl<<" \n\tThe game has been done as an Laboratory Assignment for CSC 138 - "<<endl;
   cout<<" Structured Programming during Semester July - September 2010. One of the"<<endl<<" objective of this assignment is to determine whether computer science (part 2)"<<endl;
   cout<<" understand the concept of structured programming,its component and also know"<<endl<<" how is applying them."<<endl;
   system("PAUSE");
   system("cls");
   displayMenu(advGame);
   cout<<"\n Enter Number: ";             //choose menu
   cin>>no_menu;
   system("cls");
   selectMenu(no_menu);
}
//======================================================================================================
void S_player()
{
   system("cls");
  cout<<"\n You are playing SINGLE MODE."<<endl;
  system("PAUSE");
   GameStart(1);
   displayMenu(advGame);
   cout<<"\n Enter Number: ";             //choose menu
   cin>>no_menu;
   system("cls");
   selectMenu(no_menu);
}
//======================================================================================================
void M_player()
{
     system("cls");
  cout<<"\n You are playing MULTIPLAYER MODE."<<endl;
  system("PAUSE");
//  GameStart(2);
   system("cls");
   displayMenu(advGame);
   cout<<"\n Enter Number: ";             //choose menu
   cin>>no_menu;
   system("cls");
   selectMenu(no_menu);
}
//======================================================================================================
//starting of game
void GameStart(int player)
{
int no_menu;
intBoard();
intgame_element();
initializeQuestion ();
   system("cls");
   cout<<"\n GAME START !!!...GOOD LUCK"<<endl;                                 //initialize board
   displayBoard();
   while(strcmp(world.board[8][7],"  P 1  ")!=0)
   { cout<<" Press any key to roll the dice.";
      getch();                                                     //display board
      step=dice();                               //get dice value and save as step
      system("cls");
      slowstepsBoard(step);                          //move P1 on board according to the step
      //display dice value
     cout<<endl<<" Your dice value: "<<step<<endl;
      switch (world.game_element[current_i][current_j])
      {
             case 1:
                  cout<<endl<<"Resting Place"<<endl;
                  rest();
                  break;
             case 2:
                  cout<<endl<<"Question"<<endl;
                  question();
                  break;
             case 3:
                  cout<<endl<<"Portal"<<endl;
                  portal();
                  break;
             case 4:
                  cout<<endl<<"Battle"<<endl;
                  battle();
                  displayBoard();
                  break;
      }
   }//loop, not good
   cout<<" Congratulation !!!..You Finish The Game..."<<endl
       <<" See You Again..Thank You."<<endl<<" Back to Game Menu "<<endl;
   system("PAUSE");
   system("cls");
   displayMenu(advGame);
   cout<<"\n Enter Number: ";             //choose menu
   cin>>no_menu;
   system("cls");
   selectMenu(no_menu);
}

//======================================================================================================
//dice function
int dice(void)
{
    return rand() % 6 + 1;
}
//======================================================================================================
//initialize board
void intBoard(void)
{
    for(i=0;i<row;i++)
     for(j=0;j<col;j++)
       world.board[i][j]    ="       ";
    world.board[0][0]        =" START ";
    world.board[row-1][col-1]="  END  ";
    current_i=0; current_j=0;
}
//======================================================================================================
//initialize game_element
void intgame_element(void)
{
     for (i=0;i<row;i++)
         for (j=0;j<col;j++)
       {
             int countLimitBattle=0;
             int countLimitRest=0;
             world.game_element[i][j]=rand() % 4 + 1;
             label4:
             if (world.game_element[i][j]==1)
             {
             if (countLimitRest==LimitRest)
                {world.game_element[i][j]=rand() % 4 + 1;
                goto label4;}
             else
              countLimitRest++;
             }
             label3:
             if (world.game_element[i][j]==4)
             {
             if (countLimitBattle==LimitBattle)
                {world.game_element[i][j]=rand() % 4 + 1;
                goto label3;}
             else
              countLimitBattle++;
             }
         }
world.game_element[row][col]=0; world.game_element[0][0]=0;
}
//======================================================================================================
//show game board
void displayBoard(void)
{
   world.board[0][0]=" START ";
   wait(0.2);
for(i=0;i<row;i++)
   { cout<<endl;
     for(j=0;j<(col);j++)
         cout<<"========";
      cout<<endl<<'|';
      if (i%2==1)
       for(j=(col-1);j>=0;j--)
         cout<<world.board[i][j]<<'|';
      else
       for(j=0;j<col;j++)
          cout<<world.board[i][j]<<'|';
   }
   cout<<endl;
   for(j=0;j<(col);j++)
         cout<<"========";
     cout<<endl;
}
//======================================================================================================
//stepping around board-slow motion
void slowstepsBoard(int step)
{
     //new code
     world.board[current_i][current_j]="       ";
     for (int count=0;count<=step;count++,current_j++)
     {
         system("cls");
         if (current_i==row||(current_i==row&&current_j==col))//when reach destination or over it, assign to
         {
         world.board[current_i][current_j]="       ";
         world.board[8][7]="  P 1  ";   //last destination and break out of loop
         displayBoard();
         break;
         }
         if (current_j>=col)
         {
current_j=current_j-col;
     current_i++;
         }
         world.board[current_i][current_j]="  P 1  ";
         displayBoard();
         world.board[current_i][current_j]="       ";
         wait(0.2);
         //a little problem when dealing with negative value portal
     }//for
     current_j--;
}
//======================================================================================================
//to slow down the display of the board
void wait(float seconds)
{
     //error converting clock_t from float
     //error didn't seems to affect gameplay
  clock_t endwait;
  endwait=clock()+seconds*CLOCKS_PER_SEC;
  while(clock()<endwait){}   // jarak antara nombor yang akan dipaparkan
}
//======================================================================================================
//resting function
void rest(void)
{
     //random comments in resting place element
     int randRest = rand() % 2 + 1;
     switch (randRest)
     {
            case 1:
            cout << "You found a space cafe and decided to have a tea before proceed with your adventure."<<endl;
            break;
            case 2:
            cout << "You gazes at the beautiful starry scene in front of you before continuing your journey." <<endl;
            break;
     }
     hp+=10; //resting increase hp
     if (hp>100)
        hp=100;
     cout << "Increase hp by 10.\nCurrent hp: " << hp << endl;
}
//======================================================================================================
//portal function
void portal(void)
{
     cout << "You are unlucky enough to get sucked in into a wormhole." << endl
          << "It sends you somewhere around the universe." << endl;
        
     int polarity=(rand() % 2 + 1);
     if (polarity==2)
          step=dice();
     else
          step=(-1)*dice();
        
     system("PAUSE");
     system("cls");
   world.board[(current_i)][(current_j)]="       ";
   current_j=current_j+step;
   if (current_j>=col)
   {
current_j=current_j-col;
     current_i++;
   }
   world.board[(current_i)][(current_j)]="  P 1  ";
   displayBoard();
     //slowstepsBoard(step);
}
//======================================================================================================
//battle mode -battle(),win(),lose()
int battle(void)
{
    hp+=5; //for first battle, hp will be 20. every next battle, hp increase by 5 simulating hp regeneration
    ehp=30;
    label:
    mp++; //mp regeneration
    cout << "Enemy HP: " << ehp << endl;
    cout << "Your  HP: " <<  hp << endl;
    cout << "Your  MP: " <<  mp << endl;
    cout << "(1) Attack" << endl;
    cout << "(2) Use Force[10MP]" << endl;
    cout << "(3) Heal[2MP]"<< endl;
  
    cin >> move;
    system("cls");
    if (move>=1&&move<=3)
    { cout << "Status:" << endl;
        switch (move) //note: when lose, end game [still not code-written]
        {
            case 1:
                if ((rand() % 3 + 1)==1)
                   {cout<<"You managed to come close enough to punched him in the face."<<endl; ehp-=1;}
                else if ((rand() % 3 + 1)==2)        
                   {cout<<"You shot him from distance using your rifle."<<endl; ehp-=2;}
                else
                   {cout<<"You sliced him skillfully with your sword."<<endl; ehp-=3;}
                break;
            case 2:
                if (mp>=10)
                {
                   cout<<"You used your force and pushed him back, hurting him in the process."<<endl;
                   ehp-=(rand() % 5 + 1);
                   mp-=10;
                }
                else
                {
                    cout<<"You don't have enough mp to use your force ability."<<endl;
                }
                break;
            case 3:
                if (mp>=2)
                {
                cout<<"You patched yourself quickly in the midst of battle."<<endl;
                hp+=4;
                mp-=2;
                    if (hp>100)
                       hp=100;
                }
                else
                {
                    cout<<"You don't have enough mp to heal yourself."<<endl;
                }
            }//switch(move)
        if (ehp<=0)
         {   win(); return 1;}
        else
        {
             emove=(rand() % 3 + 1);
            
             if (emove==1)
             {   cout << "The enemy shot you using his laser rifle." << endl; hp-=1;}
             else if (emove==2)        
             {   cout << "The enemy charged at you and pushed you onto the walls." <<endl; hp-=2;}
             else if (emove==3)
             {   cout << "The enemy healed himself."<<endl; ehp+=2;}
        }
    if (hp<=0)
    {   lose();
        return 0;}
    }//if (1<move<3)
    else
    {
        cerr<<"Wrong input. Enter 1,2 or 3."<<endl;
       system("PAUSE");cout<<endl;
       system("cls");}
    goto label;}
void win(void)
{
     cout<<endl<<"You win!";
     system("PAUSE");
}

void lose(void)
{
     cout<<endl<<"You lost...\nGAME OVER";
          system("PAUSE");
          system("cls");
          main();
}
//======================================================================================================
//question functions-question(),initializeQuestion(),initializeStatus()
int question (void)
{
    while(1){
//label2:
int randomQuestion=( (rand()) % size_question); //randomize the questions
if (questions[randomQuestion].status==1)
  continue;//goto label2;
char answer;
cout<<questions[randomQuestion].q<<endl;
cout<<"Your answer: ";
cin>>answer;
answer=toupper(answer);
if (answer == questions[randomQuestion].ans)//...
{ cout<<endl<<"That's correct!"<<endl; questions[randomQuestion].status=1;
    return 1;
    }
else
cout<<endl<<"That's wrong..."<<endl;
system("Pause");
system("cls");}
//goto label2;
}
//=================
//list of questions
void initializeQuestion (void)
{
questions[0].q="There are many theories about the birth of our solar system. Which theory involves a passing star pulling dust and debris from the forming sun?\n\tA: Nebular Hypothesis\n\tB: Tidal Theory\n\tC: Collision Theory\n\tD: Protoplanet Hypothesis";
questions[0].ans='B';
questions[1].q="The planets make up what percentage of the mass in our solar system?\n\tA: 0.0135 %\n\tB: 0.135 %\n\tC: 1.35 %\n\tD: 13.5 %";
questions[1].ans='B';
questions[2].q="What are the only two planets in our solar system without moons?\n\tA: Mercury & Venus\n\tB: Venus & Mars\n\tC: Uranus & Neptune\n\tD: Neptune & Pluto";
questions[2].ans='A';
questions[3].q="What is the name of Pluto's moon?\n\tA: Charon\n\tB: Phobus\n\tC: Pandora\n\tD: Nereid";
questions[3].ans='A';
questions[4].q="The three main parts of a comet are the nucleus, the tail, and the _____?\n\tA: Zenith\n\tB: Umbra\n\tC: Radiant\n\tD: Coma";
questions[4].ans='D';
questions[5].q="What year boasted the first woman in space?\n\tA: 1963\n\tB: 1968\n\tC: 1973\n\tD: 1983";
questions[5].ans='A';
questions[6].q="What is the term for the condition when three celestial bodies are arranged in a straight line?\n\tA: Occultation\n\tB: Parallax\n\tC: Syzygy\n\tD: Triple Transit";
questions[6].ans='C';
questions[7].q="Which of the following was discovered in 2002?\n\tA: Nereid\n\tB: Varuna\n\tC: Titan\n\tD: Quaoar";
questions[7].ans='D';
questions[8].q="What manned U.S. space program eventually put 12 men on the Moon?\n\tA: Apollo\n\tB: Gemini\n\tC: Mercury\n\tD: Voyager";
questions[8].ans='A';
questions[9].q="From 1978 to 1999, which planet was farthest from the Sun?\n\tA: Pluto\n\tB: Neptune\n\tC: Uranus\n\tD: Saturn";
questions[9].ans='B';
questions[10].q="What was the very first personal computer?\n\tA: TRS-80\n\tB: Commodore PET\n\tC: Kenbak-1\n\tD: Apple I";
questions[10].ans='C';
questions[11].q="What year was the word \"computer\" first used to describe a mechanical calculating device?\n\tA: 1897\n\tB: 1912\n\tC: 1926\n\tD: 1942";
    questions[11].ans='A';
questions[12].q="What was the first portable computer?\n\tA: Epson HX-20\n\tB: Cray I\n\tC: Osborne I\n\tD: IBM 5155";
    questions[12].ans='C';
questions[13].q="During the 1970s computer engineers at various research institutions began to utilize telecommunications technologies to link their computers together. This effort, the forefather of the modern Internet, was known as the ...\n\tA: INSTANET\n\tB: ARPANET\n\tC: ORDONET\n\tD: BAYONET";
    questions[13].ans='B';
questions[14].q="What was the first computer to defeat a world champion chess player?\n\tA: Chinook\n\tB: X3D Fritz\n\tC: Deep Blue\n\tD: A.L.I.C.E.";
    questions[14].ans='C';
questions[15].q="What computer device did Douglas Engelbart invent in 1963?\n\tA: Modem\n\tB: Mouse\n\tC: Floppy disk\n\tD: Microchip";
    questions[15].ans='B';
questions[16].q="What \"law\" describes the fact that, on average, computers have doubled in capacity every 18 to 24 months since 1900?\n\tA: Anderson's Law\n\tB: Moore's Law\n\tC: Jefferson's Law\n\tD: Bohr's Law";
    questions[16].ans='B';
questions[17].q="How many lines of code did the Windows 98 operating system contain?\n\tA: 4 million\n\tB: 9 million\n\tC: 18 million\n\tD: 40 million";
    questions[17].ans='C';
questions[18].q="What was the first commercially successful vector processor?\n\tA: Cray I\n\tB: HP-2115\n\tC: Altair 8800\n\tD: Apple I";
    questions[18].ans='A';
questions[19].q="What new product did Apple Computer launch with a $1.5 million commercial during the 1984 Super Bowl?\n\tA: Apple I\n\tB: Apple IIe\n\tC: Apple IIc\n\tD: Macintosh";
    questions[19].ans='D';
questions[20].q="Mt. Fuji is the highest point in what Asian country?\n\tA: Bangladesh\n\tB: Burma\n\tC: China\n\tD: Japan";
    questions[20].ans='D';
questions[21].q="What is western Asia's longest river?\n\tA: Tigris\n\tB: Euphrates\n\tC: Xi Jiang\n\tD: Kurobe";
    questions[21].ans='B';
questions[22].q="What tiny country, known to its inhabitants as Druk Yul (Land of the Thunder Dragon), is sandwiched between China and India?\n\tA: Bhutan\n\tB: Bangladesh\n\tC: Mongolia\n\tD: Burma";
    questions[22].ans='A';
questions[23].q="What mountain range runs along the northern border of India?\n\tA: Urul Mountains\n\tB: Tatra Mountains\n\tC: Xiao Hinggan Ling Mountains\n\tD: Himalayan Mountains";
    questions[23].ans='D';
questions[24].q="Korea is separated from Japan by what strait?\n\tA: Cheju\n\tB: Tsushima\n\tC: Gibraltar\n\tD: Bungo";
    questions[24].ans='B';
questions[25].q="What Chinese city is situated at the mouth of the Chang Jiang (Yangtze) River?\n\tA: Shanghai\n\tB: Beijing\n\tC: Taipei\n\tD: Changchun";
    questions[25].ans='A';
questions[26].q="What is the tallest mountain in Asia?\n\tA: Qogir\n\tB: Kangchenjunga\n\tC: Cho Oyu\n\tD: Mount Everest";
    questions[26].ans='D';
questions[27].q="Iran is slightly larger than what U.S. state?\n\tA: Rhode Island\n\tB: Montana\n\tC: Texas\n\tD: Alaska";
    questions[27].ans='D';
questions[28].q="What Japanese city is the site of the Peace Memorial Park and the eternal Peace Flame which is never to be extinguished until all nuclear weapons are dismantled?\n\tA: Hiroshima\n\tB: Nagasaki\n\tC: Tokyo\n\tD: Kyoto";
    questions[28].ans='A';
questions[29].q="What is the capital of Afghanistan?\n\tA: Teheran\n\tB: Kandahar\n\tC: Baghdad\n\tD: Kabul";
    questions[29].ans='D';

    initializeStatus ();
}

void initializeStatus (void)
{
     for ( i=0; i<size_question; i++)
   questions[i].status=0;
}
//======================================================================================================