Init commit

This commit is contained in:
derek holloway
2026-03-09 18:56:08 -07:00
commit 190204b3b6
4 changed files with 62 additions and 0 deletions
+34
View File
@@ -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;
}
+16
View File
@@ -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);
+12
View File
@@ -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;
}
Executable
BIN
View File
Binary file not shown.