C语言暑期实习 第五天
来源:互联网 发布:淘宝优惠券怎么制作 编辑:程序博客网 时间:2024/06/02 07:30
今天的主要任务是要做一个小游戏,调出一个代码,实现运行时候,界面中的“人”字符可以走动而且不撞墙,
先附上代码:
Map.cpp
// Map.cpp: implementation of the CMap class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Map.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMap::CMap()
{
}
CMap::~CMap()
{
delete mapData;
}
void CMap::LoadMap(char *fileName)
{
FILE *fp = fopen(fileName,"r");
if(fp!=NULL)
{
fscanf(fp,"%d,%d,",&this->Rows,&this->Cols);
mapData = new int[this->Rows*this->Cols];
for(int nI=0;nI<this->Rows*this->Cols;nI++)
{
fscanf(fp,"%d,",mapData+nI);
}
fclose(fp);
}
}
void CMap::Show()
{
for(int nRow=0;nRow<this->Rows;nRow++)
{
for(int nCol=0;nCol<this->Cols;nCol++)
{
switch(mapData[nRow*this->Cols+nCol])
{
case 1:
printf("▓");
break;
default:
printf(" ");
break;
}
}
printf("\n");
}
}
-----------------------------------------------------
Map.h
// Map.h: interface for the CMap class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MAP_H__056F5E34_0A1C_479E_ADA2_9D9AF88EDB7E__INCLUDED_)
#define AFX_MAP_H__056F5E34_0A1C_479E_ADA2_9D9AF88EDB7E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMap
{
public:
int *mapData;
int Cols;
int Rows;
void LoadMap(char*);
void Show();
CMap();
virtual ~CMap();
};
#endif // !defined(AFX_MAP_H__056F5E34_0A1C_479E_ADA2_9D9AF88EDB7E__INCLUDED_)
-----------------------------
stdafx.cpp
// stdafx.cpp : source file that includes just the standard includes
// Test10.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
-------------------------------------------
stdafx.h
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__406F7DEA_77AB_4743_AD6F_9C584D869C17__INCLUDED_)
#define AFX_STDAFX_H__406F7DEA_77AB_4743_AD6F_9C584D869C17__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__406F7DEA_77AB_4743_AD6F_9C584D869C17__INCLUDED_)
----------------------------------------
Test10.cpp
// Test10.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "map.h"
void main(int argc, char* argv[])
{
CMap *map = new CMap();
map->LoadMap("d:\\map.txt");
map->Show();
//......
delete map;
}
- C语言暑期实习 第五天
- C语言暑期实习 第一天
- C语言暑期实习 第三天
- C语言暑期实习 第八天
- C语言暑期实习 第七天
- C语言暑期实习 第九天
- C语言第五天
- 暑期集训第五天
- C语言暑期实习 第二天
- C语言暑期实习 第四天
- C语言暑期实习 第六天
- C语言暑期实习 第十天
- 标准C语言第五天
- IBM实习第五天
- 实习日记->第五天
- 浪潮实习第五天
- 实习篇---第五天
- 实习第五天
- 绝对可用的windows服务调试
- preg和ereg的区别
- 我收藏的IT博客网址
- linux 查看线程信息
- 25个让Java程序员更高效的Eclipse插件
- C语言暑期实习 第五天
- ubuntu 12.04下gedit查看txt中文乱码解决办法
- iptables实现端口管理,让路由器支持多端口
- 盘点Android开发者必备的十大开发工具
- 实战DeviceIoControl 之一:通过API访问设备驱动程序
- 回调函数
- 内部类
- MySQL重复安装时一直提示服务启动失败的解决办法!
- 视频和图片的相互转换