Browse Source

Merge pull request #9 from Mac10goesBRRRT/nextcycle

Nextcycle
remotes/origin/orga
Mac10goesBRRRT 2 years ago
committed by GitHub
parent
commit
6195ef36b0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 162
      src/c/character.c
  2. 53
      src/c/character.h
  3. 36
      src/c/encounter.c
  4. 2
      src/c/encounter.h
  5. 46
      src/c/spell.c
  6. 20
      src/c/spell.h
  7. 2
      test/c/test_character.c
  8. 65
      test/c/test_spell.c

162
src/c/character.c

@ -3,6 +3,7 @@
#include <string.h> #include <string.h>
#include "character.h" #include "character.h"
#include "spell.h"
Character character; Character character;
@ -172,4 +173,165 @@ int calculateDamage (Character *character,Weapon *weapon) {
default: default:
return 1; return 1;
} }
}
void setCharacterStatPoints (Character* character, int newStatPoints) {
character->statPoints = newStatPoints;
}
int getCharacterStatPoints (Character* character) {
return character->statPoints;
}
void initializeCharacter (Character *character,int weaponClass) {
setCharacterHealthPoints(character,100);
setCharacterStrength(character,10);
setCharacterDexterity(character,10);
setCharacterIntelligence(character,10);
setCharacterLevel(character,1);
setCharacterExp(character,0);
setCharacterMaxExp(character,100);
setCharacterMaxHealthPoints(character,100);
setCharacterAttack(character,10);
setCharacterArmor(character,0);
setCharacterGold(character,0);
setCharacterName(character,"Player");
setCharacterWeaponClass(character,weaponClass);
setCharacterStatPoints(character,0);
}
void setItemID (Item *item, int newID) {
item->id = newID;
}
int getItemID (Item *item) {
return item->id;
}
void setItemAmount (Item *item, int newAmount) {
item->amount = newAmount;
}
int getItemAmount (Item *item) {
return item->amount;
}
void setItemDamage (Item *item, int newDamage) {
item->damage = newDamage;
}
int getItemDamage (Item *item) {
return item->damage;
}
void setItemHealing (Item *item, int newHealing) {
item->healing = newHealing;
}
int getItemHealing (Item *item) {
return item->healing;
}
void setItemMana (Item *item, int newMana) {
item->mana = newMana;
}
int getItemMana (Item *item) {
return item->mana;
}
void setItemName (Item *item, char newName[]) {
strcpy(item->name,newName);
}
char* getItemName (Item *item) {
return item->name;
}
void setCharacterStatus (Character *character, int newStatus) {
character->status = newStatus;
}
int getCharacterStatus (Character *character) {
return character->status;
}
void setCharacterStatusDuration (Character *character, int newStatusDuration) {
character->statusDuration = newStatusDuration;
}
int getCharacterStatusDuration (Character *character) {
return character->statusDuration;
}
void initializeInventory (Character *character) {
for (int i = 0; i < 10; i++)
{
character->inventory[i] = NULL;
}
}
void putItemInInventory (Character *character, Item *item,int inventorySlot) {
if(inventorySlot > 9) {
printf("Inventory slot is out of range (0-9)\n");
} else if (inventorySlot < 0) {
printf("Inventory slot is out of range (0-9)\n");
} else if (character->inventory[inventorySlot] == NULL) {
printf("Inventory slot is already occupied\n");
} else {
character->inventory[inventorySlot] = item;
}
}
Item * getItemInInventory (Character *character, int inventorySlot) {
if(inventorySlot > 9) {
printf("Inventory slot is out of range (0-9)\n");
return NULL;
} else if (inventorySlot < 0) {
printf("Inventory slot is out of range (0-9)\n");
return NULL;
} else if (character->inventory[inventorySlot] == NULL) {
printf("Inventory slot is empty\n");
return NULL;
} else {
return character->inventory[inventorySlot];
}
}
int checkStatus (Character *character) {
switch (character->status)
{
case SPELL_EFFECT_NONE:
break;
case SPELL_EFFECT_BURN:
setCharacterStatusDuration(character,getCharacterStatusDuration(character)-1);
if (getCharacterStatusDuration == 0) {
setCharacterStatus(character,SPELL_EFFECT_NONE);
}
return getCharacterStatus(character);
break;
case SPELL_EFFECT_FREEZE:
setCharacterStatusDuration(character,getCharacterStatusDuration(character)-1);
if (getCharacterStatusDuration == 0) {
setCharacterStatus(character,SPELL_EFFECT_NONE);
}
return getCharacterStatus(character);
break;
case SPELL_EFFECT_STUN:
setCharacterStatusDuration(character,getCharacterStatusDuration(character)-1);
if (getCharacterStatusDuration == 0) {
setCharacterStatus(character,SPELL_EFFECT_NONE);
}
return getCharacterStatus(character);
break;
case SPELL_EFFECT_REGENERATION:
setCharacterStatusDuration(character,getCharacterStatusDuration(character)-1);
if (getCharacterStatusDuration == 0) {
setCharacterStatus(character,SPELL_EFFECT_NONE);
}
return getCharacterStatus(character);
break;
default:
return getCharacterStatus(character);
break;
}
} }

53
src/c/character.h

@ -1,10 +1,15 @@
#ifndef CHARACTER_H #ifndef CHARACTER_H
#define CHARACTER_H #define CHARACTER_H
typedef struct {
int id,amount,damage,healing,mana;
char name [50];
} Item;
typedef struct { typedef struct {
int strength,dexterity,intelligence,healthPoints,manaPoints,level,exp,maxExp; int strength,dexterity,intelligence,healthPoints,manaPoints,level,exp,maxExp;
int attack,armor,maxHealthPoints,gold,items[10],weaponClass;
int attack,armor,maxHealthPoints,gold,weaponClass,statPoints,status,statusDuration;
char name [50]; char name [50];
Item *inventory[10];
} Character; } Character;
typedef struct { typedef struct {
int attack,durability; int attack,durability;
@ -85,4 +90,50 @@ int getWeaponDurability (Weapon *weapon);
int setWeaponDurability (Weapon *weapon, int newDurability); int setWeaponDurability (Weapon *weapon, int newDurability);
int calculateDamage (Character *character,Weapon *weapon); int calculateDamage (Character *character,Weapon *weapon);
void setCharacterStatPoints (Character *character, int newStatPoints);
int getCharacterStatPoints (Character *character);
void initializeCharacter (Character *character,int weaponClass);
void setItemID (Item *item, int newID);
int getItemID (Item *item);
void setItemAmount (Item *item, int newAmount);
int getItemAmount (Item *item);
void setItemDamage (Item *item, int newDamage);
int getItemDamage (Item *item);
void setItemHealing (Item *item, int newHealing);
int getItemHealing (Item *item);
void setItemMana (Item *item, int newMana);
int getItemMana (Item *item);
void setItemName (Item *item, char newName[]);
char* getItemName (Item *item);
void putItemInInventory (Character *character, Item *item, int inventorySlot);
void initializeInventory (Character *character);
Item * getItemInInventory (Character *character, int inventorySlot);
void setCharacterStatus (Character *character, int newStatus);
int getCharacterStatus (Character *character);
void setCharacterStatusDuration (Character *character, int newStatusDuration);
int getCharacterStatusDuration (Character *character);
int checkStatus (Character *character);
#endif #endif

36
src/c/encounter.c

@ -201,4 +201,40 @@ void setEnemyExp(enemy* enemy, int newExp){
int getEnemyGold(enemy* enemy){ int getEnemyGold(enemy* enemy){
return enemy->gold; return enemy->gold;
}
int setEnemyGold(enemy* enemy, int newGold){
enemy->gold = newGold;
}
int createRandomEnemy(enemy* enemy)
{
int enemyType = randomIntRange(1, 3);
switch(enemyType)
{
case 1:
setEnemyHealth(enemy, 20);
setEnemyDamage(enemy, 5);
setEnemyArmor(enemy, 2);
setEnemyHealPotions(enemy, 1);
setEnemyExp(enemy, 10);
setEnemyGold(enemy, 10);
break;
case 2:
setEnemyHealth(enemy, 30);
setEnemyDamage(enemy, 10);
setEnemyArmor(enemy, 5);
setEnemyHealPotions(enemy, 2);
setEnemyExp(enemy, 20);
setEnemyGold(enemy, 20);
break;
case 3:
setEnemyHealth(enemy, 40);
setEnemyDamage(enemy, 15);
setEnemyArmor(enemy, 10);
setEnemyHealPotions(enemy, 3);
setEnemyExp(enemy, 30);
setEnemyGold(enemy, 30);
break;
}
return enemyType;
} }

2
src/c/encounter.h

@ -46,4 +46,6 @@ void setEnemyHealPotions(enemy* enemy, int newPotions);
int getEnemyExp(enemy* enemy); int getEnemyExp(enemy* enemy);
void setEnemyExp(enemy* enemy, int newExp); void setEnemyExp(enemy* enemy, int newExp);
int createRandomEnemy(enemy* enemy);
#endif #endif

46
src/c/spell.c

@ -0,0 +1,46 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "character.h"
#include "spell.h"
SpellEffect spellFireball(Character *character) {
SpellEffect fireball;
fireball.damage = 10 + (getCharacterIntelligence(character) / 2);
fireball.healing = 0;
fireball.manaCost = 10;
fireball.effect = SPELL_EFFECT_NONE;
fireball.effectDuration = 0;
return fireball;
}
SpellEffect spellHeal(Character *character) {
SpellEffect heal;
heal.damage = 0;
heal.healing = 10 + (getCharacterIntelligence(character) / 3);
heal.manaCost = 10;
heal.effect = SPELL_EFFECT_NONE;
heal.effectDuration = 0;
return heal;
}
SpellEffect spellLightning(Character *character) {
SpellEffect lightning;
lightning.damage = 10 + (getCharacterIntelligence(character) / 2);
lightning.healing = 0;
lightning.manaCost = 10;
lightning.effect = SPELL_EFFECT_STUN;
lightning.effectDuration = 1;
return lightning;
}
SpellEffect spellRegeneration (Character *character) {
SpellEffect regeneration;
regeneration.damage = 0;
regeneration.healing = 5 + (getCharacterIntelligence(character) / 4);
regeneration.manaCost = 10;
regeneration.effect = SPELL_EFFECT_REGENERATION;
regeneration.effectDuration = 2;
return regeneration;
}

20
src/c/spell.h

@ -0,0 +1,20 @@
#ifndef SPELL_H
#define SPELL_H
typedef struct {
int damage, healing, manaCost, effect, effectDuration;
} SpellEffect;
enum {
SPELL_EFFECT_NONE = 0, SPELL_EFFECT_BURN = 1, SPELL_EFFECT_FREEZE = 2, SPELL_EFFECT_STUN =3 , SPELL_EFFECT_REGENERATION = 4
};
SpellEffect spellFireball(Character *character);
SpellEffect spellHeal(Character *character);
SpellEffect spellLightning(Character *character);
SpellEffect spellRegeneration (Character *character);
#endif

2
test/c/test_character.c

@ -124,6 +124,8 @@ void test_levelUp_notEnoughExp_loseExp (void) {
} }
void test_calculateDamage_Sword (void) { void test_calculateDamage_Sword (void) {
setCharacterWeaponClass(&testCharacter2,SWORD);
TEST_ASSERT_EQUAL_INT(25,calculateDamage(&testCharacter2,&testWeapon)); TEST_ASSERT_EQUAL_INT(25,calculateDamage(&testCharacter2,&testWeapon));
} }

65
test/c/test_spell.c

@ -0,0 +1,65 @@
#ifdef TEST
#include "unity.h"
#include "character.h"
#include "spell.h"
Character testCharacter;
Character testCharacter2;
void setUp(void)
{
testCharacter.healthPoints = 0;
testCharacter2.healthPoints = 15;
testCharacter.strength = 0;
testCharacter2.strength = 5;
testCharacter.dexterity = 0;
testCharacter2.dexterity = 5;
testCharacter.intelligence = 0;
testCharacter2.intelligence = 7;
testCharacter.level = 0;
testCharacter2.level = 5;
testCharacter.exp = 50;
testCharacter2.exp = 110;
testCharacter.maxExp = 100;
testCharacter2.maxExp = 100;
testCharacter.attack = 5;
testCharacter2.weaponClass = SWORD;
}
void tearDown(void)
{
}
void test_spellFireball(void)
{
int result = spellFireball(&testCharacter).damage;
TEST_ASSERT_EQUAL_INT(10,result);
result = spellFireball(&testCharacter2).damage;
TEST_ASSERT_EQUAL_INT(13,result);
}
void test_spellHeal(void)
{
int result = spellHeal(&testCharacter).healing;
TEST_ASSERT_EQUAL_INT(10,result);
result = spellHeal(&testCharacter2).healing;
TEST_ASSERT_EQUAL_INT(12,result);
}
void test_spellLightning(void)
{
int result = spellLightning(&testCharacter).damage;
TEST_ASSERT_EQUAL_INT(10,result);
result = spellLightning(&testCharacter2).damage;
TEST_ASSERT_EQUAL_INT(13,result);
}
void test_spellRegeneration(void)
{
int result = spellRegeneration(&testCharacter).healing;
TEST_ASSERT_EQUAL_INT(5,result);
result = spellRegeneration(&testCharacter2).healing;
TEST_ASSERT_EQUAL_INT(6,result);
}
#endif // TEST
Loading…
Cancel
Save