Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #define MAX_HEALTH 5
- #define HEALTH 0
- #define STICK 1
- void init(void);
- void print_status(void);
- void print_past(char);
- void player_move(void);
- void ai_move(void);
- void reset(void);
- int player[2] = {MAX_HEALTH, 2};
- int ai[2] = {MAX_HEALTH, 2};
- char youpast[255];
- char hepast[255];
- int level = -1;
- int main(void) {
- init();
- while(player[HEALTH] > 0 && ai[HEALTH] > 0) {
- player_move();
- ai_move();
- reset();
- print_status();
- }
- if(player[HEALTH] == 0)
- printf("\nYOU LOSE!!!!\n");
- else
- printf("\nYOU WIN!!!!\n");
- return 0;
- }
- void init(void) {
- printf("You:\t\tHim:\n");
- print_status();
- }
- void print_status(void) {
- int x;
- for(x = 0; x < player[HEALTH]; x++)
- printf("=");
- printf(" \t");
- for(x = 0; x < ai[HEALTH]; x++)
- printf("=");
- printf(" \n");
- printf("H:%d/%d\t\tH:%d/%d\n", player[HEALTH], MAX_HEALTH, ai[HEALTH], MAX_HEALTH);
- printf("Stick: %d\tStick: %d\n", player[STICK], ai[STICK]);
- if(level >= 0) {
- print_past(youpast[level]);
- printf(" \t");
- print_past(hepast[level]);
- }
- printf("\n");
- if(player[HEALTH] != 0 && ai[HEALTH] != 0) {
- printf("What will you do [S, B");
- if(player[STICK] != 0)
- printf(", P");
- printf("]: ");
- }
- printf("\033[8D");
- }
- void print_past(char c) {
- switch(c) {
- case 'S':
- printf("Sharpened!");
- break;
- case 'B':
- printf("Blocked! ");
- break;
- case 'P':
- printf("Poked! ");
- break;
- }
- }
- void player_move(void) {
- char c[10];
- int ok = 0;
- char choice;
- level++;
- if(level >= 255)
- level = 0;
- do {
- fgets(c, 10, stdin);
- choice = toupper(c[0]);
- if(choice != 'S' && choice != 'P' && choice != 'B') {
- ok = 1;
- printf("\033[1A");
- if(player[STICK] == 0)
- printf("\033[25C");
- else
- printf("\033[28C");
- } else
- ok = 0;
- if(choice == 'P' && player[STICK] == 0) {
- ok = 1;
- printf("\033[1A");
- printf("\033[25C");
- }
- } while(ok != 0);
- switch(c[0]) {
- case 'S':
- case 's':
- youpast[level] = 'S';
- break;
- case 'B':
- case 'b':
- youpast[level] = 'B';
- break;
- case 'P':
- case 'p':
- youpast[level] = 'P';
- break;
- }
- }
- void ai_move(void) {
- if(ai[STICK] <= 0)
- hepast[level] = 'S';
- else
- hepast[level] = 'P';
- }
- void reset(void) {
- if(hepast[level] == 'P') {
- ai[STICK]--;
- if(youpast[level] == 'S')
- player[HEALTH]--;
- }
- if(youpast[level] == 'P') {
- player[STICK]--;
- if(hepast[level] == 'S')
- ai[HEALTH]--;
- }
- if(hepast[level] == 'S')
- ai[STICK]++;
- if(youpast[level] == 'S')
- player[STICK]++;
- printf("\033[5A");
- printf("\033[30D");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement