Simple 21-point Solitaire game solitaire display changes

Source: Internet
Author: User
Tags shuffle

Last written essay, simple 21-point solitaire Game, when the size of the form changes, the card screen will appear not to display problems, because each card is the method of GDI +, cut from the picture, does not use the VS provided control, such as the PictureBox control, This requires yourself to repaint the picture in the form's Paint event, so that when the size of the form changes, the card picture is displayed normally, and the X, y parameter in the card parent class Pkfather in the code provides the actual coordinates of the card in the form, that is, when each card class is to be displayed in the form, have already provided the coordinates on the form, then the problem solved is simple, will need to display on the form of the several cards to create another collection, this collection as long as not empty, the paint event is called, so that the size of the form can be re-drawn cards. The code is as follows

 Public Partial classForm1:form//The program start section defines the cards that are used to store the display        PrivateList<rpoker> Pcard =NewList<rpoker>(); Private voidForm1_paint (Objectsender, PaintEventArgs e) {            if(Pcard.count >0)            {                foreach(varIteminchPcard) {Item.                Draw (E.graphics); }            }         }Private voidButton1_Click (Objectsender, EventArgs e)//Start the game{pcard.clear ();  This.            Refresh (); Button1. Enabled=false; Label1. Text=""; Label2. Text=""; Label1.            Refresh (); Label2.            Refresh (); Computernumber=0; Playernumber=0; Playercount=0; Computercount=0; //draw the player's first cardAllcard[topcard]. X = $; Allcard[topcard]. Y= $; Allcard[topcard]. Draw ( This.             CreateGraphics ()); Pcard.add (Allcard[topcard]);//to display a card to join a collection            if(Allcard[topcard]. Rank >rank.ten) {Playercount+=Ten; Playernumber+=1; }            Else{Playercount+= (int) Allcard[topcard].                Rank; Playernumber+=1; } Topcard++; if(Topcard >= Wu) {Shuffle (); MessageBox.Show ("a new deck of cards!! "); } label2. Text=playercount.tostring (); Label2.            Refresh (); Label3. Text=playernumber.tostring (); Label3.             Refresh (); //Draw computer First cardAllcard[topcard]. X = $; Allcard[topcard]. Y= +; Allcard[topcard]. Draw ( This.            CreateGraphics ()); Pcard.add (Allcard[topcard]);//to display a card to join a collection            if(Allcard[topcard]. Rank >rank.ten) {Computercount+=Ten; Computernumber+=1; }            Else{Computercount+= (int) Allcard[topcard].                Rank; Computernumber+=1; } Topcard++; if(Topcard >= Wu) {Shuffle (); //pcard.clear ();MessageBox.Show ("a new deck of cards!! "); } Label1. Text=computercount.tostring (); Label1.            Refresh (); Label4. Text=computernumber.tostring (); Label4.             Refresh (); //Draw player Second cardAllcard[topcard]. X =225; Allcard[topcard]. Y= $; Allcard[topcard]. Draw ( This.            CreateGraphics ()); Pcard.add (Allcard[topcard]);//to display a card to join a collection            if(Allcard[topcard]. Rank >rank.ten) {Playercount+=Ten; Playernumber+=1; }            Else{Playercount+= (int) Allcard[topcard].                Rank; Playernumber+=1; } Topcard++; if(Topcard >= Wu) {Shuffle (); MessageBox.Show ("a new deck of cards!! "); } label2. Text=playercount.tostring (); Label2.            Refresh (); Label3. Text=playernumber.tostring (); Label3.             Refresh (); //Draw computer Second cardAllcard[topcard]. X =225; Allcard[topcard]. Y= +; Allcard[topcard]. Draw ( This.            CreateGraphics ()); Pcard.add (Allcard[topcard]);//to display a card to join a collection            if(Allcard[topcard]. Rank >rank.ten) {Computercount+=Ten; Computernumber+=1; }            Else{Computercount+= (int) Allcard[topcard].                Rank; Computernumber+=1; } Topcard++; if(Topcard >= Wu)//{Shuffle (); MessageBox.Show ("a new deck of cards!! "); } Label1. Text=computercount.tostring (); Label1.            Refresh (); Label4. Text=computernumber.tostring (); Label4.            Refresh (); Button2. Enabled=true; Button3. Enabled=true; }

Other places of code, as long as the need to display the cards, are added to the Pcard collection, of course, the beginning of the code to start the game to add Pcard.clear (), each time you start the game to empty the next collection, or the form will not necessarily show the card is the round.

In fact, the same problem can have a variety of solutions, see on the web also useful timer control, to periodically refresh the method of the form redraw, use this method to define a switch item, or the timing refresh redraw, the form will continue to blink, the definition of the switch item is more cumbersome, but also a solution, If there is a better way, please advise us.

 

Simple 21-point Solitaire game solitaire display changes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.