X-PLOD3
Here's the code for a new game That I've created! It's called X-PLOD3 (pronounced as explode)... The idea of the game sprouted when I and my brother along with our friends Stephen and Ephraim sat down. Earlier in the day, Ephraim played my Hand Cricket game and got surprisingly hooked to it :). It was really motivational to see someone like my game! After a while, he (Ephraim) came up to me and asked if I had any other games other than the 2 (both which I have blogged). I said no but, I also mentioned that If he had any idea then I'd make it into one. He said let's do something new and we started spitting out ideas and as a result of that mindless mixture of ideas this game took its shape. Well, enough said. Now about the game.
The game's rules are simple.
- At each turn, 5 missiles randomly head towards the Earth, each randomly in any of the three 120 degree sectors (left sector, middle sector and the right sector).
- At each turn, you have 5 missiles to allocate in the three sectors.
- You have 1000 defences... if you assign less number than the approaching missiles in the particular sector then you are hit and lose 50 defences for each hit.
- there's a not so complex scoring mechanism (score actually here is the number of days survived)
- The game ends once you reach 0 defences or below.
Some interesting things I tried....
- The starting of the game is a Riddle!
- See the screen shot and see if you can solve it :) (quite simple, let me know via comments)
- One more thing is that after you assign missiles in the 3 sectors and also the computer finishes assigning the outcome is shown in the form of a diagram of Asterisk!
- The numbers inside circle indicate your assignments and outer the asteroids approaching.
- And finally your score would be permanently saved in files and you can see them by accessing HISTORY option in the main menu!
Without further ado here's the code (and as always, if you have any doubts feel free to ask me via comments :) )
//asteroid blaster (X-PLOD3) with the help of epu
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <conio.h>
struct player
{
char name[100];
int score;
int health;
int waves;
}player1;
struct attack
{
int left;
int middle;
int right;
}player1_opt = {0,0,0},bot_opt = {0,0,0};
struct message
{
int hit_left, hit_middle, hit_right;
int miss_left, miss_middle, miss_right;
int update_score, update_health;
}message1;
void clear()
{
system("cls");
}
void flush()
{
int c;
while( ((c = getchar())!='\n') && c != EOF );
}
void new()
{
player1.health = 1000;
player1.score = 0;
player1.waves = 0;
}
//function proto-types :
void intro();
void intro_story();
int intro_password();
void menu();
void game();
void game_story();
void stats();
void entry();
void game_machine();
void display();
void controls();
void history();
void about();
int main(void)
{
srand(time(NULL));
intro(0);
clear();
menu();
}
void intro(int play)
{
intro_story(play);
while( !( intro_password() ) )
{
printf("WRONG pass-code! try again\n\n");
getch();
clear();
intro_story(1);
}
printf("SUCCESS! press any key to take control over X-PLOD3\n\n");
getch();
clear();
menu();
}
void intro_story(int flag)
{
clear();
printf("It's the ye(a)r 2077....");
if (flag == 0) getch();
printf("\nThe year when a massive cosmic ex(p)losion millions (o)f light years away took pla(c)e");
if (flag == 0) getch();
printf("\nThe explosion m(a)de a great number of extraterrestria(l) bodies head towards our home EARTH !");
if (flag == 0) getch();
printf("\nThere is onl(y) one machine in which our future de(p)end(s)....");
if (flag == 0) getch();
printf("\nIt's th(e) X-PLOD3 !");
if (flag == 0) getch();
printf("\n\n\n\n");
}
int intro_password()
{
int flag;
char passcode[100];
printf("\tEnter the pass-code : ");
scanf("%99[^\n]",passcode);
clear();
flush();
if(!strcmp(passcode,"apocalypse"))
{
flag = 1;
}
else
{
flag = 0;
}
return flag;
}
void menu()
{
int opt;
printf("\n\n\t\t\tX-PLOD3 VER 1.0");
printf("\n\n\n===============================================================================\n");
printf("\n\n\n\n\n\t\t\t1.SHOOT EM' UP\n\n\t\t\t2.CONTROLS GUIDE\n\n\t\t\t3.HISTORY\n\n\t\t\t4.ABOUT\n\n\t\t\t5.EXIT");
printf("\n\n\n\t\tenter your selection : ");
scanf("%d",&opt);
flush();
switch(opt)
{
case 1:
clear();
game();
break;
case 2:
clear();
controls();
break;
case 3:
clear();
history();
break;
case 4:
clear();
about();
break;
case 5:
exit(0);
default :
clear();
printf("Invalid Entry");
menu();
}
}
void game()
{
new();
game_story();
while( player1.health > 0 )
{
stats();
entry();
game_machine();
stats();
display();
}
clear();
player1.score += (player1.waves - 1)*10 ;
printf("\n\nStats :\n\n");
printf("\n\n * Name of the Captain : %20s", player1.name);
printf("\n\n * Days survived : %20d", player1.score);
printf("\n\nAye Captain %s, I'll make sure your epic stand will be noted down in HISTORY!",player1.name);
FILE *p;
p = fopen("HISTORY.txt","a");
fprintf(p,"Captain %s protected Earth from %d waves of disastrous meteor showers and helped people survive %d days!\n", player1.name, player1.waves, player1.score);
fclose(p);
printf("\n\n\tGAME OVER!\n\npress any key to continue....");
getch();
clear();
menu();
}
void game_story()
{
printf("Aye Captain! Let's save the Earth!...");
getch();
printf("\nWondering who am I? I'm your A.I.A (Artificial Intelligence Assistant) haha... :)");
getch();
printf("\nBefore entering X-PLOD3, err... data about your name has been lost! can I know your name :) ....");
getch();
printf("\n\n\t Name : ");
scanf(" %99[^\n]", player1.name);
flush();
printf("\n\n YES... I REMEMBER! Aye Captain %s, let's save the Earth :)", player1.name);
getch();
clear();
}
void stats()
{
printf("\n\n * Name of the Captain : %11s", player1.name);
printf("\n\n * Earth's defenses left : %4d / 1000", player1.health);
printf("\n\n * Number of waves survived : %11d", player1.waves);
printf("\n\n * Days survived : %11d", player1.score);
printf("\n\n================================================\n\n");
}
void entry()
{
printf("\n\nYou have 5 missiles left for this wave....");
printf("\n\nHow do plan to assign missiles Captain ?");
printf("\n\n\t Left : ");
scanf("%d", &player1_opt.left);
printf("\n\n\t Middle : ");
scanf(" %d", &player1_opt.middle);
printf("\n\n\t Right : ");
scanf(" %d", &player1_opt.right);
flush();
if( player1_opt.left + player1_opt.middle + player1_opt.right > 5)
{
printf("\n\n INVALID ENTRY! press any key to continue");
getch();
clear();
stats();
entry();
}
else
{
printf("all set, press any key to launch");
getch();
}
clear();
}
void game_machine()
{
int temp_score = player1.score;
int temp_health = player1.health;
bot_opt.left = (rand()%6);
bot_opt.middle = (rand()%(6 - bot_opt.left));
bot_opt.right = 5 - bot_opt.left - bot_opt.middle;
//for left
if(bot_opt.left > player1_opt.left)
{
message1.hit_left = player1_opt.left;
player1.score += 10*(bot_opt.left);
message1.miss_left = bot_opt.left - player1_opt.left;
player1.health -= 50*(bot_opt.left - player1_opt.left);
}
else if(bot_opt.left == player1_opt.left)
{
message1.hit_left = player1_opt.left;
player1.score += 20*(bot_opt.left);
message1.miss_left = 0;
}
else
{
message1.hit_left = bot_opt.left;
player1.score += 10*(bot_opt.left);
message1.miss_left = 0;
player1.score -= 5*(player1_opt.left - bot_opt.left);
}
//for middle
if(bot_opt.middle > player1_opt.middle)
{
message1.hit_middle = player1_opt.middle;
player1.score += 10*(bot_opt.middle);
message1.miss_middle = bot_opt.middle - player1_opt.middle;
player1.health -= 50*(bot_opt.middle - player1_opt.middle);
}
else if(bot_opt.middle == player1_opt.middle)
{
message1.hit_middle = player1_opt.middle;
player1.score += 20*(bot_opt.middle);
message1.miss_middle = 0;
}
else
{
message1.hit_middle = bot_opt.middle;
player1.score += 10*(bot_opt.middle);
message1.miss_left = 0;
player1.score -= 5*(player1_opt.middle - bot_opt.middle);
}
//for right
if(bot_opt.right > player1_opt.right)
{
message1.hit_right = player1_opt.right;
player1.score += 10*(bot_opt.right);
message1.miss_right = bot_opt.right - player1_opt.right;
player1.health -= 50*(bot_opt.right - player1_opt.right);
}
else if(bot_opt.right == player1_opt.right)
{
message1.hit_right = player1_opt.right;
player1.score += 20*(bot_opt.right);
message1.miss_right = 0;
}
else
{
message1.hit_right = bot_opt.right;
player1.score += 10*(bot_opt.right);
message1.miss_right = 0;
player1.score -= 5*(player1_opt.right - bot_opt.right);
}
if( (message1.miss_left + message1.miss_right + message1.miss_middle) == 0)
{
player1.score += 100;
}
message1.update_score = player1.score - temp_score;
message1.update_health = temp_health - player1.health;
player1.waves++;
}
void display()
{
printf("\n\n");
printf("*********************************************\n");
printf("* * * *\n");
printf("* * %d * *\n", bot_opt.middle);
printf("* * * *\n");
printf("* * * *\n");
printf("* * * * * * *\n");
printf("* * * * * *\n");
printf("* ** ** *\n");
printf("* * * %d * * *\n", player1_opt.middle);
printf("* * * * * *\n");
printf("* * %d * * %d * *\n", player1_opt.left, player1_opt.right);
printf("* * * * *\n");
printf("* * * * *\n");
printf("* * * * *\n");
printf("* * *\n");
printf("* * *\n");
printf("* %d * %d *\n", bot_opt.left, bot_opt.right);
printf("* * *\n");
printf("* * *\n");
printf("* * *\n");
printf("* * *\n");
printf("*********************************************\n\n");
printf("MESSAGES : \n");
printf("\n! Numbers in inside circle are missiles you assigned in particular direction.");
printf("\n! Numbers outside the circle show the extraterrestrial objects coming from that side.");
printf("\n\n* Captain, You have hit %d and missed %d missiles on the left", message1.hit_left, message1.miss_left);
printf("\n* Captain, You have hit %d and missed %d missiles in the middle", message1.hit_middle, message1.miss_middle);
printf("\n* Captain, You have hit %d and missed %d missiles on the right", message1.hit_right, message1.miss_right);
printf("\n* days survived +%d", message1.update_score);
printf("\n* waves survived +1");
printf("\n* defenses lost -%d",message1.update_health);
printf("\n\npress any key to continue......\n\n");
getch();
clear();
}
void controls()
{
FILE *p;
char c;
p = fopen("CONTROLS.txt","r");
printf("CONTROL GUIDE :\n\n\n");
while( (c = getc(p))!= EOF)
{
printf("%c",c);
}
fclose(p);
printf("\n\n\npress any key to return to menu...\n\n");
getch();
clear();
menu();
}
void history()
{
FILE *p;
char c;
p = fopen("HISTORY.txt","r");
printf("THE HISTORY OF EPIC STANDS TO SAVE THE EARTH\n\n\n");
while( (c = getc(p))!= EOF)
{
printf("%c",c);
}
printf("\n\n\nWe salute the brave Captains\n\n");
fclose(p);
printf("\n\n\npress any key to return to menu...\n\n");
getch();
clear();
menu();
}
void about()
{
printf("\n\n\n\t\t\tABOUT\n\n\n\n\n\n");
printf(" \t\tDEVOLOPED BY *******Cherub7*******\n\n\n");
printf(" \t\tPOWERED BY MARS V \n\n\n");
printf(" \t\t-------Special thanks to S.E-------");
printf("\n\n\n\npress any key and hit enter to exit : ");
getch();
clear();
menu();
}
How can I play this Awesome (not so :)) game this way:
- Copy code into your text editor
- Compile it
- Open the exe file and enjoy!
Awesome dude simply superbbbb best one.
ReplyDeleteThanks bro! Were you able to crack the riddle :)
Delete