Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write the source code of flying chess in C #

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces how to write the source code of flying chess in C#. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Rules of the game

If player A steps on player B, player B steps back 6 frames and steps on 1 lucky roulette, a changes positions, b bombers the other side 6 squares steps back on 2 mines, 6 squares steps back on 2 mines, 6 squares steps on 3 pauses, pauses one round into 4 time-space tunnels, 10 squares steps on squares, nothing 0 indicates normal roulette ◎ 2 indicates landmine ★ 3 pauses ▲ 4 indicates space tunnel.

On the analysis of the source code of flying chess, the next article will be issued.

Source code

Using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Flying Chess {class Program {/ / We use static fields to simulate the global variable static int [] Maps=new int [100]; / / declare an array of static fields to store the coordinates of player An and player B static int [] playerPos = new int [2]; / / store the names of two players static string [] playerNames = new string [2] / / two player tags static bool [] flags = new bool [2]; / / flags [0] player An and flags [1] player B default is false static void Main (string [] args) {GameShow (); / / load game header # region enter player name Console.WriteLine ("Please enter player A's name"); playerNames [0] = Console.ReadLine () While (playerNames [0] = "") {Console.WriteLine ("player A name cannot be empty, please re-enter"); playerNames [0] = Console.ReadLine ();} Console.WriteLine ("Please enter player B's name"); playerNames [1] = Console.ReadLine (); while (playerNames [1] = = "" | | playerNames [1] = = playerNames [0]) {if (playerNames [1] = "") {Console.WriteLine ("name cannot be empty, please re-enter") PlayerNames [1] = Console.ReadLine ();} else {Console.WriteLine ("player B name cannot be repeated, please re-enter"); playerNames [1] = Console.ReadLine ();}} # endregion / / after the player name is written, clear the screen Console.Clear (); / / clear the screen GameShow (); Console.WriteLine ("soldiers of {0} are represented by A, playerNames [0]); Console.WriteLine (" soldiers of {0} are represented by B ", playerNames [1]) Initailmap (); / / initialize the map DrowMap (); / / draw the map-Note: initialize the map before drawing the map / / while in the game when neither player A nor player B reaches the finish line (playerPos [0])

< 99 && playerPos[1] < 99) { if (flags[0] == false) { PlayGame(0); } else { flags[0] = false; } if (playerPos[0] >

= 99) {Console.WriteLine ("player {0} beat player {1}", playerNames [0], playerNames [1]); break;} if (flags [1] = = false) {PlayGame (1);} else {flags [1] = false;} if (playerPos [1] > = 99) {Console.WriteLine ("player {0} beat player {1}", playerNames [1], playerNames [0]); break;} Console.ReadKey () } / set the color of the game header and output / public static void GameShow () {Console.ForegroundColor = ConsoleColor.Blue; / / set the foreground color of the output Console.WriteLine ("* *"); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine ("* *") Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine ("* Flying Chess War *"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine ("* *"); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine ("* *"); Console.ForegroundColor = ConsoleColor.Green Console.WriteLine ("* *"); initialize the map / public static void Initailmap () {int [] lucklyturn = {6, 23, 40, 55, 69, 83}; / / for (int I = 0; I < lucklyturn.Length; I +) {int index = lucklyturn [I]; Maps [index] = 1 / / set the location values of lucky roulette to 1} int [] landMine = {5, 13, 17, 33, 38, 50, 64, 80, 94}; / / Mine for (int I = 0; I < landMine.Length; iwheel +) {int index = landMine [I]; Maps [index] = 2; / / set the location values of mines to 2} int [] pause = {9,27,60,93}; / / suspend for (int I = 0; I < pause.Length) Int index +) {int index = pause [I]; Maps [index] = 3; / / set the values of the paused position to 3} int [] timeTunnel = {20,25,45,63,72,88,90}; / / Space-time tunnel for (int I = 0; I)

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: 0

*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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report