-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.c
executable file
·94 lines (84 loc) · 1.27 KB
/
stack.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdlib.h>
#include <stdio.h>
#include <ncurses.h>
#include "stack.h"
void
push (STACK *p_s, CARD *p_c)
{
if (p_s->top < 52)
{
p_s->p_cards[p_s->top] = p_c;
p_s->top++;
}
return;
}
CARD *
pop (STACK *p_s)
{
if (p_s->top > 0)
{
p_s->top--;
return p_s->p_cards[p_s->top];
}
return NULL;
}
CARD *
peek (STACK* p_s)
{
if (p_s->top > 0)
{
return p_s->p_cards[p_s->top - 1];
}
return NULL;
}
void
unselect (STACK *p_s)
{
p_s->selected = 0;
}
CARD *
select (STACK *p_s)
{
if (p_s->selected < 2
|| !p_s->p_cards[p_s->selected - 2]->isOpen)
{
p_s->selected = p_s->top;
return p_s->p_cards[p_s->selected - 1];
}
p_s->selected--;
return p_s->p_cards[p_s->selected - 1];
}
CARD *
selected (STACK *p_s)
{
if (!p_s->selected)
return NULL;
return p_s->p_cards[p_s->selected - 1];
}
void
print_stack (STACK *p_s)
{
int i;
printw ("%c:", p_s->key);
if (p_s->selected)
attron (A_BLINK);
if (p_s->isPile)
{
print_card (peek (p_s));
if (p_s->selected)
printw ("<");
}
else
{
for (i = 0; i < p_s->top; i++)
{
print_card (p_s->p_cards[i]);
if (i == p_s->selected - 1)
printw ("<");
}
}
if (p_s->selected)
{
attroff (A_BLINK);
}
}