Last active
July 22, 2021 14:37
-
-
Save SirmaXX/2515d7005d7d6e53d718e1b2f2f36350 to your computer and use it in GitHub Desktop.
duel game in c ,Deniz Balcı
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
struct character | |
{ | |
char charname[50]; | |
int power ; | |
char weapon[50]; | |
int health; | |
}; | |
void charstats( struct character characters ); | |
void fight(struct character char1 ,struct character char2); | |
int main(int argc, char** argv) { | |
struct character char1; | |
struct character char2; | |
int weaponoption; | |
int enweaponoption; | |
printf("karakter ismi "); | |
scanf("%s", char1.charname); | |
printf("karakter sağlığı (tam sayı) "); | |
scanf("%d", &char1.health); | |
printf("kendi silahini sec 1)kilic 20 güc ,2 mızrak 30 güc \n"); | |
scanf("%d",&weaponoption); | |
switch (weaponoption) | |
{ | |
case 1: | |
strcpy( char1.weapon, "kilic"); | |
char1.power =20; | |
break; | |
case 2: | |
strcpy( char1.weapon, "mizrak"); | |
char1.power =30; | |
break; | |
default: | |
strcpy( char1.weapon, "kilic"); | |
char1.power =20; | |
break; | |
} | |
printf("rakip ismi "); | |
scanf("%s", char2.charname); | |
printf("rakip sağlığı (tam sayı) "); | |
scanf("%d", &char2.health); | |
printf(" rakibin silahini sec 1)kilic 20 güc ,2 mızrak 30 güc \n "); | |
scanf("%d",&enweaponoption); | |
switch ( enweaponoption) | |
{ | |
case 1: | |
strcpy( char2.weapon, "kilic"); | |
char2.power =20; | |
break; | |
case 2: | |
strcpy( char2.weapon, "mizrak"); | |
char2.power =30; | |
break; | |
default: | |
strcpy( char2.weapon, "kilic"); | |
char2.power =20; | |
break; | |
} | |
charstats(char1); | |
charstats(char2); | |
printf("düello baslasın"); | |
fight(char1,char2); | |
} | |
void charstats( struct character characters ) { | |
printf( "karakter adi : %s\n", characters.charname); | |
printf( "karakter gücü : %d\n", characters.power); | |
printf( "karakter silahı : %s\n", characters.weapon); | |
printf( "karakter sağlığı : %d\n", characters.health); | |
} | |
void fight(struct character char1 ,struct character char2){ | |
int fighttime=1 ; | |
printf("düello basladi \n"); | |
while(fighttime != 0) { | |
char1.health -= char2.power; | |
char2.health -= char1.power; | |
printf("%s nin can degeri %d\n",char1.charname,char1.health ); | |
printf("%s nin can degeri %d\n",char2.charname,char2.health ); | |
fighttime = 1; | |
if (char1.health <= 0 || char2.health<=0 ) | |
{ | |
if (char1.health >char2.health) | |
{ | |
printf("%s düelloyı kazandı \n",char1.charname); | |
}else | |
{ | |
printf("%s düelloyı kazandı\n",char2.charname); | |
} | |
fighttime = 0; | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdlib.h> | |
#include <unistd.h> | |
using namespace std; | |
/* Sıradan bir karakterin tanımlanması-I*/ | |
class Player | |
{ | |
public: | |
string charname; | |
int strength = 100; | |
int health = 100; | |
}; | |
/* Savaşçı bir karakterin tanımlanmasıI*/ | |
class Warior : public Player | |
{ | |
/*burada shield değerini public yapabilirdim fakat encapsulation çalışmak adına private olarak ekledim */ | |
private: | |
int shield; | |
int luck; | |
public: | |
string weaponname = "mızrak"; | |
int attack = 100; | |
int SetShield(int shield) | |
{ | |
health = health + shield; | |
return health; | |
} | |
int SetLuck(int luck){ | |
luck = rand() % luck + 1; | |
attack=attack+luck; | |
return attack; | |
} | |
}; | |
/* oyunun olduğu sınıf */ | |
class Game | |
{ | |
public: | |
/*bekleme fonksiyonu */ | |
void delay(int n) | |
{ | |
sleep(n); | |
} | |
/* oyuncuların envanterini sıralayan fonksiyon */ | |
void Inventory(Warior char1, Warior char2) | |
{ | |
cout << "birinci karakterin özellikleri \n"; | |
cout << "karakter ismi " | |
<< ":" << char1.charname << "\n"; | |
cout << "karakter attack" | |
<< ":" << char1.attack << "\n"; | |
cout << "karakter saglık" | |
<< ":" << char1.health << "\n"; | |
cout << "karakter kuvvet" | |
<< ":" << char1.strength << "\n"; | |
cout << "kullandığı silah" | |
<< ":" << char1.weaponname << "\n"; | |
delay(3); | |
cout << "ikinci karakterin özellikleri \n"; | |
cout << "karakter ismi" | |
<< ":" << char2.charname << "\n"; | |
cout << "karakter attack" | |
<< ":" << char2.attack << "\n"; | |
cout << "karakter saglık" | |
<< ":" << char2.health << "\n"; | |
cout << "karakter kuvvet" | |
<< ":" << char2.strength << "\n"; | |
cout << "kullandığı silah" | |
<< ":" << char2.weaponname << "\n"; | |
delay(3); | |
} | |
/*birinci karakter kazandığında çıkan output */ | |
void firstwon() | |
{ | |
cout << " " | |
<< "o" | |
<< "\t" | |
<< " " | |
<< "o" | |
<< "\n"; | |
cout << "/|\\ " | |
<< "================>" | |
<< "\t" | |
<< " " | |
<< "/|\\ " | |
<< "\n"; | |
cout << " " | |
<< "/\\ " | |
<< "\t" | |
<< " " | |
<< "/\\ " | |
<< "\n"; | |
} | |
/*birinci karakter vuruş outputu */ | |
void first() | |
{ | |
cout << " " | |
<< "o" | |
<< "\n"; | |
cout << "/|\\ " | |
<< "========>" | |
<< "\n"; | |
cout << "" | |
<< "/\\ " | |
<< "\n"; | |
} | |
/*ikinci karakter vuruş outputu */ | |
void sec() | |
{ | |
cout << "\t" | |
<< " " | |
<< "o" | |
<< "\n"; | |
cout << "<=======" | |
<< "/|\\ " | |
<< "\n"; | |
cout << "\t" | |
<< "" | |
<< " " | |
<< "/\\ " | |
<< "\n"; | |
} | |
/*ikinci karakter kazanma outputu */ | |
void secwin() | |
{ | |
cout << "o" | |
<< "\t" | |
<< "\t" | |
<< "" | |
<< " " | |
<< "o" | |
<< "\n"; | |
cout << " <=====/|\\======" | |
<< "/|\\ " | |
<< "\n"; | |
cout << "/\\ " | |
<< "\t" | |
<< "\t" | |
<< "" | |
<< "" | |
<< " " | |
<< "/\\ " | |
<< "\n"; | |
} | |
/* dövüş fonksiyonu */ | |
void fight(Warior char1, Warior char2) | |
{ | |
int fighttime = 1; | |
Inventory(char1, char2); | |
cout << "düello basladi \n"; | |
while (fighttime != 0) | |
{ | |
char1.health -= char2.attack; | |
char2.health -= char1.attack; | |
first(); | |
cout << "birinci karakter" | |
<< ":" << char1.charname << " " | |
<< "can durumu " | |
<< ":" << char1.health << "\n"; | |
delay(3); | |
sec(); | |
cout << "ikinci karakter" | |
<< ":" << char2.charname << " " | |
<< "can durumu " | |
<< ":" << char2.health << "\n"; | |
delay(3); | |
fighttime = 1; | |
if (char1.health <= 0 || char2.health <= 0) | |
{ | |
if (char1.health > char2.health) | |
{ | |
firstwon(); | |
cout << char1.charname << " kazandı \n"; | |
} | |
else | |
{ | |
secwin(); | |
cout << char2.charname << " kazandı \n"; | |
} | |
fighttime = 0; | |
} | |
} | |
} | |
}; | |
int main() | |
{ | |
/* karakter tanımlamaları -I*/ | |
Warior oguz; | |
oguz.charname = "oguz"; | |
oguz.SetShield(120); | |
oguz.SetLuck(20); | |
oguz.attack = 100; | |
oguz.strength = 100; | |
oguz.weaponname = "mizrak"; | |
/* karakter tanımlamaları -2*/ | |
Warior deniz; | |
deniz.charname = "deniz"; | |
deniz.SetShield(20); | |
deniz.SetLuck(10); | |
deniz.attack = 100; | |
deniz.strength = 100; | |
deniz.weaponname = "mizrak"; | |
Game firstFight; | |
firstFight.fight(oguz, deniz); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment