c#推箱子小游戏代码_C#做的一个推箱子的小游戏

这是一个使用C#编写的推箱子游戏,通过数组来标识不同的游戏元素,简化人物移动的判断。游戏根据不同的关卡等级显示不同布局,并且包含了人物移动、碰撞检测等关键功能。
摘要由CSDN通过智能技术生成

【实例简介】

本推箱子游戏使用数组实现,用不同的数字标识不同的物体,从而简化了人物移动的判断过程

【实例截图】

【核心代码】

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Media;

namespace 推箱子2._0

{

public partial class Form1 : Form

{

public const int len=10;//数组长度

int [,] num = new int[len,len];//初始化数组,数组元素全为0

public const int height = 50, width = 50;//墙的长宽

int row,col;//标记人物位置

int direction = 2;//方向1,2,3,4代表上下左右

//SoundPlayer player = new SoundPlayer();

int leval = 1;//关卡等级标记

int map = 1;//地图

public Form1()

{

InitializeComponent();

initNum();

this.KeyPreview = true;

this.BackgroundImage = new Bitmap(@"map1\floor1.png");//初始化窗口背景

}

/* 初始化界面 */

private void initGameView()

{

Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);//创建一个位图,作为PictureBox的Image

label2.Text = "第 " leval " 关";

Bitmap bitmp;//用于承载物体的图片

Graphics g = Graphics.FromImage(bmp);

if (map == 2)//地图2

{

for (int i = 0; i < len; i )

{

for (int j = 0; j < len; j )

{

bitmp = new Bitmap(@"map2\block.gif");

if (num[i, j] == 0)

bitmp = new Bitmap(@"map2\block.gif");

if (num[i, j] == 1)

bitmp = new Bitmap(@"map2\wall.png");

if (num[i, j] == 2)

bitmp = new Bitmap(@"map2\box.png");

if (num[i, j] == 3)

bitmp = new Bitmap(@"map2\ball.png");

if (num[i, j] == 4)

{

switch (direction)

{

case 1:

bitmp = new Bitmap(@"map2\person_up.png"); break;

case 2:

// bitmp = new Bitmap(@"Images\pic04down.png"); break;

bitmp = new Bitmap(@"map2\person_down.png"); break;

case 3:

bitmp = new Bitmap(@"map2\person_left.png"); break;

case 4:

bitmp = new Bitmap(@"map2\person_right.png"); break;

}

row = i;

col = j;

}

if (num[i, j] == 5)

bitmp = new Bitmap(@"map2\person5.jpg");

if (num[i, j] == 6)

bitmp = new Bitmap(@"map2\box.png");

g.DrawImage(bitmp, i * width, j * height, width, height);

}

}

pictureBox1.Image = bmp;

}

if (map == 1)//地图1

{

for (int i = 0; i < len; i )

{

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值