One of my first programming projects. I tried to learn C and use curses...it is quite embarrassing looking back at it now :D
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

65 lines
1.4 KiB

#include <events.h>
#include <structs.h>
#include <world.h>
#include <getPos.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <zombies.h>
void addItem(char *type, int yPos, int xPos){
if(!strcmp(type,"Pistol")){
struct Item pistolItem = {.type="Pistol", .symbol='p', .isAlive=1, .curXpos=xPos, .curYpos=yPos};
int i;
for (i=0;i<MAX_ITEMS;i++){
if(!allItems[i].isAlive){
allItems[i]=pistolItem;
break;
}
}
}
if(!strcmp(type,"Shotgun")){
struct Item shotgunItem = {.type="Shotgun", .symbol='s', .isAlive=1, .curXpos=xPos, .curYpos=yPos};
int i;
for (i=0;i<MAX_ITEMS;i++){
if(!allItems[i].isAlive){
allItems[i]=shotgunItem;
break;
}
}
}
}
void tryRandomEvent(){
int eventTrigger = (rand()%100)+1;
if (eventTrigger < 1+zombieModifier){
struct OpenPos openPos = getOpenPos();
addZombie(openPos.y, openPos.x);
}
if (eventTrigger < 5+itemModifier){
int i;
int x=0;
for (i=0;i<MAX_ITEMS;i++){
if(allItems[i].isAlive && !strcmp(allItems[i].type,"Shotgun")){
x++;
}
}
if(x==0){
struct OpenPos openPos = getOpenPos();
addItem("Shotgun", openPos.y, openPos.x);
}
}
if (eventTrigger < 10+itemModifier){
int i;
int x=0;
for (i=0;i<MAX_ITEMS;i++){
if(allItems[i].type && !strcmp(allItems[i].type,"Pistol")){
x++;
}
}
if(x<3){
struct OpenPos openPos = getOpenPos();
addItem("Pistol", openPos.y, openPos.x);
}
}
}