6
Delphi 实现刘谦春晚魔术 - homejun
source link: https://www.cnblogs.com/homejun/p/18018009
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Delphi 实现刘谦春晚魔术
看了博友的C# 实现刘谦春晚魔术很好,改成了delphi版的。
1 program Project1; 2 3 {$APPTYPE CONSOLE} 4 {$R *.res} 5 6 uses 7 System.SysUtils, 8 System.Classes; 9 10 var 11 list, removeElement: TStringList; 12 i, NameCount, insertIndex, directCount, sexCount: Integer; 13 tmp, element, hiddenEle1, hiddenEle2: String; 14 15 procedure Fun1(NameCount: Integer); 16 begin 17 if NameCount < list.Count then 18 begin 19 for i := 0 to NameCount - 1 do 20 begin 21 element := list[0]; // 获取第0个元素 22 list.Delete(0); // 移除第0个元素 23 list.Add(element); // 将第0个元素添加到最后 24 end; 25 26 end; 27 end; 28 29 procedure Fun2(forCount: Integer); 30 begin 31 // 被删除掉的三张牌 32 removeElement := TStringList.Create; 33 for i := 0 to forCount - 1 do 34 begin 35 removeElement.Add(list[0]); 36 list.Delete(0); 37 end; 38 Writeln(Format('被删除掉的%D张牌:%s', [forCount, removeElement.CommaText])); 39 Writeln('删除之后:' + list.CommaText); 40 41 // 把拿到的三张牌插到中间 42 Randomize; 43 insertIndex := Random(list.Count - 1) + 1; // 生成一个介于第一个和倒数第二个位置之间的随机插入位置 44 Writeln('插入位置:' + insertIndex.ToString); 45 for i := removeElement.Count - 1 downto 0 do 46 begin 47 list.Insert(insertIndex, removeElement[i]); 48 end; 49 50 end; 51 52 procedure Fun3(); 53 begin 54 // 藏起来第一张牌 55 hiddenEle1 := list.Strings[0]; 56 list.Delete(0); 57 end; 58 59 procedure Fun4(Count: Integer); 60 begin 61 for i := 0 to Count - 1 do 62 begin 63 list.Delete(0); 64 end 65 end; 66 67 procedure Fun5(); 68 begin 69 for i := 0 to 6 do 70 begin 71 element := list[0]; 72 list.Delete(0); 73 list.Add(element); 74 end; 75 end; 76 77 function Fun6(sexCount: Integer): string; 78 var 79 forCount: Integer; 80 begin 81 forCount := 0; 82 if sexCount = 1 then 83 forCount := 5 // 男生要5次 84 else 85 forCount := 4; 86 for i := 0 to forCount - 1 do 87 begin 88 // 把第一张牌放到数组最后面 (好运留下来) 89 element := list[0]; 90 list.Delete(0); 91 list.Add(element); 92 93 // 烦恼丢出去 94 list.Delete(0); 95 end; 96 result := list[0]; 97 end; 98 99 begin 100 try 101 try 102 list := TStringList.Create; 103 list.CommaText := 'A,B,C,D,A,B,C,D'; 104 Writeln('初始牌组:' + list.CommaText); 105 Writeln('请输入你的名字有几个字:'); 106 ReadLn(tmp); 107 NameCount := tmp.ToInteger; 108 109 Fun1(NameCount); 110 Writeln('变化之后:' + list.CommaText); 111 112 Fun2(3); 113 Writeln('插入三张牌后:' + list.CommaText); 114 Fun3(); 115 Writeln('藏起来第一张牌后:' + list.CommaText); 116 117 Writeln('北方-1 南方-2 不南不北-3,请输入对应数字:'); 118 ReadLn(tmp); 119 directCount := tmp.ToInteger; 120 Fun2(directCount); 121 Writeln('南北方人后:' + list.CommaText); 122 123 Writeln('男-1 女-2,请输入对应数字:'); 124 ReadLn(tmp); 125 sexCount := tmp.ToInteger; 126 Fun4(sexCount); 127 Writeln('男女生后:' + list.CommaText); 128 129 Fun5(); 130 131 Writeln('见证奇迹后:' + list.CommaText); 132 133 Writeln('开始好运留下了 烦恼丢出去'); 134 hiddenEle2 := Fun6(sexCount); 135 Writeln(Format('牌1:%s 牌2:%s', [hiddenEle1, hiddenEle2])); 136 137 ReadLn; 138 except 139 on E: Exception do 140 Writeln(E.ClassName, ': ', E.Message); 141 end; 142 143 finally 144 removeElement.Free; 145 list.Free; 146 147 end; 148 149 end.
Recommend
-
69
LG 在两年前的 CES 上展出过可弯曲的 OLED 屏幕,但当时显然地只是个工程样品, 一点也看不出来成品会长什么样子,或者有什么样的应用。两年后的今天,虽然我们看到的依然只是个 65 吋 4K OLED 电视的原型机,但至少我们知道了 LG 对这个技术的打算为何。
-
54
为什么有些记者会乱用标准?因为按照标准的话,出不了大新闻啊……
-
41
这算近景魔术了吧?
-
26
赣春 魔术贴扎带 背对背式 长钩款 10mm*5米 5色可选 4.6元包邮(需用券),来自什么值得买甄选出的天猫精选优惠产品,汇聚数十万什么值得买网友对该网购产品的点评。
-
43
给大家表演一个魔术
-
38
街头近景魔术
-
53
这么沙雕的魔术表演,他是怎么做到不笑场的……
-
50
FISM国际魔术大赛总冠军,台湾魔术师简纶廷的表演
-
7
我居然看穿了刘谦春晚的魔术雾影鬼人(49级)楼主2022-02-07 07:59:33推荐...
-
2
今年春晚刘谦的魔术堪称惊艳全场,那么他这个魔术实现的原理是什么呢?今天,就让咱们使用 JS 是实现这个魔术。约瑟夫环问题简介约瑟夫环问题源自古罗马,由历史学家约瑟夫斯提出,而其数学模型则在19世纪被命名。问题设定如下:n个人围成一圈,从第...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK