Dota design model-Memorandum

Source: Internet
Author: User
Tags dota
In the memo mode, the most direct thing is to record the game progress. If an 18-level game cannot record the game progress, it must start from the first level each time, if you want to give up the game, I will, hey.
Serialization in C # makes it easier for us to complete the memorandum mode. The UML diagram gives you a concept:

Details Code See the complete code.
Test code:
Dotapatternlibrary. Memento. Game = new dotapatternlibrary. Memento. Game ();
Game. gamelevel = 1;
Landpyform. Form. outputresult ("gamelevel:" + game. gamelevel );
Landpyform. Form. outputresult ("ten minute left ");
Game. gamelevel = 5;
Landpyform. Form. outputresult ("gamelevel:" + game. gamelevel );
Landpyform. Form. outputresult ("savegame ");
Dotapatternlibrary. Memento. gameprogress = game. getgameprogress ();
System. runtime. serialization. iformatter formatter = new system. runtime. serialization. formatters. Binary. binaryformatter ();
System. Io. filestream fsobj = new system. Io. filestream ("gameprogress. dat", system. Io. filemode. Create );
Formatter. serialize (fsobj, gameprogress );
Fsobj. Close ();
Landpyform. Form. outputresult ("Save OK ");
Thread. Sleep (3000 );
Landpyform. Form. outputresult ("3 second left ");

System. Io. filestream fsobj2 = new system. Io. filestream ("gameprogress. dat", system. Io. filemode. Open );
Gameprogress = formatter. deserialize (fsobj2) as dotapatternlibrary. Memento. gameprogress;
Dotapatternlibrary. Memento. Game game2 = new dotapatternlibrary. Memento. Game ();
Landpyform. Form. outputresult ("gamelevel:" + game2.gamelevel );
Landpyform. Form. outputresult ("loadgame ");
Game2.setprogress (gameprogress );
Landpyform. Form. outputresult ("gamelevel:" + game2.gamelevel );
Complete code: Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
Using System. runtime. serialization. formatters. Binary;
Using System. runtime. serialization;
Using System. IO;

NamespaceDotapatternlibrary. Memento
{
[Serializable]
Public ClassGame
{
Private Int_ Gamelevel;

Public IntGamelevel
{
Get{Return_ Gamelevel ;}
Set{_ Gamelevel=Value ;}
}

Public Gameprogress getgameprogress ()
{
Return   New Gameprogress ( This );
}
Public   Void Setprogress (gameprogress)
{
This . _ Gamelevel = Gameprogress. Game. gamelevel;
}
}

[serializable]
Public class gameprogress
{< br> Public game;
Public gameprogress (Game)
{< br> This . game = game;
}< 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.