C#实现winform版飞行棋

这篇文章主要为大家详细介绍了C#实现winform版飞行,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了C#实现winform版飞行棋的具体代码,供大家参考,具体内容如下

游戏界面

游戏规则:

1、两个人轮流掷骰子红人和绿人
2、投掷出2,4,6点出门,投掷出6点可以在出门后再次投掷行走
3、地图长度共100步
4、地图中除过普通地板之外,另设六种特殊功能地板

(1) 踩到香蕉皮,退6步
(2) 踩到时空,前进6步
(3) 踩到陷阱,暂停一回合
(4) 踩到星星,可以再投掷一次
(5) 踩到移魂大法,可以做出选择与对方互换位置
(6) 踩到手枪,可以击退对方3步
(7) 踩到大炮,可以直接将对方轰炸回家(需要重新出门)

5、如果踩到对方,则对方直接回到起点,

游戏策划

1.地图面积30*13
2.每个格子30像素
3.地面的代号=0,普通地板=1,香蕉皮=2,时空=3,陷阱=4,星星=5,大挪移=6,手枪=7
红人=8,绿人=9
起点=10,终点=11
两人在同一位置=12

程序代码

 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 飞行棋 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Panel map = new Panel(); // 创建游戏区对象 int[] mapList = new int[390];//存储地图数的数组 PictureBox[] mapImg = new PictureBox[390];// 存储图片的数组 const int size = 30;// 格子大小 Label jiLu = new Label(); RichTextBox msg = new RichTextBox(); //存储近况 Random r = new Random(); PictureBox dice = new PictureBox(); //创建骰子对象 Panel redplayHome = new Panel(); // 红方飞机 Panel greenplayHome = new Panel(); //绿方飞机 private void Form1_Load(object sender, EventArgs e) { // 设置不可移动 this.FormBorderStyle = FormBorderStyle.FixedSingle; // this.FormBorderStyle=FormBorderStyle.FixedToolWindow与Icon图标不可连用 this.BackColor =Color.Plum; this.Size = new Size(1200, 600); this.Location = new Point(Screen.PrimaryScreen.Bounds.Width / 2 - this.Width / 2, Screen.PrimaryScreen.WorkingArea.Height / 2 - this.Height / 2); // 地图对象 map.Width = 30 * size; map.Height = 13 * size; map.Location = new Point(10, 150); map.BorderStyle = BorderStyle.FixedSingle; this.Controls.Add(map); InitialGame(); //调用初始化地图图片方法 // 红方的家 redplayHome.Size = new Size(100, 100); redplayHome.BackgroundImage = Image.FromFile("../../img/select_circle.png-600"); redplayHome.Location = new Point(20, map.Top - 120); redplayHome.BackgroundImageLayout = ImageLayout.Stretch; this.Controls.Add(redplayHome); // 绿方的家 greenplayHome.Size = new Size(100, 100); greenplayHome.BackgroundImage = Image.FromFile("../../img/select_circle.png-600"); greenplayHome.Location = new Point(map.Left+map.Width-greenplayHome.Width, 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-600"); redPlayer.Location = new Point(10, 10); redPlayer.SizeMode = PictureBoxSizeMode.StretchImage; redplayHome.Controls.Add(redPlayer); //绿飞机 PictureBox greenPlayer = new PictureBox(); greenPlayer.Size = new Size(80, 80); greenPlayer.Image = Image.FromFile("../../img/green.png-600"); greenPlayer.Location = new Point(10, 10); greenPlayer.SizeMode = PictureBoxSizeMode.StretchImage; greenplayHome.Controls.Add(greenPlayer); // 记录游戏近况框 msg.Size = new Size(260, 390); msg.ReadOnly = true;//设置只读 msg.Location = new Point(map.Right,map.Top); msg.Font = new Font("微软雅黑", 12); msg.BackColor = Color.LightPink; this.Controls.Add(msg); // 游戏近况字 jiLu.Size = new Size(100, 30); jiLu.Text = "游戏近况"; jiLu.Font = new Font("楷体", 16); jiLu.ForeColor = Color.Maroon; jiLu.BackColor = Color.Aquamarine; jiLu.Location = new Point(msg.Left+msg.Width/2-jiLu.Width/2, map.Top-jiLu.Height); this.Controls.Add(jiLu); //骰子 dice.Size = new Size(100, 100); dice.Image = Image.FromFile("../../img/roll.png-600"); dice.Location = new Point(map.Left+map.Width/2-dice.Width/2,map.Top-dice.Height); dice.SizeMode = PictureBoxSizeMode.StretchImage; this.Controls.Add(dice); dice.MouseClick += Dice_MouseClick; string startmsg = "请两个人先轮流掷骰子,点大的先一步,红方先手"; ResultTell(startmsg); //调用 } // 骰子点击事件 private void Dice_MouseClick(object sender, MouseEventArgs e) { PlayDice(); PlayGame(); } // 记录谁可以投掷   索引0代表红方,1代表绿方 bool[] whoCan = new bool[2] { true, false }; int[] startNum = new int[2]; // 记录双方投掷的点数 string[] playeName = new string[2] { "红方", "绿方" }; int[] playPostion = new int[2] { -1, -1 };// 记录两个人现在位置 没有出门默认-1 int[] playStan = new int[2]{ -1,-1}; // 记录上飞机上一个位置的坐标索引默认为-1 private void PlayDice() // 轮流投掷的方法  此方法为投掷为一轮 { //红方先投   默认红方先投掷 if (whoCan[0]) //默认为true { startNum[0] = r.Next(1, 7); ResultTell(string.Format("红方投掷出【{0}】点", startNum[0])); whoCan[0] = !whoCan[0]; // false赋给红方 } else { whoCan[0] = !whoCan[0]; //将false变为true } // 绿方投掷 if (whoCan[1]) // 默认为false { startNum[1] = r.Next(1, 7); ResultTell(string.Format("绿方投掷出【{0}】点", startNum[1])); whoCan[1] = !whoCan[1]; // 将true变为false } else { whoCan[1] = !whoCan[1]; //将true变为false } } // 控制游戏刚开始谁先行 bool start = true; //

以上就是C#实现winform版飞行棋的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 其他教程