Exemplo n.º 1
0
//assists the player in performing their actions.
//Actions are: "Fire", "Reload", "Switch"(weapons), "Hunker", "Item",
//"Other".
//"Fire" prompts a target selection out of the current enemy
//combatants.
//Reload resets the current weapon's ammo counter to full, and
//decrements magazines by 1.
//"Switch" prompts a weapon selection when applicable.
//"Hunker" Puts the player in hunkered cover, offering +25 defense.
//"Item" prompts an item selection when applicable.
//"Other" prompts a description of the action, and prints it.
void playerTurn (int activeEnemies, int* player) {
    int ha = 4; //Number of Half-Actions a player has per turn.
    //This is an artifact of the way the pen & paper game is played.

    char* action = malloc(sizeof(char)*8);

    while (ha > 0) {
        //ask player what to do
        printf ("====================\n");
        printf("Half-Actions Remaining: %d\n", ha);
        printf ("What would you like to do?:\n");
        printf (" Fire  [1]|| Reload [2]|| Switch[1]\nHunker [2]||  Item  [1]|| Other [1]\n");
        scanf("%s", action);
        printf("Action selected: \"%s\"\n", action);
        if (strcmp(action, "Fire") == 0 || strcmp(action, "fire") == 0 || strcmp(action, "f") == 0 || strcmp(action, "F") == 0) {
            printf("---Fire---\n");
            pAttack(playerSelect(activeEnemies), player[7], player[8]);//target, miss, damage
            ha--;
        } else if (action == "Reload" || action == "reload" || action == "R" || action == "r") {
            printf("---Reload---\n");
            if (ha > 1) {
                ha-=2;
                if (player[11] > 0) {
                    player[9] = player[10];
                    player[11]--;
                    printf("Lock 'n' load!\n");
                } else {
                    printf("No Mags!\n");
                }
            } else {
                printf("Not enough time!\n");
            }
        } else if (action == "Switch" || action == "switch" || action == "S" || action == "s") {
            printf("---Switch---\n");
            printf("You only have 1 weapon.");
            /*if (ha > 1) {
                ha--
                switch();
            }*/
        } else if (action == "Hunker" || action == "hunker" || action == "H" || action == "h") {
            printf("---Hunker---\n");
            if (ha>2) {
                ha-=2;
                printf("You take cover, +25 Defense");
                player[13] = 25;
                //isHunkered = true;
            }
        } else if (action == "Item" || action == "item" || action == "I" || action == "i") {
            printf("---Item---\n");
            printf("No items :(\n");
        } else if (action == "Other" || action == "other" || action == "O" || action == "o") {
            printf("---Other---\n");
            if (ha > 1) {
                printf("Some time is spent, -1 half action\n");
            }
        }

    }

}
Exemplo n.º 2
0
/**
 * Set up game with default values
 */
void setUpGame (ticTacToeBoard* selector, char *charPtr, unsigned short int* intPtr)
{
    // Sets turn number to 0
    *intPtr = 1;

    // Stores number of players as "num_players"
    intPtr[1] = numberOfPlayers();

    // Stores selected player as "user"
    charPtr[41] = playerSelect();

    // If there is an AI, ask for difficulty
    if(intPtr[1] == 1)
        intPtr[2] = findDifficulty(selector);

    // Flip coin to see who goes first
    coinFlip(charPtr);

    // Create a fresh board
    initBoard(charPtr);
}