可以选择关卡,设置自定义地图。
winform,windows窗体程序开发。

一、任务描述:
1.题目:推箱子小游戏2.功能描述:
(1)箱子只能推动而不能拉动。一次只能推动一个箱子。
(2)在一个狭小的仓库中,要求把木箱放到指定的位置,稍不小心就会出现箱子无法移动或者通道被堵住的情况。
(3)本游戏的目的就是把所有的箱子都推到目标位置上。

(4)通过使用键盘的方向键来控制移动方向。
(5)具有重玩本关、跳过本关的功能。

2.功能设计:
(1).能够显示主菜单和界面:允许玩家对游戏关卡进行设置,增设关卡,把编辑好的关卡进行存储,并能弹出窗体提示当前设计完成的关卡数;
(2).能够实现键盘操作功能:使用上、下、左、右方向键控制工人的移动方向,空格键重玩;
(3).能够把放置到目的地的箱子进行变色显示;
(4).游戏胜负判断功能:当玩家把箱子移动到指定位置时,成功通过当前关卡;(5).可以切换上一关、下一关、增加关卡以及重玩当前关卡;
(6).可以判断当前的关卡数,在处于第一关和最后一关时分别不能进行“前一关”和“后一关”操作,并弹出窗体进行提示;

主要分为三个层。

主要窗体层

开始界面

菜单栏设置

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using ModeLayer;
using DataLayer;
using System.Threading;namespace UILayer
{public partial class MainForm : Form{//游戏管理者GameManager manager = null;//游戏菜单窗体GameMenuForm gmf = null;public MainForm(){InitializeComponent();//窗体位于桌面中间this.StartPosition = FormStartPosition.CenterScreen;}//由游戏的行列数动态改变窗体的大小private void ChangeFormSize(){int width = manager.Gezi * manager.CurentMapRow;int height = manager.Gezi * manager.CurentMapCol;this.Size = new Size(height, width);//MessageBox.Show ("");}//窗体最小化private void MinSizeForm(){this.WindowState = FormWindowState.Minimized;}//关闭窗体private void CloseForm(){Application.Exit();}//改变窗体的背景private void ChangeBackImg(){Bitmap Img = manager.CurentBmp;if (Img == null) return;Bitmap originalBmp = (Bitmap)Img.Clone();int n = 20;Bitmap currentBmp = new Bitmap(originalBmp.Width, originalBmp.Height);//Graphics gCurrentBmp = Graphics.FromImage(currentBmp);//gCurrentBmp.FillRectangle(Brushes.White, new Rectangle(0, 0, currentBmp.Width, currentBmp.Height));//gCurrentBmp.Dispose();Graphics gPictureBox =panel1.CreateGraphics();int width = originalBmp.Width; // 表示每一块百叶窗的宽度int heightPerSlice = originalBmp.Height / n; // 表示每块百叶窗的高度 = 图片高度 / 百叶窗数目for (int i = 0; i < heightPerSlice; i++) // (for i...)循环处理每一页百叶窗的第i行,从第0行到第heightPerSlice - 1行{for (int k = 0; k < n; k++) // 循环k表示依次处理n页百叶窗,从第0到第n-1页{for (int j = 0; j < width; j++) // 循环枚举每一页百叶窗的第j列{currentBmp.SetPixel(j, k * heightPerSlice + i,originalBmp.GetPixel(j, k * heightPerSlice + i));}}// 将currentBmp按拉伸图像的方式画回pictureBox1上。gPictureBox.DrawImage(currentBmp,new Rectangle(0, 0, panel1.Width, panel1.Height), // 表示目标画板(pictureBox1)的绘图范围new Rectangle(0, 0, currentBmp.Width, currentBmp.Height),  // 表示图片源(currentBmp)的绘图范围GraphicsUnit.Pixel);System.Threading.Thread.Sleep(3); // 挂起线程,即让程序停顿100毫秒,再继续执行for循环。}gPictureBox.Dispose();originalBmp.Dispose();currentBmp.Dispose();}//加载private void MainForm_Load(object sender, EventArgs e){//窗体传值用的委托Action actChangeFormSize = new Action(ChangeFormSize);//改变窗体大小的委托Action actChangeImg = new Action(ChangeBackImg);//改变窗体背景的委托Action actMinForm = new Action(MinSizeForm);//窗体最小化的委托Action actCloseForm = new Action(CloseForm);//关闭窗体的委托manager = new GameManager(panel1);//初始化一个游戏管理者panel1.Invalidate();//获取第i关的高和宽int width = manager.Gezi * manager.CurentMapRow;int height = manager.Gezi * manager.CurentMapCol;this.Size = new Size(width, height);//菜单窗体gmf = new GameMenuForm(manager);//注册委托gmf.MinSizeForm1 = actMinForm;gmf.CloseForm = actCloseForm;//gmf.ChangeMainFormSize = act;manager.ChangeMainFormSize = actChangeFormSize;manager.ChangeBackImg = actChangeImg;gmf.Width = this.ClientSize.Width / 5;gmf.Height = this.ClientSize.Height;gmf.Show();gmf.TopMost = true;//gmf.Hide();gmf.Opacity = 0.5;//菜单窗体停靠在主窗体左边int top = this.ClientRectangle.Top;int left = this.ClientRectangle.Left;Point poin = this.PointToScreen(new Point(left, top));gmf.Location = poin;}//重回时间private void panel1_Paint(object sender, PaintEventArgs e){e.Graphics.DrawImage(manager.CurentBmp, panel1.ClientRectangle);}//按下按钮触发private void MainForm_KeyDown(object sender, KeyEventArgs e){manager.keyDownOrreStep = true;manager.RoleTryTo(e);}protected override void OnClosed(EventArgs e){base.OnClosed(e);//结束整个程序Application.Exit();}private void MainForm_MouseMove(object sender, MouseEventArgs e){//窗体移动if (isdrow){//根据鼠标的移动大小,移动窗口this.Left += MousePosition.X - currentPositionX;this.Top += MousePosition.Y - currentPositionY;currentPositionY = MousePosition.Y;currentPositionX = MousePosition.X;}//菜单栏隐藏int top = this.ClientRectangle.Top;int left = this.ClientRectangle.Left;Point poin = this.PointToScreen(new Point(left, top));gmf.Location = poin;if (e.X < this.Width / 5 && e.X > 10){gmf.Show();}else{gmf.Hide();}}private void MainForm_SizeChanged(object sender, EventArgs e){try{gmf.Width = 130;gmf.Height = this.ClientSize.Height;//panel1.Invalidate();}catch (Exception){}}private void MainForm_Move(object sender, EventArgs e){if (gmf == null){return;}int top = this.ClientRectangle.Top;int left = this.ClientRectangle.Left;Point poin = this.PointToScreen(new Point(left, top));gmf.Location = poin;}#region 无边款窗体移动int currentPositionX = 0;int currentPositionY = 0;bool isdrow = false;private void panel1_MouseDown(object sender, MouseEventArgs e){isdrow = true;currentPositionX = MousePosition.X;currentPositionY = MousePosition.Y;}private void panel1_MouseLeave(object sender, EventArgs e){//恢复起始状态currentPositionX = 0;currentPositionY = 0;isdrow = false;}private void panel1_MouseUp(object sender, MouseEventArgs e){isdrow = false;}#endregion}
}

数据层

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ModeLayer;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;namespace DataLayer
{public static class MapInfo{/// <summary>/// 获取MapInfo文件里面的信息;/// </summary>/// <returns></returns>public static List<Map> ReadMapInofFile(){List<Map> listMapDal = null;if (!File.Exists("MapInfo.bin"))return null;try{using (FileStream fs = new FileStream("MapInfo.bin", FileMode.Open, FileAccess.Read)){BinaryFormatter bf = new BinaryFormatter();listMapDal = bf.Deserialize(fs) as List<Map>;if (listMapDal == null){//MessageBox.Show("listMap==null");return null;}}}catch (Exception){//MessageBox.Show("读取文件失败");throw;}return listMapDal;}/// <summary>/// 存储ListMap/// </summary>/// <param name="listMap"></param>/// <returns></returns>public static bool SaveMapInfoToMapInfoFile(List<Map> listMap){bool mark = true;try{using (FileStream fs = new FileStream("MapInfo.bin", FileMode.OpenOrCreate, FileAccess.Write)){BinaryFormatter bf = new BinaryFormatter();bf.Serialize(fs, listMap);}}catch (Exception){mark = false;}return mark;}}}

地图层

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;namespace ModeLayer
{[Serializable]public class Map : IDisposable,ICloneable {/// <summary>/// 深拷贝;/// </summary>/// <returns></returns>public object Clone(){return new Map(Col, Row){_logicMap = DeepCopyLogicMap(),_col = Col,_row = _row,//_reallMap = _reallMap.Clone() as Bitmap,//_box = _box.Clone() as Bitmap,//_road = _road.Clone() as Bitmap,//_role = _role.Clone() as Bitmap,//_target = _target.Clone() as Bitmap,//_wall = _wall.Clone() as Bitmap};}/// <summary>/// 释放资源/// </summary>public void Dispose(){_box.Dispose();//_reallMap.Dispose();_road.Dispose();_role.Dispose();_target.Dispose();_wall.Dispose();}public char[,] DeepCopyLogicMap(){char[,] ch = new char[_row, _col];for (int i = 0; i < _row; i++){for (int j = 0; j < _col; j++){ch[i, j] = _logicMap[i, j];}}return ch;}char[,] _logicMap;//默认值;private int _col = 6;//行private int _row = 6;//列//private Bitmap _reallMap = null;//地图画布;private static Bitmap _box = null;//路障;private static Bitmap _road = null;//路;private static Bitmap _role = null;//角色;private static Bitmap _target = null;//目标;private static Bitmap _wall = null;//墙/// <summary>/// 设置这个位置的状态;/// </summary>/// <param name="x"></param>/// <param name="y"></param>/// <param name="ch"></param>public void SetMapState(int x, int y, char ch){_logicMap[x, y] = ch;}/// <summary>/// 使用默认值构建地图;大小为6*6/// </summary>public Map(){InitImg();}private void InitImg(){ResourceManager rsm = Properties.Resources.ResourceManager;_role = new Bitmap((rsm.GetObject("role") as Image), new Size(60, 60));_box = new Bitmap((rsm.GetObject("box") as Image), new Size(60, 60));_road = new Bitmap((rsm.GetObject("road") as Image), new Size(60, 60));_target = new Bitmap((rsm.GetObject("target") as Image), new Size(60, 60));_wall = new Bitmap((rsm.GetObject("Wall") as Image), new Size(60, 60));//_reallMap = new Bitmap(60 * _row, 60 * _col);}/// <summary>/// 自定义地图;/// </summary>/// <param name="col">列</param>/// <param name="row">行</param>public Map(int col, int row){_col = col;_row = row;_logicMap = new char[_row, _col];InitImg();}/// <summary>/// 获取逻辑地图/// </summary>public char[,] LogicMap{get{return _logicMap;}}/// <summary>///  获取逻辑地图的列数/// </summary>public int Col{get{return _col;}}/// <summary>/// 获取逻辑地图的行数;/// </summary>public int Row{get{return _row;}}/ <summary>/ 真是的地图/ </summary>//public Bitmap ReallMap//{//    get//    {//        return _reallMap;//    }//    set//    {//        _reallMap = value;//    }//}/// <summary>/// 障碍物/// </summary>public Bitmap Box{get{return _box;}set{_box = value;}}/// <summary>/// 路/// </summary>public Bitmap Road{get{return _road;}set{_road = value;}}/// <summary>/// 人物/// </summary>public Bitmap Role{get{return _role;}set{_role = value;}}/// <summary>/// 目标/// </summary>public Bitmap Tatget{get{return _target;}set{_target = value;}}/// <summary>/// 墙;/// </summary>public Bitmap Wall{get{return _wall;}set{_wall = value;}}}
}

部分代码来源于网络,侵删。

C#推箱子小游戏C#推箱子小游戏-其他文档类资源-CSDN下载

课程设计-推箱子C#(win form)相关推荐

  1. 数据结构课程设计-推箱子

    1. 题目描述 推箱子的游戏规则是扮演工人的玩家,以"推"的方式推动箱子.玩家可以在没有阻碍物(如墙壁等的阻碍物)的情况下,向上.下.左.右的方向移动,将箱子移动到指定位置,当箱子 ...

  2. 推箱子android课程设计,推箱子游戏课程设计精选.doc

    推箱子游戏课程设计精选 目 录 Ⅰ 摘要 Ⅱ 前言 Ⅲ 功能描述 Ⅳ 配置要求 Ⅴ 总体设计 一.功能模块设计 二.数据结构设计 三.函数功能描述 四.代码实现 Ⅵ 参考文献 Ⅰ 摘 要 推箱子游戏是 ...

  3. 原因好消息: 自己主动算法设计推箱子游戏(三)

    在本节中,我们谈论的闭合曲线充满,为什么这件事情 当一个场景,当我们递归,我们推标箱,假设没有推箱子.然后跑到哪里都白跑.最好是反复出现歧视坐标都是一样的 这些坐标被反转包含(同样的排序结果).工的位 ...

  4. python实现推箱子

    python课程作业-推箱子 现在整理经常会用到的课程作业( python第三弹,持续更新中-) 目录 python课程作业-推箱子 简介 运行结果 系统环境 其他依赖 运行说明 实现代码 结语 简介 ...

  5. 初学者一学就会的小程序开发——推箱子

    最经典的推箱子游戏,类似的游戏你一定早就玩过.要控制搬运工上下左右移动,来将箱子推到指定地点. 经典的推箱子是一个来自日本的古老游戏,目的是在训练你的逻辑思考能力.在一个狭小的仓库中,要求把木箱放到指 ...

  6. 大一C语言课程设计之推箱子小游戏

    大一C语言课程设计之推箱子小游戏 先看一下效果 因为技术原因,开发说明没有加进去 按任意键以后 )] 同时响起来 你笑起来真好看的bgm 胜利界面会弹出一个弹出框 私信我或者加我qq:65245534 ...

  7. c语言语音控制游戏文献,C语言课程设计-基于C语言推箱子游戏设计-毕业论文文献.doc...

    gd工程职业技术学院毕业论文 基于C语言的推箱子游戏设计 Design of the push box Based on Combined Language 作者姓名: 学科专业: 应用电子技术 学院 ...

  8. 推箱子 | Java课程设计

    忙了快20天了,终于把推箱子的游戏做完了.自己第一次做这种项目,收获还是比较多的.先把项目交给大家,和面还会 有几篇博客,是关于我在项目中遇到的问题以及解决办法,如果有想法的可以关注我. 文章目录 项 ...

  9. Java课程设计之推箱子

    推箱子游戏是一个比较古老的游戏,深受广大游戏爱好者的欢迎,它在带来乐趣的同时也能培养我们的反应力以及严谨的思维能力. 游戏规则是要求角色将地图中所有放置的箱子推到指定目标位置,只有合理安排移动次序和位 ...

最新文章

  1. jqgrid如何渲染表格数据_jqgrid,jquery_jqGrid pivot 增加分项小计,jqgrid,jquery,jquery插件,javascript,表格 - phpStudy...
  2. 蓝图跑酷游戏教学的项目文件
  3. Python-OpenCV 处理图像(一):基本操作
  4. mongodb查询优化
  5. Flash 与数学:圆的切线(2)
  6. 国产车崛起粉碎德日工业神话
  7. Assimp 裁剪编译 Android 库
  8. 三分钟,带你了解PLM
  9. Django的了解及应用途径
  10. 旷世巨作!20 多位架构师携手打造的“Java 面试核心宝典”限时开源
  11. Django中引入bootstrap的方法
  12. 电脑重启f12怎么处理_联想电脑开机按f12后,怎么设置默认启动项
  13. Python 编辑器哪个好用
  14. Vue.extend构造器
  15. 需求分析挑战之旅(疯狂的订餐系统)(3)——背景-需要-需求规格
  16. 阿里云双11活动撸福利攻略云服务器篇 必买爆款
  17. 2021年煤矿采煤机(掘进机)操作考试题及煤矿采煤机(掘进机)操作报名考试
  18. 机器人误触发动作监控原因分析
  19. 歌谣学前端之react笔记之学习日历样式的设置
  20. 移植Opus音频编解码库到FreeScale iMX6q(飞凌嵌入式的OKMX6Q-C开发板)平台

热门文章

  1. xctf攻防世界 CRYPTO高手进阶区 shanghai
  2. winserver搭建smtp_如何在服务器搭建本地smtp邮件服务
  3. css sheet2.0,详解CSS3.0(Cascading Style Sheet) 层叠级联样式表
  4. Excel VLOOKUP实用教程之 09 VLOOKUP 与多个条件一起使用?(教程含数据excel)
  5. 20170224找女朋友之路思考总结
  6. RT3062无线wifi处理器参数介绍
  7. 微服务(SpringCloud、Dubbo、Seata、Sentinel、SpringGateway)
  8. 安全电子邮件基本原理 P114
  9. 【一起说说简历和面试的那些事儿】
  10. html全屏播放器代码,Bilibili HTML5播放器网页全屏模式优化 脚本版