Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: supermanv2 on May 5th, 2012  |  syntax: None  |  size: 5.26 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include "Game.h"
  6.  
  7. int validPath(path thePath);
  8. int rollDice();
  9. int getNextMove)();
  10.  
  11. int main(int argc, char* argv[]){
  12.    srand(time(NULL));
  13.    int curPlayer = 0;
  14.    int curMove;
  15.    int curDice = 0;
  16.    int trainFrom, trainTo;
  17.  
  18.    action curAction;
  19.  
  20.    int disciplines[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
  21.    disciplines[0] = STUDENT_THD;
  22.  
  23.    int counter = 1;
  24.    int temCounter = 1;
  25.  
  26.    while(counter < NUM_REGIONS){
  27.       temCounter = 1;
  28.       while((temCounter <= 6) && (counter + temCounter - 1 < NUM_REGIONS)){
  29.          disciplines[counter + temCounter - 1] = temCounter;
  30.          temCounter++;
  31.       }
  32.       counter += 5;
  33.    }
  34.  
  35.    char moveString[100];
  36.  
  37.    int dice[19] = {2,4,12,3,5,9,10,2,6,9,11,8,8,10,12,4,2,10,11};
  38.    Game curGame = newGame(disciplines,dice);
  39.  
  40.    int winFlag = FALSE;
  41.    int legitInput = FALSE;
  42.    int legitDice = FALSE;
  43.    int endTurn = FALSE;
  44.    int diceRolled;
  45.    int resultDice;
  46.  
  47.    path pathBuffer;
  48.  
  49.    printf("Welcome to generic_team_name's Game!");
  50.    printf("Our game is cool\n");
  51.    printf("Instruction set:\n");
  52.    printf("To build an arc, type a followed by xx and yy");
  53.  
  54.    while(winFlag == FALSE){
  55.       endTurn = FALSE;
  56.  
  57.       while(!legitDice){
  58.          diceRolled = rollDice();
  59.  
  60.          if(diceRolled >= 2 && diceRolled <= 12){
  61.             legitDice = TRUE;
  62.          } else {
  63.             printf("Dear friendly awesome dungeon master, please enter a valid roll (2-12)");
  64.          }
  65.       }
  66.  
  67.       throwDice(curGame, diceRolled);
  68.  
  69.       curPlayer = getWhoseTurn(curGame);
  70.  
  71.       while(!endTurn){
  72.          printf("What is your next intended move, sweet prince of ponies?: ");
  73.          legitInput = FALSE;
  74.  
  75.          curMove = getNextMove();
  76.  
  77.          if (curMove < 8 && curMove >= 0){
  78.             legitInput = TRUE;
  79.             curAction.actionCode = curMove;
  80.  
  81.             if (curMove == PASS){
  82.                endTurn = TRUE;
  83.  
  84.             } else if(curMove == BUILD_CAMPUS){
  85.                fgets(pathBuffer, PATH_LIMIT, stdin);
  86.                if (validPath(pathBuffer)){
  87.                   strncpy(curAction.destination,pathBuffer,PATH_LIMIT);
  88.                   makeAction(curGame,curAction);
  89.                }
  90.  
  91.             } else if (curMove == BUILD_GO8){
  92.                fgets(pathBuffer, PATH_LIMIT, stdin);
  93.                if ((validPath(pathBuffer)) && ((getGO8s(curGame,UNI_A) + getGO8s(curGame,UNI_B) + getGO8s(curGame,UNI_C)) < 8 )){
  94.                   strncpy(curAction.destination,pathBuffer,PATH_LIMIT);
  95.                   makeAction(curGame,curAction);
  96.                }
  97.  
  98.             } else if (curMove == OBTAIN_ARC){
  99.                fgets(pathBuffer, PATH_LIMIT, stdin);
  100.                if (validPath(pathBuffer)){
  101.                   if (getARC(curGame, pathBuffer) == VACANT_ARC){
  102.                      strncpy(curAction.destination,pathBuffer,PATH_LIMIT);
  103.                      makeAction(curGame, curAction);
  104.                   }
  105.                }
  106.  
  107.             } else if (curMove == START_SPINOFF){
  108.                /*
  109.                randomValue = (rand() % 100 + 1) / 3.0;
  110.                if (randomValue <= 33.33){
  111.                   curAction.actionCode = OBTAIN_IP_PATENT;
  112.                   makeAction(curGame, curAction);
  113.                } else {
  114.                   curAction.actionCode = OBTAIN_PUBLICATION;
  115.                   makeAction(curGame, curAction);
  116.                }
  117.                */
  118.             } else if (curMove == OBTAIN_PUBLICATION){
  119.                makeAction(curGame,curAction);
  120.  
  121.             } else if (curMove == OBTAIN_IP_PATENT){
  122.                makeAction(curGame,curAction);
  123.  
  124.             } else if (curMove == RETRAIN_STUDENTS){
  125.                scanf("%d %d",&trainFrom,&trainTo);
  126.                curAction.disciplineFrom = trainFrom;
  127.                curAction.disciplineTo = trainTo;
  128.  
  129.                if(!isLegitAction(curGame,curAction)){
  130.                   legitInput = FALSE;
  131.                   printf("WE REQUIRE MORE VESPENE GAS\n");
  132.                 } else {
  133.                   makeAction(curGame,curAction);
  134.                 }
  135.             }
  136.  
  137.             if(!legitInput){
  138.                printf("Please type in a valid move on pain of death\n");
  139.             }
  140.          }
  141.       }
  142.  
  143.       if (getKPIpoints(curGame,curPlayer) >= 150){
  144.          printf("%d Wins\n",curPlayer);
  145.          winFlag=TRUE;
  146.       }
  147.    }
  148.  
  149.    return EXIT_SUCCESS;
  150. }
  151.  
  152.  
  153. int validPath(path thePath) {
  154.    int i = 0;
  155.    int isEnd = FALSE;
  156.    int isInvalid = FALSE;
  157.    while (i < PATH_LIMIT && !isEnd && !isInvalid) {
  158.       if (thePath[i] != 'B' &&
  159.           thePath[i] != 'R' &&
  160.           thePath[i] != 'L' &&
  161.           thePath[i] != 0) {
  162.  
  163.           isInvalid = TRUE;
  164.       } else if (thePath[i] == 0) {
  165.           isEnd = TRUE;
  166.       }
  167.       i++;
  168.    }
  169.  
  170.    return !isInvalid;
  171. }
  172.  
  173. int rollDice(){
  174.  
  175.    int diceRoll;
  176.  
  177.    printf("Almighty SudoUser, what is le dice roll?: ");
  178.    scanf("%d",&diceRoll);
  179.  
  180.    return diceRoll;
  181. }
  182.  
  183. int getNextMove() {
  184.    int move;
  185.    while(!legitInput) {
  186.       scanf("%d",&move);
  187.       if((move < 8) && (move >= 0)) {
  188.          legitInput = TRUE;
  189.       } else {
  190.          printf("Please type in a valid move on pain of death\n");
  191.       }
  192.    }
  193.    return move;
  194. }