Init commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include "class.h"
|
||||||
|
|
||||||
|
void moveHuman(Humanoid_t* self, int Horizontal, int Vertical){
|
||||||
|
printf("My name is : %s", self->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lookHuman(Humanoid_t* self, int Horizontal, int Vertical){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void removeHuman(Humanoid_t* self){
|
||||||
|
if (self != NULL){
|
||||||
|
// Free malloced internals first
|
||||||
|
free(self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Humanoid_t* InitHuman(char* PlayerName){
|
||||||
|
|
||||||
|
assert(strlen(PlayerName) < MaxNameLength && "Name is too long!");
|
||||||
|
|
||||||
|
Humanoid_t* human = malloc(sizeof(Humanoid_t));
|
||||||
|
human->health = StartingHelath;
|
||||||
|
strncpy(human->name, PlayerName, MaxNameLength - 1);
|
||||||
|
human->move = moveHuman;
|
||||||
|
human->look = lookHuman;
|
||||||
|
human->remove = removeHuman;
|
||||||
|
|
||||||
|
return human;
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define MaxNameLength 100
|
||||||
|
#define StartingHelath 100
|
||||||
|
|
||||||
|
typedef struct Humanoid Humanoid_t;
|
||||||
|
|
||||||
|
struct Humanoid {
|
||||||
|
char name[MaxNameLength];
|
||||||
|
float health;
|
||||||
|
void (*move)(Humanoid_t* self, int x, int y);
|
||||||
|
void (*look)(Humanoid_t* self, int x, int y);
|
||||||
|
void (*remove)(Humanoid_t* self);
|
||||||
|
};
|
||||||
|
|
||||||
|
Humanoid_t* InitHuman(char* PlayerName);
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "class.h"
|
||||||
|
|
||||||
|
int main(int argc, char** argv){
|
||||||
|
|
||||||
|
Humanoid_t* Player1 = InitHuman("Derek Hollowy");
|
||||||
|
Player1->move(Player1, 4, 9);
|
||||||
|
|
||||||
|
Player1->remove(Player1);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user