资源简介
实现了21点小游戏的基本操作,适合初学者使用,谢谢支持
代码片段和文件信息
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;//是否继续要牌
public bool isPlayAgain;//是否再继续玩一轮
public int userCards = 0;//用户要的牌的张数
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
public string[] UCard = new string[10];//存储用户所得到的牌
private int computerPoints = 0;//电脑的牌面点数
public int ComputerPoints
{
get { return computerPoints; }
}
private int userPoints = 0;//用户的牌面点数
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];//定义一个新的空数组,按顺序存放随机产生的牌
Random ran = new Random();
public void Shuffle()//洗牌方法
{
for (i = 0; i < 52; i++ p--)//新数组是按顺序接收的
{
int a = ran.Next(p);//从52个数里随机产生一个数,作为CardList数组的下标
NewCardList[i] = CardList[a];//再把这个带有随机下标的数组值赋给新的数组
for (int j = a; j < p - 1; j++)//如果抽出一张牌后,则之后所有的牌向前移一位
{
CardList[j] = CardList[j + 1];//向前移一位
}
}
}
public void IntotalPoints()//统计用户的牌面点数
{
for (int i = 0; i < 2; i++) //统计电脑的牌面点数
{
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++)//统计玩家分数
{
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
评论
共有 条评论