飞行棋案例
一.基本方案
游戏规则:
-
两个人轮流掷骰子红人和绿人
-
投掷出2,4,6点出门,投掷出6点可以在出门后再次投掷行走
-
地图长度共100步
-
地图中除过普通地板之外,另设六种特殊功能地板
-
踩到香蕉皮,退6步
-
踩到时空,前进6步
-
踩到陷阱,暂停一回合
-
踩到星星,可以再投掷一次
-
踩到移魂大法,可以做出选择与对方互换位置
-
踩到手枪,可以击退对方3步
-
踩到大炮,可以直接将对方轰炸回家(需要重新出门)
-
-
如果踩到对方,则对方直接回到起点,
二.游戏策划
-
地图面积30*13
-
每个格子30像素
-
地面的代号=0,普通地板=1,香蕉皮=2,时空=3,陷阱=4,星星=5,大挪移=6,手枪=7
红人=8,绿人=9
起点=10,终点=11
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;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Panel map = new Panel();
//这个数组是所有的地板的一个数组,游戏逻辑全部取决于数字数组
int[] mapList = new int[390];
//这个数组是所有的图片,根据maplist决定每个元素的内容
PictureBox[] mapImg = new PictureBox[390];
const int size = 30;
//这个数组用来记录所有的路的索引位置
int[] road = new int[100];
private void Form1_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
this.BackColor = Color.FloralWhite;
this.Width = 1300;
this.Height = 700;
this.Left = Screen.PrimaryScreen.Bounds.Width / 2 - this.Width / 2;
this.Top = Screen.PrimaryScreen.Bounds.Height / 2 - this.Height / 2;
//获取维度
map.Width = 30 * size;
map.Height = 13 * size;
this.Controls.Add(map);
map.Location = new Point(50, 250);
map.BorderStyle = BorderStyle.FixedSingle;
//调用方法
InitialGame();
//红色玩家home生成
redplayHome.Size = new Size(100, 100);
redplayHome.BackgroundImage = Image.FromFile("../../img/select_circle.png");
redplayHome.Location = new Point(50, map.Top - 120);
redplayHome.BackgroundImageLayout = ImageLayout.Stretch;
this.Controls.Add(redplayHome);
//绿色玩家home生成
greenplayHome.Size = new Size(100, 100);
greenplayHome.BackgroundImage = Image.FromFile("../../img/select_circle.png");
greenplayHome.Location = new Point(170, map.Top - 120);
greenplayHome.BackgroundImageLayout = ImageLayout.Stretch;
this.Controls.Add(greenplayHome);
//红色玩家生成
PictureBox redPlayer = new PictureBox();
redPlayer.Size = new Size(80, 80);
redPlayer.Image = Image.FromFile("../../img/red.png");
redPlayer.Location = new Point(10, 10);
redPlayer.SizeMode = PictureBoxSizeMode.StretchImage;
redplayHome.Controls.Add(redPlayer);
redPlayer.BackColor = Color.Transparent;
//绿色玩家生成
PictureBox greenPlayer = new PictureBox();
greenPlayer.Size = new Size(80, 80);
greenPlayer.Image = Image.FromFile("../../img/green.png");
greenPlayer.Location = new Point(10, 10);
greenPlayer.SizeMode = PictureBoxSizeMode.StretchImage;
greenplayHome.Controls.Add(greenPlayer);
greenPlayer.BackColor = Color.Transparent;
//创建游戏步骤框
msg.Size = new Size(260, 600);
msg.Location = new Point(map.Right + 20, 50);
msg.ReadOnly = true;
this.Controls.Add(msg);
//生成骰子
dice.Size = new Size(100, 100);
dice.Image = Image.FromFile("../../img/roll.png");
dice.Location = new Point(msg.Left - 100, 50);
dice.SizeMode = PictureBoxSizeMode.StretchImage;
this.Controls.Add(dice);
//添加骰子鼠标点击事件
dice.MouseClick += Dice_MouseClick;
//设置游戏开始弹框
string startmsg = "请两个人先轮流掷骰子,点大的先行一步,红方先手";
//步骤框消息记录
ResultTell(startmsg);
}
//玩家home实例化
Panel redplayHome = new Panel();
Panel greenplayHome = new Panel();
//实例化一个 RichTextBox,记录游戏步骤
RichTextBox msg = new RichTextBox();
Random r = new Random();
//记录谁可以投掷
//索引为0代表红方,索引为1代表绿方
bool[] whoCan = new bool[2] { true, false };
//轮流投掷筛子
private void PlayDice()
{
//红方先投掷
if (whoCan[0])
{
startNum[0] = r.Next(1, 7);
ResultTell(String.Format("红方投掷出【{0}】点", startNum[