-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplay.cpp
More file actions
69 lines (56 loc) · 1.44 KB
/
Replay.cpp
File metadata and controls
69 lines (56 loc) · 1.44 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
#include"stdafx.h"
#include"Replay.h"
#include<string.h>
CReplay::CReplay()
{
m_pFile = nullptr;
}
CReplay::~CReplay()
{
}
void CReplay::OpenFile(char* argFileName)
{
m_readFileName = new char[strlen(argFileName) + 1];
strcpy(m_readFileName, argFileName);
m_pFile = fopen(m_readFileName, "rb");
if (m_pFile==nullptr)
{
perror("打开文件失败: ");
}
}
void CReplay::ReadRunTime(clock_t *time)
{
fseek(m_pFile, 0, SEEK_SET);
fread(time, sizeof(clock_t), 1, m_pFile);
fseek(m_pFile, 0x20, SEEK_SET);
}
void CReplay::ReadData(CFood* food, CSnake* snake, clock_t *time)
{
//食物
fread(&food->m_nRow, 1, sizeof(food->m_nRow), m_pFile);
fread(&food->m_nCol, 1, sizeof(food->m_nCol), m_pFile);
fread(&food->m_nShapeID, 1, sizeof(food->m_nShapeID), m_pFile);
fread(&food->m_nFoodColorID, 1, sizeof(food->m_nShapeID), m_pFile);
//蛇:长度、方向、结点
int nCount = snake->m_Body.size();
fread(&nCount, 1, sizeof(nCount), m_pFile);
fread(&snake->m_eDir, 1, sizeof(snake->m_eDir), m_pFile);
for (int i = 0; i < nCount; i++)
{
tagSnakeNode* pNewNode = new tagSnakeNode(0, 0);
fread(&pNewNode->m_nRow, 1,
sizeof(pNewNode->m_nRow), m_pFile);
fread(&pNewNode->m_nCol, 1,
sizeof(pNewNode->m_nCol), m_pFile);
snake->m_Body.push_back(pNewNode);
}
//时间
fread(time, 1, sizeof(clock_t), m_pFile);
}
void CReplay::CloseFile()
{
if (m_pFile!=nullptr)
{
fclose(m_pFile);
}
}