1 Star 0 Fork 0

reference/DesignPatternExample

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
abstract_game.c 1.69 KB
一键复制 编辑 原始数据 按行查看 历史
gigi 提交于 2016-04-23 23:08 +08:00 . update
#include <stdio.h>
#include <stdlib.h>
#include "base.h"
#include "igame.h"
#include "abstract_game.h"
static void AbstractGame_play(AbstractGame*, int);
static void AbstractGame_initialize(IGame*);
static void AbstractGame_makePlayer(IGame*, int);
static void AbstractGame_end(IGame*);
static void AbstractGame_printWinner(IGame*);
void AbstractGame_construct(void* addr)
{
if (addr == NULL) {
return NULL;
}
AbstractGame* abstractGame = addr;
abstractGame->playerCount = 0;
abstractGame->play = AbstractGame_play;
abstractGame->initialize = AbstractGame_initialize;
abstractGame->makePlayer = AbstractGame_makePlayer;
abstractGame->end = AbstractGame_end;
abstractGame->printWinner = AbstractGame_printWinner;
}
void AbstractGame_destruct(AbstractGame* abstractGame)
{
}
void AbstractGame_play(AbstractGame* abstractGame, int playerCount)
{
abstractGame->initialize(&abstractGame->igame);
abstractGame->makePlayer(&abstractGame->igame, playerCount);
abstractGame->end(&abstractGame->igame);
abstractGame->printWinner(&abstractGame->igame);
}
void AbstractGame_initialize(IGame* igame)
{
fprintf(stderr, "Not implemented!\n");
abort();
}
void AbstractGame_makePlayer(IGame* igame, int playerCount)
{
AbstractGame* abstractGame = container_of(igame, AbstractGame, igame);
abstractGame->playerCount = playerCount;
}
void AbstractGame_end(IGame* igame)
{
fprintf(stderr, "Not implemented!\n");
abort();
}
void AbstractGame_printWinner(IGame* igame)
{
AbstractGame* abstractGame = container_of(igame, AbstractGame, igame);
printf("The count of the player is %d. Player 1 is the winner!\n",
abstractGame->playerCount);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/reference/DesignPatternExample.git
git@gitee.com:reference/DesignPatternExample.git
reference
DesignPatternExample
DesignPatternExample
master

搜索帮助