f

void CMapEditDlg::OnButtonSave()
{
 FILE  *pFilein;
 char caption[100];
 //»ñÈ¡Ò¶ÃæÄÚÈÝ
 strcpy(caption,csMapName);
 
 char stype[100];
 strcpy(stype,csMapStyle);
 char texture[100];
 CString csTemp = _T("");
 csTemp.Format(_T("%d"),m_nFloorNum);
 strcpy(texture,csTemp);
 char music[100];
 strcpy(music,csMapMusic);
//  int height = m_nHeight;
//  int width = m_nWidth;
//  int t = 0;
//  int mymap[143];
//
//
//  for (int i = 0; i < width; i++)
//  {
//   for (int j = 0; j < height; j++)
//   {
//    mymap[t] = t;
//    t++;
//   }
//  }
// csTemp = m_csMapPath +
// str = "C://"+m_cCaption+".map";
 //**************************************************************************
    if ((pFilein = fopen(csTemp, "ab+")) == NULL)
    {
      printf("cannot open file");
      exit(0);
    }
    FILE *stream = tmpfile();//´´½¨ÁÙʱÎļþ
    fwrite(&caption, 100, 1, stream); // ½«ÄÚÈÝдÈëÁÙʱÎļþ
 fwrite(&stype, 100, 1, stream);
 fwrite(&texture, 100, 1, stream);
 fwrite(&music, 100, 1, stream);
 m_progress.SetPos(1);
 int i = 2;
 for (int nRow = 0; nRow < 11; nRow++)
 {
  for (int nCol = 0; nCol < 13; nCol++)
  {
   fwrite(&m_stMapObj[nRow][nCol],16,1,stream);
   i++;
   int n = static_cast<int>((static_cast<float>(i)/static_cast<float>(286))*100);
   m_progress.SetPos(n);
  }
 }
 rewind(stream);//ÒÆÖÁÎļþÍ·
 //¼ÓÃÜÎļþ

 char ch;
 ch=fgetc(stream);
 CString s = _T("passwordfsdfasdfasdf");
 char *psw = s.GetBuffer(0);
 int j = 0;
  i = 0;
 while(psw[++i]);
 int z = 0;
 while(!feof(stream))
 {
  ch=ch^psw[j>=i?j=0:j++];
  
  fputc(ch,pFilein);
  ch=fgetc(stream);
  z++;
  int n= 50 + static_cast<int>((static_cast<float>(z)/static_cast<float>(5376))*100);
  m_progress.SetPos(n);
 }
 _rmtmp();//ɾ³ýÁÙʱÎļþ
    fclose(pFilein);
  m_progress.ShowWindow(FALSE);
 m_progress.SetPos(0);
}
void CMapEditDlg::ReadMap()
{
 FILE *pFileout;  // Îļþ²Ù×÷Ö¸Õë
 char caption[100] = "";
 char stype[100] = "";
 char texture[100] = "";
 char music[100] = "";
 int t = 0;
 CString str;
 // ÒÔ¶þ½øÖÆ·½Ê½´ò¿ªuser.datÎļþ
 CFileDialog dlg(TRUE,"*.map",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"Map Files (*.map)|*.map|",NULL);
 if (dlg.DoModal() == IDOK)
 {
  str = dlg.GetPathName();
 }
 else
 {
  return;
 }
 if ((pFileout = fopen(str, "rb")) == NULL)
 {
  printf("cannot open file");
  exit(0);
 }
 // ³É¿é´ÓÎļþÖжÁÈ¡
 FILE *stream = tmpfile();//´´½¨ÁÙʱÎļþ
 //½âÃÜÎļþ
 char ch;

 ch=fgetc(pFileout);
 CString s = _T("passwordfsdfasdfasdf");
 char *psw = s.GetBuffer(0);
 int a,b;
 b = a = 0;
 while(psw[++a]);
 int z = 0;
 while(!feof(pFileout))
 {
  ch=ch^psw[b>=a?b=0:b++];
  fputc(ch,stream);
  ch=fgetc(pFileout);
  z++;
  int n= static_cast<int>((static_cast<float>(z)/static_cast<float>(5376))*100);
  m_progress.SetPos(n);
 }
 fclose(pFileout);
 rewind(stream);//ÒÆÖÁÎļþÍ·
 fread(&caption, 100, 1, stream);
 fread(&stype, 100, 1, stream);
 fread(&texture, 100, 1, stream);
 fread(&music, 100, 1, stream);
 int i = 0;
 for (int nRow = 0; nRow < 11; nRow++)
 {
  for (int nCol = 0; nCol < 13; nCol++)
  {
   fwrite(&m_stMapObj[nRow][nCol],16,1,stream);
   i++;
   int n = 50 + static_cast<int>((static_cast<float>(i)/static_cast<float>(286))*100);
   m_progress.SetPos(n);
  }
 }
 _rmtmp();//ɾ³ýÁÙʱÎļþ
 m_progress.ShowWindow(FALSE);
 m_progress.SetPos(0);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值