資源簡介
實現(xiàn)了21點小游戲的基本操作,適合初學(xué)者使用,謝謝支持

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
namespace?Point21
{
????class?Game
????{
????????private?int?p?=?52;//常量p為52,
????????private?int?i;
????????public?bool?isRiffleAgain;//是否繼續(xù)要牌
????????public?bool?isPlayAgain;//是否再繼續(xù)玩一輪
????????public?int?userCards?=?0;//用戶要的牌的張數(shù)
????????private?string?name;
????????public?string?Name
????????{
????????????get?{?return?name;?}
????????????set?{?name?=?value;?}
????????}
????????public?string[]?UCard?=?new?string[10];//存儲用戶所得到的牌
????????private?int?computerPoints?=?0;//電腦的牌面點數(shù)
????????public?int?ComputerPoints
????????{
????????????get?{?return?computerPoints;?}
????????}
????????private?int?userPoints?=?0;//用戶的牌面點數(shù)
????????public?int?UserPoints
????????{
????????????get?{?return?userPoints;?}
????????}
????????public?Game()
????????{
????????????//this.p?=?52;
????????????//this.i?=?0;
????????????//this.userCards?=?0;
????????????//this.isRiffleAgain?=?true;
????????????//this.isPlayAgain?=?true;
????????}
????????public?string[]?CardList?=?new?string[52]?
??????????{?“A“?“A“?“A“?“A“?“2“?“2“?“2“?“2“
????????????“3“?“3“?“3“?“3“?“4“?“4“?“4“?“4“
????????????“5“?“5“?“5“?“5“?“6“?“6“?“6“?“6“?
????????????“7“?“7“?“7“?“7“?“8“?“8“?“8“?“8“?
????????????“9“?“9“?“9“?“9“?“10“?“10“?“10“?“10“
????????????“J“?“J“?“J“?“J“?“Q“?“Q“?“Q“?“Q“?
????????????“K“?“K“?“K“?“K“?};
????????public?string[]?NewCardList?=?new?string[52];//定義一個新的空數(shù)組,按順序存放隨機產(chǎn)生的牌
????????Random?ran?=?new?Random();
????????public?void?Shuffle()//洗牌方法
????????{
????????????for?(i?=?0;?i?52;?i++?p--)//新數(shù)組是按順序接收的
????????????{
????????????????int?a?=?ran.Next(p);//從52個數(shù)里隨機產(chǎn)生一個數(shù),作為CardList數(shù)組的下標(biāo)
????????????????NewCardList[i]?=?CardList[a];//再把這個帶有隨機下標(biāo)的數(shù)組值賦給新的數(shù)組
????????????????for?(int?j?=?a;?j?????????????????{
????????????????????CardList[j]?=?CardList[j?+?1];//向前移一位
????????????????}
????????????}
????????}
????????public?void??IntotalPoints()//統(tǒng)計用戶的牌面點數(shù)
????????{
????????????for?(int?i?=?0;?i?2;?i++)??//統(tǒng)計電腦的牌面點數(shù)
????????????{
????????????????if?(NewCardList[i]?==?“A“)
????????????????{
????????????????????computerPoints?+=?1;
????????????????}
????????????????else?if?(NewCardList[i]?==?“J“?||?NewCardList[i]?==?“Q“?||?NewCardList[i]?==?“K“)
????????????????{
????????????????????computerPoints?+=?10;
????????????????}
????????????????else
????????????????{
????????????????????computerPoints?+=?int.Parse(NewCardList[i]);
????????????????}
????????????}
????????????for?(int?i?=?2;?i?4?+?userCards;?i++)//統(tǒng)計玩家分?jǐn)?shù)
????????????{
????????????????if?(NewCardList[i]?==?“A“)
????????????????{
????????????????????userPoints?+=?1;
????????????????}
????????????????else?if?(NewCardList[i]?==?“J“?||?NewCardList[i]?==?“Q“?||?NewCardList[i]?==?“K“)
????????????????{
????????????????????userPoints?+=?10;
????????????????}
????????????????else
?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????911??2009-12-21?20:08??21Point\21Point.sln
????..A..H.?????18432??2010-01-25?21:21??21Point\21Point.suo
?????文件???????2632??2009-12-22?22:55??21Point\21Point\21Point.csproj
?????文件????????648??2009-12-21?20:43??21Point\21Point\ClassDiagram1.cd
?????文件???????5321??2009-12-23?20:15??21Point\21Point\Game.cs
?????文件???????1427??2009-12-23?11:13??21Point\21Point\OutPut.cs
?????文件???????2810??2009-12-23?20:15??21Point\21Point\Program.cs
?????文件???????8192??2009-12-23?20:16??21Point\21Point\bin\Debug\21Point.exe
?????文件??????19968??2009-12-23?20:16??21Point\21Point\bin\Debug\21Point.pdb
?????文件??????14328??2010-01-25?21:20??21Point\21Point\bin\Debug\21Point.vshost.exe
?????文件????????490??2009-06-11?05:14??21Point\21Point\bin\Debug\21Point.vshost.exe.manifest
?????文件???????1615??2010-01-25?21:20??21Point\21Point\obj\Debug\21Point.csproj.FileListAbsolute.txt
?????文件???????8192??2009-12-23?20:16??21Point\21Point\obj\Debug\21Point.exe
?????文件??????19968??2009-12-23?20:16??21Point\21Point\obj\Debug\21Point.pdb
?????文件???????1346??2009-12-21?20:08??21Point\21Point\Properties\AssemblyInfo.cs
?????目錄??????????0??2009-12-21?20:09??21Point\21Point\obj\Debug\Refactor
?????目錄??????????0??2009-12-21?20:09??21Point\21Point\obj\Debug\TempPE
?????目錄??????????0??2009-12-23?20:16??21Point\21Point\bin\Debug
?????目錄??????????0??2009-12-23?20:16??21Point\21Point\obj\Debug
?????目錄??????????0??2009-12-22?00:23??21Point\21Point\bin
?????目錄??????????0??2009-12-22?00:23??21Point\21Point\obj
?????目錄??????????0??2009-12-22?00:23??21Point\21Point\Properties
?????目錄??????????0??2009-12-23?20:15??21Point\21Point
?????目錄??????????0??2009-12-22?00:23??21Point
-----------?---------??----------?-----??----
???????????????106280????????????????????24
評論
共有 條評論