c# 中shuffle游戏

时间:2018-07-10 10:21:44
【文件属性】:
文件名称:c# 中shuffle游戏
文件大小:5KB
文件格式:TXT
更新时间:2018-07-10 10:21:44
shuffle 在c#中开发shuffle的代码。using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Shuffle { public partial class Form1 : Form { private int[] Matrix = new int[9]; private int nRow = 0; private int nCol = 0; public Form1() { InitializeComponent(); InitializeMatrix(); } public void InitializeMatrix() { for (int i = 0; i < 9; i++) { Matrix[i] = i; } Random rnd = new Random(DateTime.Now.Millisecond * DateTime.Now.Second); for (int i = 0; i < 100; i++) { int a1 = rnd.Next(9); int a2 = (a1 + 1)%9; Exchange(ref Matrix[a1], ref Matrix[a2]); } } private void Exchange(ref int A1, ref int A2) { A1 = A1 ^ A2; A2 = A1 ^ A2; A1 = A1 ^ A2; }

网友评论