Skip to main content

Musings about the card engine

what is a card?

A card has ability's and hooks lets look at some examples

Hooks:

  • before attack
  • attack
  • after attack
  • before receive damage
  • receive damage
  • after receive damage
  • on drop
  • on death
  • round over
  • turn over
  • card turn over
  • card moved
  • this card moved

Each one of these hooks should be an array of ability's so we can build up complex interactions

Context

Lets zoom out a bit and talk about card battle context or just context for short. Every thing in the game is going to need a common set of data to work with. Lets look at a sample context

 type GameContext={
handA:Card[],
handB:Card[],
round:number
turn:number
}
const gameContext:GameContext= {
handA:[{...},],
handB:[{...},],
round:0
turn:1
}

So with this context we can now develop an attack context.

 type AttackContext={
gameContext:GameContext,
attackingCard:Card,
defendingCard:Card
}
const attackContext:AttackContext= {
gameContext:gameContext,
attackingCard:{...},
defendingCard:{...}
}

Now this is really a lot of data to work with. This attack context is what can be passed into very hook and there for every action. Now if we implement a state system like this that can be parced in and out of some sort of plain text we can now have a context manager.


contextManager{
gameContext:GameContext[],
timeStamps:string[]
changeContext(id,newContext){
// id should be turn:round
gameContext.push(newContext)
timeStamps.push(id)
}
returnContext(){
return gameContext.last()
}

}

So with this system We can roll back turns whole rounds. That in of its self can be an action. With keeping ever state of the game we do grow our memery footprint every turn. But with a game looking to be quite short we sould be ok.