Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define BLACK 1
- #define WHITE 0
- struct Gracz{
- int pozycjaX;
- int pozycjaY;
- int zycie;
- int color;
- };
- struct TerenSkazony{
- unsigned int wierz1X;
- unsigned int wierz1Y;
- unsigned int wierz2X;
- unsigned int wierz2Y;
- unsigned int wierz3X;
- unsigned int wierz3Y;
- unsigned int wierz4X;
- unsigned int wierz4Y;
- };
- void Czy_skazony(struct Gracz *player);
- void poruszenie( struct Gracz *player, struct Gracz do_sprawdzenia);
- void rysuj_mape(struct Gracz player1, struct Gracz player2);
- void wyswietl_stan_gry(struct Gracz player1, struct Gracz player2, struct TerenSkazony *tablica);
- int main(){
- srand(time(NULL));
- struct Gracz player1 = {0,0,5,BLACK};
- struct Gracz player2 = {19,39,5,WHITE};
- struct TerenSkazony tablica[2] = {{8,8,8,16,10,8,10,16},{8,30,8,38,10,30,10,38}};
- rysuj_mape(player1, player2);
- char pomoc;
- wyswietl_stan_gry(player1, player2, tablica);
- while(player1.zycie > 0 && player2.zycie >0 ){
- poruszenie(&player1, player2);
- poruszenie(&player2, player1);
- Czy_skazony(&player1);
- Czy_skazony(&player2);
- rysuj_mape(player1,player2);
- wyswietl_stan_gry(player1, player2, tablica);
- printf("podaj jakis znak aby kontynuowac: ");
- scanf("%c", &pomoc);
- getchar();
- }
- printf("KONIEC ");
- return 0;
- }
- void poruszenie( struct Gracz *player, struct Gracz do_sprawdzenia){
- int ruch;
- ruch = ((rand() %4)+0);
- int czy_mozna = 0;
- while(czy_mozna == 0){
- if(ruch == 0){
- if( (player->pozycjaX >=1) && ((player->pozycjaX-1) != do_sprawdzenia.pozycjaX ) ){// ruch w gore
- player->pozycjaX--;
- break;
- }
- }
- else if(ruch == 1){
- if( (player->pozycjaY <=38) && ((player->pozycjaY +1) != do_sprawdzenia.pozycjaY) ){// ruch w prawo
- player->pozycjaY++;
- break;
- }
- }
- else if(ruch ==2){
- if( (player->pozycjaX +1 <=18) && ((player->pozycjaX +1) != do_sprawdzenia.pozycjaX) ){// ruch dol
- player->pozycjaX++;
- break;
- }
- }
- else if(ruch == 3) { // ruch w lewo
- if( (player->pozycjaY >=1) && ((player->pozycjaY -1) != do_sprawdzenia.pozycjaY) ){
- player->pozycjaY--;
- break;
- }
- }
- ruch = ((rand() %4)+0);
- }
- }
- void wyswietl_stan_gry(struct Gracz player1, struct Gracz player2, struct TerenSkazony *tablica)
- {
- 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 );
- }
- void rysuj_mape(struct Gracz player1, struct Gracz player2){
- for(int i = 0; i<22; i++){
- for(int j = 0; j<42; j++){
- if( i==player1.pozycjaX+1 && j == player1.pozycjaY+1)
- printf("#");
- else if( i == player2.pozycjaX +1 && j == player2.pozycjaY +1)
- printf("@");
- else if((i>=9 && i<= 11 && j>=9 && j <=17) ||
- (i>=9 && i<= 11 && j>=31 && j <=39))
- printf("*");
- else if( i == 0 || i == 21)
- printf("-");
- else if( j == 0 || j == 41 )
- printf("|");
- else printf(" ");
- }
- printf("\n");
- }
- }
- void Czy_skazony(struct Gracz *player){
- if((player->pozycjaX>=8 && player->pozycjaX<= 10 && player->pozycjaY>=8 && player->pozycjaY <=16) ||
- (player->pozycjaX>=8 && player->pozycjaX<= 10 && player->pozycjaY>=30 && player->pozycjaY <=38))
- player->zycie--;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement