GrandSlam-纸牌游戏(类似于Windows Hearts的游戏)(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/grandslam-a-card-playing-game-a-game-like-windows-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 4 分钟阅读 - 1887 个词 阅读量 0GrandSlam-纸牌游戏(类似于Windows Hearts的游戏)(译文)
原文地址:https://www.codeproject.com/Articles/18679/GrandSlam-A-Card-Playing-Game-A-Game-like-Windows
原文作者:Mehran Farshadmehr
译文由本站 robot-v1.0 翻译
前言
An article about using GDI+ for Windows Forms games development and if-based intelligent game.
有关使用GDI +进行Windows Forms游戏开发和基于if的智能游戏的文章.
介绍(Introduction)
本文是关于使用GDI +功能来构建基于if的智能游戏.我试图使其GUI类似于Windows Hearts游戏,并且使其基于if的逻辑尽可能智能.我试图通过尽量减少形状涂料来制作没有闪烁的GUI,而且还尝试以自然的方式模拟游戏中的所有内容.我的意思是洗牌,寻找最好的牌,预先装扮((This article is about using GDI+ capabilities to build an if-based intelligent game. I tried to make its GUI like Windows Hearts game and its logic as intelligent as possible with if-based logic. I tried to make GUI without flicker by minimizing form paints and I also tried to simulate everything in the game in a natural way. I mean shuffling cards, finding the best card to play, prefiguring (a special step in) GrandSlam
), 等等.该项目的另一个有用功能是它包含两个项目.首先,一个名为的库项目(DLL)(), and so on. Another useful feature of the project is that it comprises two projects. First, a library project (DLL) named) Card
可以在您单独开发的任何纸牌游戏中使用.二,将Windows Forms项目命名为(that can be used in any card playing game that you develop separately. Second, the Windows Forms project named) GrandSlam
处理应用程序GUI和基于if的智能逻辑(好主意之一可以将此区域分为两个单独的类).(that handles application GUI and if-based intelligent logic (one of the good ideas can be separating this area into two separate classes).)
背景(Background)
GrandSlam
(波斯语中的Shelem)是((Shelem in Farsi language) is a) 打牌(Card Playing) 在上面的屏幕快照中,您看到了像Windows Hearts这样的两个团队中有四个玩家的游戏.请参阅(game with four players in two teams like Windows Hearts as you see in the screen shot above. Please refer to) 维基百科(Wikipedia) 有关游戏的详细说明.(for a detailed description of the game.)
使用代码(Using the Code)
如果您要开发新的纸牌游戏,只需添加以下内容的引用即可:(If you want to develop a new card playing game, simply add a reference to)**Card.dll(Card.dll)**并使用它(and use its) Mehran.Card
类;此类的松散耦合足以执行您想要的操作.使用以下构造函数(完整参数构造函数)创建一个新实例:(class; this class is loosely coupled enough to do what you want. You create a new instance with the following constructor (the full argument constructor):)
public Card(CardValues value, CardType type, Point topLeft)
如您所见,此类同时处理逻辑和GUI.它还提供了一种在提供的纸牌中抽奖的方法(As you see, this class handles both logic and GUI. It also has a method for drawing cards in the provided) Graphics
目的:(object:)
public void Draw(Graphics grp)
卡组件包含用于绘制每张卡的必需资源(包括卡图像).确切地说,该程序集不包含每张卡的52张图像,而是仅包含所需的零件(如4张卡类型符号).(The card assembly contains the required resource (Include card images) for drawing each card. To be precise, the assembly does not contain 52 images for each card, but it includes only the required part like 4 card type symbol.)
但(But) GrandSlam
该类的基于if的智能逻辑不在本文的讨论范围之内,因此我将在另一篇文章中进行描述(请耐心等待).关于其GUI,我使用了单独的(class’s if-based intelligent logic is out of scope of this article, so I will describe it in another one (please be patient). About its GUI, I used a separate) UserControl
命名(named) PrefigureControl
处理预装步骤.它不包含任何复杂的内容.构造函数将其添加到窗体的控件列表中,并且在完成工作后将自身隐藏.(to handle the prefiguring step. It didn’t contain any complex stuff. The constructor adds it to the controls list of form, and it will hide itself after doing its job.)
#region prefigure Control
prefigureControl = new PrefigureControl();
prefigureControl.Location = new Point(200,200);
prefigureControl.OK += new EventHandler(Prefigure_OK);
Controls.Add(prefigureControl);
....
它还扮演着其他角色,它捕获了玩家的名字.在里面(It also plays an additional role, it captures the player’s names. In the) Prefigure_OK
方法,名称将显示在位置和游戏开始处,从这里开始,应用程序应尊重用户的互动(method, the name will be displayed in the location and game start, from here, the application should respect the user interaction on) OnMouseDown
事件的形式.(event of form.)
if(userCardsRect.Contains(e.X,e.Y) && deckNum != -1 && !startButtonVisible)
{
...
这里(Here) Play(int ind)
调用方法来更改数据和视图(MVC中的模型),您会看到完成每个GUI操作都无需调用(method is called to change data and view (model in MVC), You see that every GUI operation is done without calling the) Invalidate()
方法,因为如果频繁使用它会闪烁.(method because it flickers if it is used frequently.)
另一个技巧是,当四个玩家玩纸牌时,我将线程休眠2秒钟,然后从表单中收集纸牌以模拟现实:(Another trick is that when four players play their cards, I sleep the thread 2 seconds and then collect cards from the form to simulate reality:)
System.Threading.Thread.Sleep(2000);
CollectCenter();
请注意包含显示配置常量的"查看常量"区域.(Be careful about the “View constants” region that contains display configuration constant.) 如果您能对本文发表意见和反馈,我们将不胜感激.(I would appreciate if you could give your opinions and feedback for this article.)
历史(History)
- 6(6)日(th)2007年5月:初始职位(May, 2007: Initial post)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# C#2.0 WinXP Windows .NET .NET2.0 VS2005 Visual-Studio VS.NET2003 Dev 新闻 翻译