C # snake games-Game Information Access (4)

Source: Internet
Author: User

If the game is not archived and starts from scratch every time, it will be boring. To improve the playability of the game, I have added the information access function, mainly including the game points, the access and ranking of the game role, so that each time you open the game, you can see the highest score! In this way, it is challenging. Challenge the highest score and record your name on the hero list!

I use points. The player-format saves the Game Information on the notepad of the local disk @ "D:/snkegameinfo.txt". This way, after starting the game, you can read and store the game information.

And sort the hero rankings by points:

Savegameinfo. CS

Public class savegameinfo <br/>{< br/> private string filepath = @ "D:/snkegameinfo.txt "; <br/> // save information <br/> Public bool saveinfo (string score, string player) <br/>{< br/> try <br/> {<br/> // if there is no information archiving file, the new key file, otherwise, append information to the end of an existing file <br/> filestream; <br/> If (! File. exists (filepath) <br/> filestream = new filestream (filepath, filemode. create); <br/> else <br/> filestream = new filestream (filepath, filemode. append); <br/> streamwriter = new streamwriter (filestream); <br/> streamwriter. write (score + ";" + player + "-"); <br/> streamwriter. close (); <br/> return true; <br/>}< br/> catch {return false ;} </P> <p >}< br/> // read information <br/> Public String [] Readinfo () <br/>{< br/> If (! File. exists (filepath) <br/> return NULL; <br/> else <br/>{< br/> string [] scores = new string [] {}; // score and player <br/> try <br/>{</P> <p> string STR = ""; <br/> filestream = new filestream (filepath, filemode. open); <br/> streamreader = new streamreader (filestream); <br/> STR = streamreader. readtoend (); <br/> scores = Str. split ('-'); <br/> streamreader. close (); <br/>}< br/> catch {}< br/> return scores; <br/>}< br/>}

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.