Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. #define BLACK 1
  6. #define WHITE 0
  7.  
  8. struct Gracz{
  9.   int pozycjaX;
  10.   int pozycjaY;
  11.   int zycie;
  12.   int color;
  13. };
  14.  
  15. struct TerenSkazony{
  16.   unsigned int wierz1X;
  17.   unsigned int wierz1Y;
  18.  
  19.   unsigned int wierz2X;
  20.   unsigned int wierz2Y;
  21.  
  22.   unsigned int wierz3X;
  23.   unsigned int wierz3Y;
  24.  
  25.   unsigned int wierz4X;
  26.   unsigned int wierz4Y;
  27. };
  28.  
  29.  
  30. void Czy_skazony(struct Gracz *player);
  31. void poruszenie( struct Gracz *player, struct Gracz do_sprawdzenia);
  32. void rysuj_mape(struct Gracz player1, struct Gracz player2);
  33. void wyswietl_stan_gry(struct Gracz player1, struct Gracz player2, struct TerenSkazony *tablica);
  34.  
  35.  
  36.  
  37.  
  38. int main(){
  39.   srand(time(NULL));
  40.   struct Gracz player1 = {0,0,5,BLACK};
  41.   struct Gracz player2 = {19,39,5,WHITE};
  42.   struct TerenSkazony tablica[2] = {{8,8,8,16,10,8,10,16},{8,30,8,38,10,30,10,38}};
  43.   rysuj_mape(player1, player2);
  44.   char pomoc;
  45.   wyswietl_stan_gry(player1, player2, tablica);
  46.  
  47.   while(player1.zycie > 0 && player2.zycie >0 ){
  48.    
  49.  
  50.   poruszenie(&player1, player2);
  51.   poruszenie(&player2, player1);
  52.   Czy_skazony(&player1);
  53.   Czy_skazony(&player2);
  54.   rysuj_mape(player1,player2);
  55.   wyswietl_stan_gry(player1, player2, tablica);
  56.  
  57.  
  58.  
  59.   printf("podaj jakis znak aby kontynuowac: ");
  60.   scanf("%c", &pomoc);
  61.   getchar();
  62.   }
  63.  
  64.   printf("KONIEC ");
  65.  
  66.   return 0;
  67.  
  68. }
  69.  
  70.  
  71. void poruszenie( struct Gracz *player, struct Gracz do_sprawdzenia){
  72.   int ruch;
  73.   ruch = ((rand() %4)+0);
  74.   int czy_mozna = 0;
  75.  
  76.   while(czy_mozna == 0){
  77.   if(ruch == 0){
  78.     if( (player->pozycjaX >=1) && ((player->pozycjaX-1) != do_sprawdzenia.pozycjaX ) ){// ruch w gore
  79.     player->pozycjaX--;
  80.     break;
  81.     }
  82.   }
  83.   else if(ruch == 1){
  84.     if( (player->pozycjaY <=38) && ((player->pozycjaY +1) != do_sprawdzenia.pozycjaY) ){// ruch w prawo
  85.     player->pozycjaY++;
  86.     break;
  87.     }
  88.   }
  89.   else if(ruch ==2){
  90.     if( (player->pozycjaX +1 <=18) && ((player->pozycjaX +1) != do_sprawdzenia.pozycjaX) ){// ruch dol
  91.     player->pozycjaX++;
  92.     break;
  93.     }
  94.   }
  95.   else if(ruch == 3) { // ruch w lewo
  96.     if( (player->pozycjaY >=1) && ((player->pozycjaY -1) != do_sprawdzenia.pozycjaY) ){
  97.     player->pozycjaY--;
  98.     break;
  99.     }
  100.   }
  101.   ruch = ((rand() %4)+0);
  102.   }
  103. }
  104.  
  105.  
  106.  
  107. void wyswietl_stan_gry(struct Gracz player1, struct Gracz player2, struct TerenSkazony *tablica)
  108. {
  109. printf("Wyswietlanie aktualnego stanu gry: \nPlayer1: \npozycja X: %d, pozycja Y: %d, ilosc zyc: %d\nPlayer2: \npozycja X: %d, pozycja Y: %d, ilosc zyc: %d\nTereny skażone: \n(%d,%d); (%d,%d); (%d,%d); (%d,%d);\n(8,30); (8,38); (10,30); (10,38);\n", player1.pozycjaX, player1.pozycjaY, player1.zycie, player2.pozycjaX, player2.pozycjaY, player2.zycie, tablica[0].wierz1X, tablica[0].wierz1Y, tablica[0].wierz2X, tablica[0].wierz2Y,tablica[0].wierz3X, tablica[0].wierz3Y,tablica[0].wierz4X, tablica[0].wierz4Y );
  110. }
  111.  
  112.  
  113. void rysuj_mape(struct Gracz player1, struct Gracz player2){
  114.   for(int i = 0; i<22; i++){
  115.     for(int j = 0; j<42; j++){
  116.       if( i==player1.pozycjaX+1 && j == player1.pozycjaY+1)
  117.       printf("#");
  118.       else if( i == player2.pozycjaX +1 && j == player2.pozycjaY +1)
  119.       printf("@");
  120.       else if((i>=9 && i<= 11 && j>=9 && j <=17) ||
  121.      (i>=9 && i<= 11 && j>=31 && j <=39))
  122.      printf("*");
  123.       else if( i == 0 || i == 21)
  124.       printf("-");
  125.       else if( j == 0 || j == 41 )
  126.       printf("|");
  127.       else printf(" ");
  128.     }
  129.     printf("\n");
  130.   }
  131.    
  132. }
  133.  
  134. void Czy_skazony(struct Gracz *player){
  135.   if((player->pozycjaX>=8 && player->pozycjaX<= 10 && player->pozycjaY>=8 && player->pozycjaY <=16) ||
  136.      (player->pozycjaX>=8 && player->pozycjaX<= 10 && player->pozycjaY>=30 && player->pozycjaY <=38))
  137.      player->zycie--;
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement