GitHub download down C # console mini-game [including source code]

Source: Internet
Author: User

I have heard that GitHub is the world's largest source repository, but I do not understand, today to study the next, registered an account, and then search the above C # game, and then found that there are many games.

Randomly choose one, feel relatively simple, so downloaded down. This solution consists of 5 projects, each of which is a small console game.

I opened it up and there were 2 project errors, but cars and ping-pong could run.

Look at the code, feel good, there are many places worth learning.

This codebase is provided by an American, and instantly feels like it has become foreign flavor!

It's simple enough to have only one file per project.

Put out the ping-pong code and see

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading;usingSystem.Threading.Tasks;namespacepingpong{classProgram {Static intFirstplayerpadsize =Ten; Static intSecondplayerpadsize =4; Static intBallpositionx =0; Static intBallpositiony =0; Static BOOLBalldirectionup =true;//determines if the ball direction are up        Static BOOLBalldirectionright =false; Static intFirstplayerposition =0; Static intSecondplayerposition =0; Static intFirstplayerresult =0; Static intSecondplayerresult =0; StaticRandom Randomgenerator =NewRandom (); Static voidRemovescrollbars () {Console.foregroundcolor=Consolecolor.yellow; Console.bufferheight=Console.windowheight; Console.bufferwidth=Console.windowwidth; }        Static voidDrawfirstplayer () { for(inty = firstplayerposition; Y < firstplayerposition + firstplayerpadsize; y++) {printatposition (0Y'|'); Printatposition (1Y'|'); }        }        Static voidPrintatposition (intXintYCharsymbol)            {console.setcursorposition (x, y);        Console.Write (symbol); }        Static voidDrawsecondplayer () { for(inty = secondplayerposition; Y < secondplayerposition + secondplayerpadsize; y++) {printatposition (Console.windowwidth-1Y'|'); Printatposition (Console.windowwidth-2Y'|'); }        }        Static voidsetinitialpositions () {firstplayerposition= Console.windowheight/2-Firstplayerpadsize/2; Secondplayerposition= Console.windowheight/2-Secondplayerpadsize/2;        Setballatthemiddleofthegamefield (); }        Static voidSetballatthemiddleofthegamefield () {Ballpositionx= Console.windowwidth/2; Ballpositiony= Console.windowheight/2; }        Static voidDrawball () {printatposition (Ballpositionx, Ballpositiony,'@'); }        Static voidPrintresult () {console.setcursorposition (Console.windowwidth/2-1,0); Console.Write ("{0}-{1}", Firstplayerresult, Secondplayerresult); }        Static voidMovefirstplayerdown () {if(Firstplayerposition < Console.windowheight-firstplayerpadsize) {firstplayerposition++; }        }        Static voidMovefirstplayerup () {if(Firstplayerposition >0) {firstplayerposition--; }        }        Static voidMovesecondplayerdown () {if(Secondplayerposition < Console.windowheight-secondplayerpadsize) {secondplayerposition++; }        }        Static voidMovesecondplayerup () {if(Secondplayerposition >0) {secondplayerposition--; }        }        Static voidSecondplayeraimove () {intRandomnumber = Randomgenerator.next (1,101); //if (Randomnumber = = 0)//{            //Movesecondplayerup (); //}            //if (Randomnumber = = 1)//{            //Movesecondplayerdown (); //}            if(Randomnumber <= -)            {                if(Balldirectionup = =true) {Movesecondplayerup (); }                Else{movesecondplayerdown (); }            }        }        Private Static voidMoveball () {if(Ballpositiony = =0) {Balldirectionup=false; }            if(Ballpositiony = = Console.windowheight-1) {Balldirectionup=true; }            if(Ballpositionx = = Console.windowwidth-1) {Setballatthemiddleofthegamefield (); Balldirectionright=false; Balldirectionup=true; Firstplayerresult++; Console.setcursorposition (Console.windowwidth/2, Console.windowheight/2); Console.WriteLine ("First player wins!");            Console.readkey (); }            if(Ballpositionx = =0) {Setballatthemiddleofthegamefield (); Balldirectionright=true; Balldirectionup=true; Secondplayerresult++; Console.setcursorposition (Console.windowwidth/2, Console.windowheight/2); Console.WriteLine ("Second player wins!");            Console.readkey (); }            if(Ballpositionx <3)            {                if(Ballpositiony >=firstplayerposition&& Ballpositiony < Firstplayerposition +firstplayerpadsize) {Balldirectionright=true; }            }            if(Ballpositionx >= Console.windowwidth-3-1)            {                if(Ballpositiony >=secondplayerposition&& Ballpositiony < Secondplayerposition +secondplayerpadsize) {Balldirectionright=false; }            }            if(balldirectionup) {Ballpositiony--; }            Else{ballpositiony++; }            if(balldirectionright) {Ballpositionx++; }            Else{Ballpositionx--; }        }        Static voidMain (string[] args)            {Removescrollbars ();            Setinitialpositions ();  while(true)            {                if(console.keyavailable) {consolekeyinfo keyInfo=Console.readkey (); if(Keyinfo.key = =consolekey.uparrow) {Movefirstplayerup (); }                    if(Keyinfo.key = =consolekey.downarrow) {movefirstplayerdown ();                }} secondplayeraimove ();                Moveball ();                Console.clear ();                Drawfirstplayer ();                Drawsecondplayer ();                Drawball ();                Printresult (); Thread.Sleep ( -); }        }    }}/*|____________________________________ ||                                     1-0 | |                                     ||         |||                                   *                         *|||                                   *|||                                   *|||                                     *||                                     ||                                     ||                                     ||                                     || || _____________________________________|_*/

Novice and learner worthy to see the code! Click to download

GitHub download down C # console mini-game [including source code]

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.