In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces how to use C# to achieve flying chess, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Ask the boss for advice on the shortcomings based on the Winform framework.
Using System;using System.Drawing;using System.Windows.Forms;namespace Flying Chess {public partial class Form1: Form {public Form1 () {InitializeComponent ();} / create a digital assembly game floor int [] mapList = new int [390]; / / create an array of pictures PictureBox [] mappic = new PictureBox [390]; / / create an array of int [] road = new int [100]; / / create a map Panel map = new Panel (); int size = 30 / / create dice PictureBox dice = new PictureBox (); / / Red Panel plan1 = new Panel () in the parking area of the initial position; / / Green Panel plan2 = new Panel () in the parking area of the initial position; private void Form1_Load (object sender, EventArgs e) {this.Size = new Size (250,100); this.FormBorderStyle = FormBorderStyle.FixedSingle; this.Location = new Point (250,100); this.BackColor = Color.Wheat; map.Size = new Size (30*size, 13*size) Map.BorderStyle = BorderStyle.FixedSingle; map.Location = new Point (40160); this.Controls.Add (map); / / method of displaying pictures Init (); plan1.Size = new Size (100,100); plan1.Location = new Point (map.Left, map.Top-120); plan1.BackgroundImage = Image.FromFile (".. /.. / img/circle.png"); plan1.BackgroundImageLayout = ImageLayout.Stretch; this.Controls.Add (plan1); plan2.Size = new Size (100,100) Plan2.Location = new Point (map.Left+120, map.Top-120); plan2.BackgroundImage = Image.FromFile (".. /.. / img/circle.png"); plan2.BackgroundImageLayout = ImageLayout.Stretch; this.Controls.Add (plan2); 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; plan1.Controls.Add (redPlayer) 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; plan2.Controls.Add (greenPlayer); / / create dialog tall.Size = new Size (200,500); tall.Location = new Point (map.Right + 20,50); tall.ReadOnly = true; this.Controls.Add (tall) / / player 1: name.Size = new Size (100,30); name.Location = new Point (45Magazine 10); this.Controls.Add (name); / / player 2: names.Size = new Size (100,30); names.Location = new Point (160Final10); this.Controls.Add (names); btn.Location = new Point (300jor10); btn.Text = "start the game"; btn.Size = new Size (100,30); btn.BackColor = Color.Pink; btn.Click + = Btn_Click This.Controls.Add (btn); / / Dice dice.Size = new Size (80,80); dice.Image = Image.FromFile (".. /.. / img/roll.png"); dice.Location = new Point (map.Right-160,map.Top-120); dice.SizeMode = PictureBoxSizeMode.StretchImage; this.Controls.Add (dice); dice.MouseClick + = Dice_MouseClick } private void Btn_Click (object sender, EventArgs e) {/ / create the initial pop-up frame Tall (string.Format ("Please roll the dice, {0} first hand, click big first", name.Text); playName [0] = name.Text; playName [1] = names.Text; tall.Focus ();} TextBox name = new TextBox (); TextBox names = new TextBox (); Button btn = new Button (); / / dialog box for creating key records RichTextBox tall = new RichTextBox () / / create a random Random r = new Random (); / / take turns to roll the dice 0 for the red side 1 for the green side bool [] playStart = new bool [2] {true, false}; / / record the current position of both parties int [] playPosition = new int [2] {- 1,-1}; int [] playStand = new int [2] {- 1,-1}; / / record the points of the dice int [] shaizi = new int [2] String [] playName = new string [2]; / / array storage points int [] num = new int [2]; / / 1. Take turns throwing sieves to decide who goes out first private void Dice_MouseClick (object sender, MouseEventArgs e) {PlayDice (); PlayGame ();} private void PlayDice () {/ / Red throws red to true after throwing becomes false Green throwing if (playStart [0]) {shaizi [0] = r.Next (1d7); Tall (String.Format ("{1} throw {0} points", shaizi [0], playName [0])); playStart [0] =! playStart [0] } else {playStart [0] =! playStart [0];} / / Green side throws false Green side becomes true after throwing. It's the red side's turn to throw if (playStart [1]) {shaizi [1] = r.Next (1,7); Tall (String.Format ("{1} throw {0} points", shaizi [1], playName [1]); playStart [1] =! playStart [1];} else {playStart [1] =! playStart [1] }} / / decide who is the first player in the game private void OutDoor () {/ / when the red side is true and the green side is false, the corresponding number of dice after one round is not 0 if (playStart [0] & &! playStart [1] & & (shaizi [0]! = 0 | | shaizi [1]! = 0)) {if (shaizi [0] = shaizi [1]) {Tall ("both sides have the same points, please throw it again") } else {/ / second round st = false; if (shaizi [0] > shaizi [1]) {Tall ("{0} points are large, first step, {0} throw", name.Text); playStart [0] = true; playStart [1] = false;} if (shaizi [0])
< shaizi[1]) { Tall(String.Format("{0}点数较大,先行一步,{0}投掷", names.Text)); playStart[0] = false; playStart[1] = true; } } } } bool st = true; //控制游戏谁先走 private void PlayGame() { //判断游戏刚开始时候比点数先行 if (st == true) { OutDoor(); //都为false的时候绿方投掷 if (!playStart[0]&&playStart[1]) { Tall(string.Format("请{0}投掷",names.Text)); }//都为true的时候红方投掷 else if(playStart[0]&&!playStart[1]) { Tall(string.Format("请{0}投掷!",name.Text)); } } else { if (playStart[0] && !playStart[1])//如果绿方大, 绿方为true { PlayReturn(1); }//红方 else if (!playStart[0] && playStart[1]) { PlayReturn(0); } } } /// /// 双方轮流游戏 /// /// 传入参数index0为红方 1为绿方 bool[] re = new bool[2] { false, false }; private void PlayReturn(int index) { //都没出门 if (playPosition[index] == -1) { switch (shaizi[index]) { case 2: case 4: Tall(String.Format("{0}可以起步", playName[index])); playPosition[index] = 0; playStand[index] = 0; //如果两个位置相等 if (playPosition[1] == playPosition[0]) { mappic[road[playPosition[index]]].Image = imageList1.Images[2]; } else { mappic[road[playPosition[index]]].Image = imageList1.Images[index]; } break; case 6: playStart[index] = true; playStart[1 - index] = false; Tall(String.Format("{0}可以起步", playName[index])); playPosition[index] = 0; playStand[index] = 0; if (playPosition[1] == playPosition[0]) { mappic[road[playPosition[index]]].Image = imageList1.Images[2]; } else { mappic[road[playPosition[index]]].Image = imageList1.Images[index]; } Tall(String.Format("请{0}投掷骰子", playName[index])); break; default: Tall(String.Format("很遗憾,{0}投掷出{1}点无法起步,轮到{2}投掷", playName[index], shaizi[index], playName[1 - index])); break; } if (playPosition[0] != -1) { plan1.Controls.Clear(); } if (playPosition[1] != -1) { plan2.Controls.Clear(); } } else { //改变位置之前记录好之前的位置 playStand[index] = playPosition[index]; playPosition[index] += shaizi[index]; if (playPosition[index] >Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 247
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.