-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cc
116 lines (105 loc) · 1.85 KB
/
player.cc
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "player.h"
// Constructor function
player::player( char* inname, char* inteam, char* inrtn, const char* inpos )
{
snprintf( name, NAMELEN, "%s", inname );
snprintf( team, TEAMLEN, "%s", inteam );
snprintf( rtn, TEAMLEN, "%s", inrtn );
pos = (char*) calloc( POSLEN, sizeof(char));
snprintf( pos, POSLEN, "%s", inpos );
ab = h = r = rbi = b2 = b3 = hr = bb = k = sb = cs = pal = par = 0;
posn = getpos( pos );
}
void
player::hit( int i )
{
h++;
ab++;
switch ( i ) {
case 2:
b2++;
break;
case 3:
b3++;
break;
case 4:
hr++;
break;
}
}
void
player::sout(FILE *fp)
{
fprintf(fp,"%-8s %-5s%-5s%-17s%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d%3d",
pos,team,rtn,name,ab,r,h,rbi,b2,b3,hr,sb,cs,bb,k,pal,par);
}
char*
player::nout()
{
return( name );
}
char*
player::pout()
{
char *p;
if ( strlen( pos ) < 3 )
return( pos );
else
p = strrchr( pos, int('-') );
return( ++p );
}
void
player::pa( char c )
{
if ( c=='r' || c=='R' )
par++;
if ( c=='l' || c=='L' )
pal++;
}
void
player::new_pos( char *newpos )
{
// extend pos string
pos = (char*) realloc( pos, strlen(pos) + strlen(newpos) + 2 );
snprintf( pos + strlen(pos), 4, "-%s", newpos );
posn = getpos( newpos );
}
int
player::getpos( char *posstr )
{
switch ( *posstr ) {
case '1' :
return( 3 );
case '2' :
return( 4 );
case '3' :
return( 5 );
case 's' :
case 'S' :
return( 6 );
case 'l' :
case 'L' :
return( 7 );
case 'r' :
case 'R' :
return( 9 );
case 'c' :
case 'C' :
switch ( *(posstr+1) ) {
case 'f' :
case 'F' :
return( 8 );
default :
return( 2 );
}
default :
return( 0 );
}
}
player::~player()
{
free(pos);
#ifdef DEBUG
fprintf(stderr,"deleted %s\n",this->nout());
#endif
}