最简单的C#小游戏编程

2024-12-04 17:05:26
推荐回答(4个)
回答1:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
class Player
{
public string Name;
Card[] cards = new Card[5];

public void InitFiveCards()//五张牌
{

Random md = new Random();
int m = md.Next(1, 14);
for (int i = 0; i < 5; i++)
{
Card card = new Card();
card.Point = md.Next(1, 14);
card.Color = md.Next(0, 4);
cards[i] = card;

}

}

public void display()
{
for (int i = 0; i < 5; i++)
{
Console.WriteLine(cards[i].CardDisplayString());

}

}

public void chosecard() //取牌
{
int n;
Random md = new Random();
int m = md.Next(1, 14);

n = Convert.ToInt32(Console.ReadLine());

Card cd = new Card();
switch (n)
{
case 0:
Table.tablecard = n;

Console.WriteLine("新取的牌");
break;

case 1:

n = m;
Console.WriteLine("上个玩家丢的牌");
break;

}

}
public void throwcard()//丢牌
{
Card[] cards = new Card[5];

Random md = new Random();
int m = md.Next(1, 14);
for (int i = 0; i < 5; i++)
{
Card card = new Card();
card.Point = md.Next(1, 14);
card.Color = md.Next(0, 4);
cards[i] = card;

switch (i)
{
case 0:
card = cards[1];
break;
case 1:
card = cards[2];
break;
case 2:
break;
case 3:
card = cards[3];
break;
case 4:
card = cards[4];
break;

}
}
Console.WriteLine("chose the card:{0}");

}
public void Changeplayer()
{
int m;

}

public bool isWin()
{

for (int i = 1; i < 5;i++ )
{
if (cards[i].Color != cards[0].Color)
{
return false;
}
}
return true;

}

}

class Table
{

public static int tablecard;

public void cunchu()
{

Console.WriteLine(tablecard);

}

}

class Card
{

public int Point;
public int Color;

public string CardDisplayString()
{
string sColor = "";

switch (Color)
{
case 0:
sColor = "红心";
break;
case 1:
sColor = "方块";
break;
case 2:
sColor = "黑桃";
break;
case 3:
sColor = "草花";
break;
}

return string.Format("花色:{0} Point:{1}", sColor, Point);

}

class Program
{
static void Main(string[] args)
{

//1.输入玩家数量
int py;
Console.WriteLine("请输入玩家的数量");
py = int.Parse(Console.ReadLine());

Player[] pys = new Player[py];

//2.输入玩家姓名
for (int m = 0; m < py; m++)
{
pys[m] = new Player();
Console.WriteLine("请输入第{0}玩家名字", m + 1);
pys[m].Name = Console.ReadLine();
pys[m].InitFiveCards();
}

//3.开始游戏
bool isExit = false;

while (!isExit)
{
for (int m = 0; m < py; m++)
{

pys[m].display();

pys[m].chosecard();
pys[m].throwcard();
if (pys[m].isWin())
{
Console.WriteLine("The player name :{0}" + "游戏结束");

isExit = true;
break;
}

}

}

Console.ReadLine();

}
}
}
}

回答2:

热规范多个风格

回答3:

网上一搜一大堆,楼主太懒了。

回答4:

给个邮箱,我给你发