-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcell.c
More file actions
executable file
·74 lines (64 loc) · 1.56 KB
/
cell.c
File metadata and controls
executable file
·74 lines (64 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* cell.c */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "baize.h"
#include "pile.h"
#include "array.h"
#include "cell.h"
static struct PileVtable cellVtable = {
&CellCanMoveTail,
&CellCanAcceptCard,
&CellCanAcceptTail,
&GenericTailTapped,
&CellCollect,
&CellComplete,
&PileInertUnsortedPairs,
&PileReset,
&PileUpdate,
&PileDraw,
&PileFree,
};
struct Cell* CellNew(struct Baize *const baize, Vector2 slot, enum FanType fan)
{
struct Cell* self = calloc(1, sizeof(struct Cell));
if ( self ) {
PileCtor(baize, (struct Pile*)self, "Cell", slot, fan);
self->super.vtable = &cellVtable;
}
return self;
}
_Bool CellCanMoveTail(struct Array *const tail)
{
(void)tail;
return 1;
}
_Bool CellCanAcceptCard(struct Baize *const baize, struct Pile *const self, struct Card *const c)
{
(void)c;
if ( !PileEmpty(self) ) {
BaizeSetError(baize, "(CSOL) Can only move a card to an empty Cell");
return 0;
}
return 1;
}
_Bool CellCanAcceptTail(struct Baize *const baize, struct Pile *const self, struct Array *const tail)
{
if ( ArrayLen(tail) != 1 ) {
BaizeSetError(baize, "(CSOL) Can only move a single card to a Cell");
return 0;
}
if ( !PileEmpty(self) ) {
BaizeSetError(baize, "(CSOL) Can only move a card to an empty Cell");
return 0;
}
return 1;
}
int CellCollect(struct Pile *const self)
{
return PileGenericCollect(self);
}
_Bool CellComplete(struct Pile *const self)
{
return PileEmpty(self);
}