Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by Steve ( 15 years ago )
#include <iostream>
#include <fstream>
#include <time.h>
#include <string>
#include "Tile.h"

#define TILES (150)
#define MAX_LINE_CHARACTERS (50)

using namespace std;

//-----//Grid
static char playgrid[10][10];
int j, i;
int playerHealth = 7;
int nTile = 0;
CTile tiles [TILES];

//-----//Create Grid
void initGrid() {
 for(int i=0;i<10;i++){
 for(int j=0;j<10;j++){
  playgrid[i][j] = 'x';
 }
 }
}
void printGrid(char playgrid[10][10], int w, int h) {
 for (int i = 0; i < w; i++) {
 for (int j = 0; j < h; j++) {
  cout << playgrid[i][j] << " | ";
 }
 cout << endl;
 }
}

void loadField(){

//-----//campspellfield
 ifstream inFile; 
 char Xcor;
 char Ycor;
 char misc; 
 string type;
 string word1;
 string word2;
 string word3;
 string word4;
 char cluePos;
 int distance;
 int value;

 void CheckDictionary(char *filename);

 int numberOfPlus;
 numberOfPlus = 0;

inFile.open("CampSpellField.txt");

//-----//Array function
while(inFile >> misc >> Xcor >> misc >> Ycor >> misc >> misc >> type){
 if(type == "SPELL"){
  inFile >> misc >> word1 >> word2 >> word3 >> word4;
      word4.resize(3);
   CTile tmptile(Xcor,Ycor,type,word1,word2,word3,word4);
  tiles[nTile] = tmptile;
  nTile+=1;
 }
 else if(type == "RESTORE"){
  playerHealth = 7;
  CTile tmptile(Xcor,Ycor,type);
  tiles[nTile] = tmptile;
  nTile+=1;
   }
 
 else if(type == "CLUE"){
  inFile >> misc >> cluePos >> misc;
  CTile tmptile(Xcor,Ycor,type,cluePos);
  tiles[nTile] = tmptile;
  nTile+=1;
  }
 
 else if(type == "TRAP"){
  CTile tmptile(Xcor,Ycor,type);
  tiles[nTile] = tmptile;
  nTile+=1;
   }
 
 else if(type == "DISTANCE"){
  inFile >> misc >> distance >> misc;
  CTile tmptile(Xcor,Ycor,type,distance);
  tiles[nTile] = tmptile;
  nTile+=1;
   }

 else if(type == "WIN"){
  CTile tmptile(Xcor,Ycor,type);
  tiles[nTile] = tmptile;
  nTile+=1;
   }   
}

inFile.close();

inFile.open("MagicWordsDictionary.txt");
if(inFile.fail()){
 cerr << "MagicWordsDictionary.txt could not be loaded. " << endl;
 return 0;
}

for(int i=0;i<=nTile;i++){
   if(tiles[i].m_Xcor == playgrid[0][0] && tiles[i].m_Ycor == playgrid[1][0]){
     if(tiles[i].m_type=="SPELL"){      
    while (inFile.getline >> word >> value ){
    //Check with every word whether they have a plus and keep track of that amount
    if(tiles[i].m_word1==word){
     if(value == '+'){
      numberOfPlus +=1;
     }
    }
    else if(>tiles[i].m_word2==word){
     if(value == '+'){
      numberOfPlus +=1;
     }
    }
    else if(tiles[i].m_word3==word){
     if(value == '+'){
      numberOfPlus +=1;
     }
    }
    else if(tiles[i].m_word4==word){
     if(value == '+'){
      numberOfPlus +=1;
     }
    }
   }
    //Change message and health depending on the amount of plusses.
     switch (numPlus)
      {
      case 0:
      m_playerHealth-= 3;
       cout << " " << tiles[i].m_word1 << " " << tiles[i].m_word2
        << " " << tiles[i].m_word3 << " " << tiles[i].m_word4 << " It seems the spells have done terrible damage to you, -3 health " 
       << endl;
       break;
      case 1:
      m_playerHealth-= 1;
       cout << " " << tiles[i].m_word1 << " " << tiles[i].m_word2
        << " " << tiles[i].m_word3 << " " << tiles[i].m_word4 << " It seems the spells have done damage to you, -1 health " 
       << endl;
       break;
      case 2:
       cout << " " << tiles[i].m_word1 << " " << tiles[i].m_word2
        << " " << tiles[i].m_word3 << " " << tiles[i].m_word4 << " It seems the spells have done absolutely nothing to you " 
       << endl;
       break;
      case 3:
      m_playerHealth+= 1;
       cout << " " << tiles[i].m_word1 << " " << tiles[i].m_word2
        << " " << tiles[i].m_word3 << " " << tiles[i].m_word4 << " It seems the spells have restored health to you, +1 health " 
       << endl;
       break;
      case 4:
      m_playerHealth+= 3;
       cout << tiles[i].m_word1 << " " << tiles[i].m_word2
        << " " << tiles[i].m_word3 << " " << tiles[i].m_word4 << " It seems the spells have restored a lot of health to you, +3 health " 
      << endl;
       break;
      }
   
    } else if (tiles[i].m_type=="RESTORE"){
    m_playerHealth = 7;
    cout << "You are back to your original health" << endl;

    } else if (tiles[i].m_type=="CLUE"){
    if(tiles[i].m_cluePos=="R"){
     cout << "The win square is right." << endl;
    }else if(tiles[i].m_cluePos=="L"){
     cout << "The win square is left." << endl;
    }else if(tiles[i].m_cluePos=="U"){
     cout << "The win square is upwards." << endl;
    }else if(tiles[i].m_cluePos=="D"){
     cout << "The win square is downwards." << endl;
    }

    } else if (tiles[i].m_type=="TRAP"){
     //Halves player health and round it down, does not work with integers
   m_playerHealth = floor(m_playerHealth/2);
    cout << "You have fallen into a trap, and lost half your health." << endl;

    } else if (tiles[i].m_type=="DISTANCE"){ 
   cout << "The distance to the win tile is: " << m_squares[i].m_distance << endl;
    } else if (tiles[i].m_type=="WIN"){
   cout << "FINISHED" << endl;
    m_quit = true;
   break;
      }
   
    } else if (this->m_squares[i].m_type=="RESTORE"){
    m_playerHealth = 7;
    cout << "You are back to your original health" << endl;

    } else if (this->m_squares[i].m_type=="CLUE"){
    if(this->m_squares[i].m_word1=="R"){
     cout << "The win square is right." << endl;
    }else if(this->m_squares[i].m_word1=="L"){
     cout << "The win square is left." << endl;
    }else if(this->m_squares[i].m_word1=="U"){
     cout << "The win square is upwards." << endl;
    }else if(this->m_squares[i].m_word1=="D"){
     cout << "The win square is downwards." << endl;
    }

    } else if (this->m_squares[i].m_type=="TRAP"){
     //Halves player health and round it down, does not work with integers
   m_playerHealth = floor(m_playerHealth/2);
    cout << "You have fallen into a trap, and lost half your health." << endl;

    } else if (this->m_squares[i].m_type=="DISTANCE"){ 
   cout << "The distance to the win tile is: " << m_squares[i].m_distance << endl;
    } else if (this->m_squares[i].m_type=="WIN"){
   cout << "FINISHED" << endl;
    m_quit = true;
   break;
  }
 }
}
inFile.close();

}

int main(){

loadField();
string plusminus;
string spell;

initGrid();
int pi = 9, pj = 0;
playgrid[pi][pj] = 'O';
printGrid(playgrid,10,10);
string command;

//-----//MagicWordDictionary
do{
 cout << "Wizard Health: " << playerHealth << endl;
 cout << "Your position is : " << pi << "," << pj << endl;
 cout << "Please insert the Wizard movement: " << endl;;
 cin >> command;
 
  if(command == "u"){
   for(int index=0;index<=nTile;index++){
   //cout << tiles[index].m_Xcor << "," << tiles[index].m_Ycor << "|" << tiles[index].m_type << endl;
   }
  initGrid();
  pi -= 1;
  playgrid[pi][pj] = 'O';
  printGrid(playgrid,10,10);
  cout << "you went up" << endl;}
 else if(command == "r"){
  initGrid();
  pj += 1;
  playgrid[pi][pj] = 'O';
  printGrid(playgrid,10,10);
  cout << "you went right" << endl;}
 else if(command == "l"){
  initGrid();
  pj -= 1;
  playgrid[pi][pj] = 'O';
  printGrid(playgrid,10,10);
  cout << "you went left" << endl;}
 else if(command == "d"){
  initGrid();
  pi += 1;
  playgrid[pi][pj] = 'O';
  printGrid(playgrid,10,10);
  cout << "you went down" << endl;}
 else if(command == "b")
  cout << "ctrl+z" << endl;
 else if(command == "q")
  return 1;
 else{
  cerr << "Command not recognized: " << command << endl;
  cerr << "Legit commands are \"q\", \"b\", \"l\", \"r\", \"u\", \"d\"." << endl;
  }
 }while(1);
cin.get();
}

 

Revise this Paste

Parent: 35721
Children: 35724
Your Name: Code Language: