The Poker Hand class

In video poker, cards are always assembled into a hand consisting of 5 cards. The machine starts by dealing 5 cards at random. The user can discard none, some, or all of these cards in an attempt to improve the hand's score. Therefore, a hand is an obvious choice for an application class. The Hand class represents a poker hand consisting of 5 cards. Figure 3.3 depicts a Hand object for a royal flush in spades. Figure 3.3 Example Hand object representing a royal flush in spades Figure 3.3...

Coding a SOAP client

The WSDL standard for describing Web services means that we can query a service description and discover information about it. For example, listing 6.3 presents a simple program which queries a service at a given URL and displays the service name, description, and ports. Listing 6.3 Querying a service description file wsdldesc.cs compile csc wsdldesc.cs using System.Web.Services.Description public static void Main(string args) url ServiceDescription desc ServiceDescription.Read( new...

Creating a Visual Studio NET project

Launch Visual Studio .NET and select File New Project from the main menu. You should be presented with a dialog box which lists the available project templates. Select Visual C Projects in the left pane, and select Windows Application in the right. Call the project VsWinPok. See figure 7.9. Click OK to create the project. You should see a screen similar to that shown in figure 7.10. Figure 7.9 Creating a Visual Studio .NET project Figure 7.9 Creating a Visual Studio .NET project Figure 7.10 The...

Using XML serialization

Before we leave the data layer, let's take the opportunity to use the functionality of the Poker.Bank class to create a reporting utility class, called XmlRep. We design it so that it generates the report in XML format. This gives us the flexibility to convert the report to HTML for display in a Web browser, or to send the XML to other applications for further processing. We want the XML to look like the following < TakenIn> 3 03< TakenIn> < PaidOut> 161< PaidOut> < Profit>...

Playing video poker

Video poker took the casino industry by storm in the early 1980s. In Las Vegas casinos, and elsewhere, it now accounts for a greater share of income than traditional slot machines. The game is simple. You play against a machine which acts as dealer and you insert money to receive credits. Then you make a bet and hit the Deal button. The machine displays five cards from the deck. The idea is to make the best possible poker hand out of these five cards by holding onto the best cards and drawing...

Working with Web Forms

ASP.NET introduces some new terms to the ASP developer's vocabulary Web Forms and server controls. A Web Form is a form with a runat server attribute that causes it to be processed on the server. A server control is a control which also contains a runat server attribute. It too is processed on the server and generates HTML JavaScript to be rendered in the browser. To the developer, server controls appear similar to the Windows Forms controls we saw in the previous chapter. Indeed, using Visual...

Boxing and unboxing in IL

Using ildasm.exe, we can see what boxing and unboxing look like underneath the covers. To find out, create the short C file, box.cs, shown in listing 2.10. Listing 2.10 Boxing and unboxing in C int i 12 3 object o i int j (int)o When we compile and disassemble this file, we get the IL shown in listing 2.11. Listing 2.11 Boxing and unboxing in IL Listing 2.11 Boxing and unboxing in IL The first thing we notice is that the box and unbox operations are IL primitives. Boxing and unboxing are...

Creating check boxes

We've got five check boxes laid out left to right across the form. The player checks a box to indicate that the card above should be held when cards are drawn. Listing 7.12 sets up these check boxes. Listing 7.12 The initHoldCheckBoxes method private void initHoldCheckBoxes() init hold CheckBoxes hold1 new CheckBox() hold1.Location new Point(12, 208) hold2 new CheckBox() hold2.Location new Point(100, 208) hold3 new CheckBox() hold3.Location new Point(188, 208) hold4 new CheckBox()...

Validating user input

The Web Forms infrastructure provides a selection of validation controls that you can use to validate user input, and display error messages to the user. Common validation scenarios are supported including requiring that a field contains data, ensuring that an entry is within a specified range, matching an entry against a pattern, and so forth. You can attach one or more validation controls to an input control. The built-in validation controls include an entry in a field * CompareValidator...

Creating the Poker Bank class

The Poker.Bank class is the heart of the application's data layer. It provides the interface between the various poker applications and the database. The full source code for the Bank class is presented in listing 4.9. In the meantime, we'll go through the code in outline here. First, the constructor TargetMargin GetParm(TargetMargin, 25) refresh() We don't want the application talking directly to the Bank class. When the application needs data, it should ask the Poker.Machine class, which asks...

The Data Reader

The DataReader provides a read-only, forward-only stream of results from a database query or stored procedure. You should use a DataReader if it is desirable, and possible, to keep the connection to the database open while data is being processed. Listing 4.6 presents an example which displays the names of the authors in the Pubs database. file pubsreader.cs compile csc pubsreader.cs public class PubsReader public static void Main() SqlConnection con new SqlConnection( string sql SELECT * FROM...

Creating Web Forms using Visual Studio NET

So far, we've done things the hard way and hand-coded all our ASPNET examples. While this is the best way to learn, you'll eventually want to take advantage of some of the powerful features of Visual Studio .NET to ease the burden and reduce the tedium. So let's see what Visual Studio .NET can do for us. We'll create a base 64 encoding form similar to the remote service we developed in chapter 5. 8.9.1 Creating a Web application using Visual Studio .NET Launch Visual Studio .NET, select File...

Enabling Web service discovery

The process of locating Web services and retrieving their WSDL contracts is known as Web service discovery. Discovery can be facilitated by storing a so-called DISCO file with the service, or at an appropriate URL such as in a UDDI registry. The DISCO file is a regular XML document which provides links to the WSDL contract and associated documentation. The XML Web services infrastructure will automatically generate a bare-bones DISCO file for your service. Point your browser to to generate the...

The Data Sets Get Xml and Get XmlSchema methods

We can display both the XML data and schema for the ds DataSet created in the pubscount program, as follows display DataSet as XML display DataSet schema as XML Listing 4.2 shows what the XML schema looks like. lt xsd schema id PubsDataSet targetNamespace xmlns xmlns xsd http www.w3.org 2 0 01 XMLSchema lt xsd element name PubsDataSet lt xsd choice maxOccurs unbounded gt lt xsd element name a_count gt lt xsd complexType gt lt xsd sequence gt lt xsd element name cnt type xsd int minOccurs 0 gt...

Understanding types and assemblies

2.2 Value vs. reference types 18 2.4 Understanding finalization 23 2.6 Private vs. shared assemblies 29 2.9 Types, assemblies, and reflection 41 2.10 Building a simple compiler 44 Creating a .NET application involves coding types, and packaging them into assemblies. .NET types are similar to data types in non-object-oriented languages except that they contain both data, in the form of fields, and behavior in the form of methods. .NET types are also language-neutral. An assembly containing types...

Installing the poker Windows service

We compile svcpokservice.cs and install it as a Windows service using the installutil.exe utility, as shown in figure 5.20. C DotNet pokerNSucPok gt csc r poker.dll sucpokseruice.cs Microsoft lt R gt Uisual Cft Compiler Uersion 7.00.9254 CLR uersion ul.0.2914 Copyright lt C gt Microsoft Corp 2000-2001. All rights reserued. LogToConsole false sucpokseruice.exe Microsoft lt R gt .NET Framework Installation utility Copyright lt C gt Microsoft Corp 2001. All rights reserued. Figure 5.20 Installing...

Console poker using COM and VBScript

Listing 3.5 presents a VBScript client which plays a COM-based version of our simple poker game. ' description VBScript poker game ' execute cscript compok.vbs wscript.stdout.writeLine A simple poker game wscript.stdout.writeLine Hit Ctrl-c at any time to abort wscript.stdout.writeLine set machine do while true ' play forever set dealHand machine.Deal wscript.stdout.writeLine dealhand.Text wscript.stdout.write Enter card numbers 1 to 5 to hold holdCards wscript.stdin.readLine set drawHand...

Creating the WSPok client

As usual, run the wsdl.exe utility to generate the client proxy wsdl namespace Poker This will generate the wspokservice.cs file containing definitions for both the Poker.WSPokService and Poker.GameResult classes. All that remains is to code the simple client shown in listing 6.18. compile csc out WSPok.exe WSPokService.cs WSPok.cs namespace Poker using System public static void Main new WSPok start game Console.WriteLine A WebService-based poker game Console.WriteLine Hit Ctrl-c at any time to...

Visual Basic NET Hello program

For comparison, listing 1.2 shows the same program coded in Visual Basic .NET. ' file hello.vb ' compile vbc hello.vb Console.WriteLine Hello from VB.NET end sub You can see that the Visual Basic .NET version of the program is very similar. Specifically, the Visual Basic .NET program uses the same Console class from the System namespace. The Framework class library is part of the .NET platform and is not the preserve of a particular programming language. In general, there is less difference...

Compiling the C Hello program

To compile and test this example, you'll need a copy of the .NET SDK, or Visual Studio .NET. At the time of writing, the SDK could be downloaded from the Microsoft Developer Network site, http www.msdn.com. To compile and run this program, open a command window, and use the C command-line compiler, as shown in figure 1.2. Microsoft lt R gt Uisual CK Compiler Uersion 7.00.9254 CLP version ul.0.2914 Copyright C gt Microsoft Corp 2000-2001. All rights reserved. C Do t Ne t c ha_l gt he 1 lo Hello...

Example logging into a Web service

You could use the stateful approach to provide application-level login logout for a service. Listing 6.10 presents a StringCaseService service which requires the client to login in order to call the ToUpper and ToLower Web methods. In contrast, the GetLength method can be executed without logging in. lt WebService Language C Class StringCaseService gt file stringcaseservice.asmx description A web service to change string case. Requires user to login first. using System.Web.Services using...