Exemple #1
0
int main(int argc, const char * argv[]) {
  char command;
  char dir;
  char race;
  string s;
  Floor* f;
  bool end = false;
  int score;
  
  ifstream in("welcome.txt");	// welcome page
  while (getline(in, s)) {
    cout << s << endl;
  }
  
  while (true) {		// determine if whitespace is pressed
    cin >> command;
    if (command == 'c') {
      break;
    }
    if (command == 'q') {
      return 0;
    }
  }
  
  f = new Floor(25, 79);	// choose race
  f->init(argv[1]);
  cout << "please choose your race" << endl;
  cout << "h: human" << endl;
  cout << "d: dwarf" << endl;
  cout << "e: evlves" << endl;
  cout << "o: orc" << endl;
  cout << "i: ironman" << endl;
  
  while (true) {
    cin >> race;	// specify race
    if (race == 'q') return 0;
    else if (race == 'h' || race == 'e' || race == 'd' || race == 'o' ||
             race == 'i') break;
    else cout << "no such race" << endl;
  }
  
  switch(race) {	// spawn pc and stair
    case 'h':
      character = new Human;
      f->newGame(character);
      break;
    case 'e':
      character = new Elves;
      f->newGame(character);
      break;
    case 'd':
      character = new Dwarf;
      f->newGame(character);
      break;
    case 'o':
      character = new Orc;
      f->newGame(character);
      break;
    case 'i':
      character = new Ironman;
      f->newGame(character);
      break;
  }
  f->enemyMove();
  f->notifyTd();
  cout << *f;
  
  while (true) {
    if (character->getHp() <= 0) {	// determine if PC is dead
      ifstream in("lose.txt");
      while(getline(in, s)) {
        cout << s << endl;
      }
      score = character->getGold();
      if (character->getRace() == "human") {
        score += score / 2;
      }
      cout << "Your Score is: " << score << endl;
      end = true;
    }
    
    cin >> command;
    
    if (end == true) {	// wait for r or q after previous game
      while (command != 'r' && command != 'q') {
        cin >> command;
      }
      end = false;
    }
    
    switch(command) {
      case 'n':		// move
        cin >> dir;
        switch(dir) {
          case 'w':	
            f->pcMove(0);
            break;
          case 'o':
            f->pcMove(1);
            break;
          case 'e':
            f->pcMove(2);
            break;
          default:
            cout << "invalid command" << endl;
            break;
        }
        break;
      case 'w':
        cin >> dir;
        if (dir == 'e') {
          f->pcMove(3);
        } else {
          cout << "invalid command" << endl;
        }
        break;
      case 'e':
        cin >> dir;
        if (dir == 'a') {
          f->pcMove(4);
        } else {
          cout << "invalid command" << endl;
        }
        break;
      case 's':
        cin >> dir;
        switch(dir) {
          case 'w':
            f->pcMove(5);
            break;
          case 'o':
            f->pcMove(6);
            break;
          case 'e':
            f->pcMove(7);
            break;
          default:
            cout << "invalid command" << endl;
            break;
        }
        break;
        
      case 'u':		// drink potion
        cin >> command;
        switch(command) {
          case 'n':	
            cin >> dir;
            switch(dir) {
              case 'w':
                f->pcUse(0);
                break;
              case 'o':
                f->pcUse(1);
                break;
              case 'e':
                f->pcUse(2);
                break;
              default:
                cout << "invalide command" << endl;
                break;
            }
            break;
          case 'w':
            cin >> dir;
            if (dir == 'e') {
              f->pcUse(3);
            } else {
              cout << "invalid command" << endl;
            }
            break;
          case 'e':
            cin >> dir;
            if (dir == 'a') {
              f->pcUse(4);
            } else {
              cout << "invalid command" << endl;
              break;
            }
            break;
          case 's':
            cin >> dir;
            switch(dir) {
              case 'w':
                f->pcUse(5);
                break;
              case 'o':
                f->pcUse(6);
                break;
              case 'e':
                f->pcUse(7);
                break;
              default:
                cout << "invalid command" << endl;
                break;
            }
            break;
        }
        break;
        
      case 'g':		// get potion
        cin >> command;
        switch(command) {
          case 'n':
            cin >> dir;
            switch(dir) {
              case 'w':
                f->pcGet(0);
                break;
              case 'o':
                f->pcGet(1);
                break;
              case 'e':
                f->pcGet(2);
                break;
              default:
                cout << "invalide command" << endl;
                break;
            }
            break;
          case 'w':
            cin >> dir;
            if (dir == 'e') {
              f->pcGet(3);
            } else {
              cout << "invalid command" << endl;
            }
            break;
          case 'e':
            cin >> dir;
            if (dir == 'a') {
              f->pcGet(4);
            } else {
              cout << "invalid command" << endl;
              break;
            }
            break;
          case 's':
            cin >> dir;
            switch(dir) {
              case 'w':
                f->pcGet(5);
                break;
              case 'o':
                f->pcGet(6);
                break;
              case 'e':
                f->pcGet(7);
                break;
              default:
                cout << "invalid command" << endl;
                break;
            }
            break;
        }
        break;

      case 'a':		// attack enemy
        cin >> command;
        switch(command) {
          case 'n':
            cin >> dir;
            switch(dir) {
              case 'w':
                f->pcAttack(0);
                break;
              case 'o':
                f->pcAttack(1);
                break;
              case 'e':
                f->pcAttack(2);
                break;
              default:
                cout << "invalid command" << endl;
                break;
            }
            break;
          case 'w':
            cin >> dir;
            if (dir == 'e') {
              f->pcAttack(3);
            } else {
              cout << "invalid command" << endl;
            }
            break;
          case 'e':
            cin >> dir;
            if (dir == 'a') {
              f->pcAttack(4);
            } else {
              cout << "invalid command" << endl;
            }
            break;
          case 's':
            cin >> dir;
            switch(dir) {
              case 'w':
                f->pcAttack(5);
                break;
              case 'o':
                f->pcAttack(6);
                break;
              case 'e':
                f->pcAttack(7);
                break;
              default:
                cout << "invalid command" << endl;
                break;
            }
            break;
        }
        break;
        
      case 'b':
        int i;
        cin >> i;
        cin >> command;
        f->pcBuy(command, i);
        break;
        
      case 'd':		// drink potion
        f->pcDrink();
        break;

      case 'r':		// restart game
        end = false;
        delete f;
        f = new Floor(25, 79);
        f->init(argv[1]);
        cout << "please choose your race" << endl;
        cout << "h: human" << endl;
        cout << "d: dwarf" << endl;
        cout << "e: evlves" << endl;
        cout << "o: orc" << endl;
        cout << "i: ironman" << endl;
        while (true) {
          cin >> race;	// specify race
          if (race == 'q') return 0;
          else if (race == 'h' || race == 'e' || race == 'd' || race == 'o'
                   || race == 'i') break;
          else cout << "no such race" << endl;
        }
        switch(race) {
          case 'h':
            character = new Human;
            f->newGame(character);
            break;
          case 'e':
            character = new Elves;
            f->newGame(character);
            break;
          case 'd':
            character = new Dwarf;
            f->newGame(character);
            break;
          case 'o':
            character = new Orc;
            f->newGame(character);
            break;
          case 'i':
            character = new Ironman;
            f->newGame(character);
            break;
        }
        break;
        
      case 'q':
        cout << "you give up, try harder next time." << endl;
        delete f;
        return 0;
        
      default:
        continue;
    }
    if (f->getF() >= numFloor) {
      ifstream in("win.txt");
      while (getline(in, s)) {
        cout << s << endl;
      }
      score = character->getGold();
      if (character->getRace() == "human") {
        score += score / 2;
      }
      cout << "Your Score is: " << score << endl;
      end = true;
      continue;
    }
    f->enemyMove();
    f->notifyTd();
    cout << *f;
  }
  return 0;
}
void ColoredCubeApp::initApp()
{
	D3DApp::initApp();
	
	audio->playCue(MAIN_TRACK);

	srand(time(0));

	left = Vector3(1,0,0);
	right = Vector3(-1,0,0);
	forward = Vector3(0,0,-1);
	back = Vector3(0,0,1);
	up = Vector3(0,1,0);
	down = Vector3(0,-1,0);
	zero = Vector3(0,0,0);
	
	whiteBox.init(md3dDevice, 1.0f, WHITE);
	redBox.init(md3dDevice, 1.0f, RED);
	blueBox.init(md3dDevice, 1.0f, BLUE);
	greenBox.init(md3dDevice, 1.0f, GREEN);
	crimBox.init(md3dDevice, 0.8f, CRIMSON);
	dRedBox.init(md3dDevice, 0.8f, DARKRED);
	dBlueBox.init(md3dDevice, 0.25f, DARKBLUE);

	line.init(md3dDevice, 10.0f, GREEN);

	////// New Stuff added by Steve //////
	gLine.init(md3dDevice, 10.0f, GREEN);
	rLine.init(md3dDevice, 10.0f, RED);
	bLine.init(md3dDevice, 10.0f, BLUE);
	xLine.init(&rLine, Vector3(0,0,0), 10);
	xLine.setPosition(Vector3(0,0,0));
	yLine.init(&gLine, Vector3(0,0,0), 10);
	yLine.setPosition(Vector3(0,0,0));
	yLine.setRotationZ(ToRadian(90));
	zLine.init(&bLine, Vector3(0,0,0), 10);
	zLine.setPosition(Vector3(0,0,0));
	zLine.setRotationY(ToRadian(90));
	numberOfObstacles = 50;
	float obstacleScale = 2.5f;
	float playerScale = 2.67f;
	Vector3 oScale(obstacleScale, obstacleScale, obstacleScale);
	Vector3 pScale(playerScale, playerScale, playerScale);
	playerBox.init(md3dDevice, playerScale, WHITE);
	player.init(&playerBox, sqrt(playerScale * 2.0f), Vector3(0, 2, 0), Vector3(0, 0, 0), 10, pScale, audio);
	player.linkInput(input);

	int posZ = 0;
	int posX = 0;
	int chance = 0;
	int r = 0;
	float floorSpeed = floor.getSpeed();
	for (int i=0; i<numberOfObstacles; ++i)
	{	
		Box* box = new Box();
		box->init(md3dDevice, obstacleScale, GREEN);
		obstacleBoxes.push_back(box);
		Obstacle o;
		o.init(box, sqrt(5.0f), Vector3(0,0,200), Vector3(0,0,-1), 0, Vector3(oScale));
		o.setInActive();
		obstacles.push_back(o);
	}
	///Set obstacle cluster variables
	clusterSize = 1;
	clusterSizeVariation = 3;
	clusterSeparation = 100;
	cubeSeparation = 30;
	lineJiggle = 3;
	cubeJiggle = 3;
	clusterJiggle = 10;
	floorMovement = 0.0f;

	//Other floor variables
	floorClusterCounter = 0;
	floorClusterThreshold = 7;
	floorSpeedIncrease = 5;

	//New spectrum HUD by Andy
	specHudBox[0].init(md3dDevice, .5f, 1.0f, 1.0f, RED, YELLOW);
	specHudBox[1].init(md3dDevice, .5f, 1.0f, 1.0f, YELLOW, GREEN);
	specHudBox[2].init(md3dDevice, .5f, 1.0f, 1.0f, GREEN, CYAN);
	specHudBox[3].init(md3dDevice, .5f, 1.0f, 1.0f, CYAN, BLUE);
	specHudBox[4].init(md3dDevice, .5f, 1.0f, 1.0f, BLUE, MAGENTA);
	specHudBox[5].init(md3dDevice, .5f, 1.0f, 1.0f, MAGENTA, RED);
	cursorBox.init(md3dDevice, .15f, 1.0f, .75f, BLACK, BLACK);

	Vector3 specPos = Vector3(11.0f, 25.0f, -5.0f);
	spectrum[0].init(&specHudBox[0], 1.0f,specPos + Vector3(0.0f,0.0f,0.0f), Vector3(0.0f,0.0f,0.0f), 0, Vector3(0.0f,0.0f,0.0f));
	spectrum[1].init(&specHudBox[1], 1.0f,specPos + Vector3(2.0f,0.0f,0.0f), Vector3(0.0f,0.0f,0.0f), 0, Vector3(0.0f,0.0f,0.0f));
	spectrum[2].init(&specHudBox[2], 1.0f,specPos + Vector3(4.0f,0.0f,0.0f), Vector3(0.0f,0.0f,0.0f), 0, Vector3(0.0f,0.0f,0.0f));
	spectrum[3].init(&specHudBox[3], 1.0f,specPos + Vector3(6.0f,0.0f,0.0f), Vector3(0.0f,0.0f,0.0f), 0, Vector3(0.0f,0.0f,0.0f));
	spectrum[4].init(&specHudBox[4], 1.0f,specPos + Vector3(8.0f,0.0f,0.0f), Vector3(0.0f,0.0f,0.0f), 0, Vector3(0.0f,0.0f,0.0f));
	spectrum[5].init(&specHudBox[5], 1.0f,specPos + Vector3(10.0f,0.0f,0.0f), Vector3(0.0f,0.0f,0.0f), 0, Vector3(0.0f,0.0f,0.0f));
	cursor.init(&cursorBox,1.0f,specPos + Vector3(-.80f, -1.0f, 0.0f), Vector3(0.0f,0.0f,0.0f), 0, Vector3(0.0f,0.0f,0.0f));


	gameObject1.init(&whiteBox, sqrt(2.0f), Vector3(-10,0,0), Vector3(0,0,0), 0,Vector3(2,2,2));
	gameObject2.init(&redBox, sqrt(2.0f), Vector3(4,0,0), Vector3(0,0,0), 0,Vector3(2,2,2));
	gameObject3.init(&redBox, sqrt(2.0f), Vector3(-4,0,0), Vector3(0,0,0), 0,Vector3(2,2,2));

	floor.init(md3dDevice);

	gameOver = false;
	activeMessage = false;
	messageTimer = 0.0f;

	//init lights - using pointlights
	lightType = 1;
	numberOfLights = 1;
	for (int i=0; i<numberOfLights; ++i)
	{
		Light l;
		l.pos = Vector3(0, 50, -17);
		l.ambient = Color(0.67f, 0.67f, 0.67f);
		l.diffuse = Color(1.0f, 1.0f, 1.0f);
		l.specular = Color(1.0f, 1.0f, 1.0f);
		l.att.x = 1.5f;
		l.att.y = 0.0f;
		l.att.z = 0.0f;
		l.range = 97.0f;
		lights.push_back(l);
	}


	buildFX();
	buildVertexLayouts();

}