C语言拼图游戏实验报告
课程设计实验报告
班级:光电104—2 姓名:刘云龙 学号:201058501220
一、实验题目:使用C语言编写一个小游戏(拼图游戏)
二、实验目的:C语言是每一个通信学生的必修课之一,此次课程设计要求我们使用C语言编写一个小游戏,在完成课程设计的过程中,加强了我们对C语言的综合应用。虽然在平时的课堂上积累了很多的理论知识,但在实际应用时还是有很多不明白的地方。为了更好地完成实验要求,通过翻课本,请教同学,在网上查找资料等途径解决了试验中遇到的疑难。在完成实验的过程中,暴露了自己在C语言学习上的很多不足和缺陷,同时也解决了很多平时不明白的地方。
三、实验内容
本次试验选定的实验项目是使用C语言编写一个拼图游戏
以下是拼图游戏的源代码:
// 九宫格拼图Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "九宫格拼图.h"
#include "九宫格拼图Dlg.h"
#include "spell.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CSpell spell(3, 3, 2, 2);
//
//
void ShowTranBmp(CDC * dc, CBitmap * bmp, COLORREF bgcolor, int x, int y, int w, int h, int bx, int by, int bw, int bh){
CDC mdc;
CDC tdc; // 图像
CDC ddc; // 遮罩
CBitmap tbmp;
CBitmap dbmp;
CBitmap *ob;
CBitmap *tob;
CBitmap *dob;
mdc.CreateCompatibleDC(dc);
tdc.CreateCompatibleDC(dc);
ddc.CreateCompatibleDC(dc);
tbmp.CreateBitmap(bw, bh, 1, 32, NULL);
dbmp.CreateBitmap(bw, bh, 1, 1, NULL);
ob = mdc.SelectObject(bmp);
tob = tdc.SelectObject(&tbmp);
dob = ddc.SelectObject(&dbmp);
tdc.BitBlt(-bx, -by, bw+bx, bh+by, &mdc, 0, 0, SRCCOPY);
tdc.SetBkColor(bgcolor);
ddc.BitBlt(0, 0, bw, bh, &tdc, 0, 0, SRCCOPY);
///
//显示
dc->BitBlt(x, y, w, h, &tdc, 0, 0, SRCINVERT);
dc->BitBlt(x, y, w, h, &ddc, 0, 0, SRCAND);
dc->BitBlt(x, y, w, h, &tdc, 0, 0, SRCINVERT);
mdc.SelectObject(ob);
tdc.SelectObject(tob);
ddc.SelectObject(dob);
}
void ShowTranBmp(CDC * dc, CBitmap * bmp, COLORREF bgcolor, int x, int y, int w, int h){
CDC tdc; // 图像
CDC ddc; // 遮罩
CBitmap dbmp;
CBitmap *tob;
CBitmap *dob;
tdc.CreateCompatibleDC(dc);
ddc.CreateCompatibleDC(dc);
dbmp.CreateBitmap(w, h, 1, 1, NULL);
tob = tdc.SelectObject(bmp);
dob = ddc.SelectObject(&dbmp);
tdc.SetBkColor(bgcolor);
ddc.BitBlt(0, 0, w, h, &tdc, 0, 0, SRCCOPY);
///
//显示
dc->BitBlt(x, y, w, h, &tdc, 0, 0, SRCINVERT);