Guest User

Untitled

a guest
Jun 23rd, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         public Program(String sav)
  11.         {
  12.             this.save = sav;
  13.         }
  14.         public Player p = new Player();
  15.         public String save;
  16.         public void game()
  17.         {
  18.             try{
  19.                 string option = mainScreen();
  20.                 if (option == "new game")
  21.                 {
  22.                     Program.Main(null);
  23.                 }
  24.                 else if (option == "level up")
  25.                 {
  26.                     if (p.lastLevel > 0)
  27.                     {
  28.                         levelUp();
  29.                     }
  30.                     else
  31.                     {
  32.                         game();
  33.                     }
  34.                 }
  35.                 else if (option == "fight")
  36.                 {
  37.                     try
  38.                     {
  39.                         new Fight(this, p, new Monster(p.level));
  40.                     }
  41.                     catch (Exception e)
  42.                     {
  43.                         error(this);
  44.                     }
  45.                 }
  46.                 else if (option == "hp potion")
  47.                 {
  48.                     p.useHp();
  49.                     game();
  50.                 }
  51.                 else if (option.StartsWith("save"))
  52.                 {
  53.                     try
  54.                     {
  55.                         string[] split = option.Split(' ');
  56.                         if (split.Length > 0)
  57.                         {
  58.                             FileManager.save(this, split[1], false);
  59.                         }
  60.                         else
  61.                         {
  62.                             FileManager.save(this, save, false);
  63.                         }
  64.  
  65.                         game();
  66.                     }
  67.                     catch (Exception e)
  68.                     {
  69.                         error(this);
  70.                     }
  71.                 }
  72.                 else if (option.StartsWith("load"))
  73.                 {
  74.                     string[] split = option.Split(' ');
  75.                     FileManager.load(split[1]).game();
  76.                 }
  77.                 else if (option.StartsWith("delete"))
  78.                 {
  79.                     if (option.StartsWith("delete "))
  80.                     {
  81.                         string[] split = option.Split(' ');
  82.                         FileManager.delete(split[1]);
  83.                         if (split[1] == save)
  84.                         {
  85.                             Program.Main(null);
  86.                         }
  87.                         else
  88.                         {
  89.                             game();
  90.                         }
  91.                     }
  92.                     else if (option == "delete")
  93.                     {
  94.                         {
  95.                             FileManager.delete(save);
  96.                             Program.Main(null);
  97.                         }
  98.                     }
  99.                 }
  100.                 else if(option.StartsWith("rename")) {
  101.                     string[] split = option.Split(' ');
  102.                     if (split.Length == 2) {
  103.                         FileManager.save(this, split[1], false);
  104.                         FileManager.delete(save);
  105.                         save = split[1];
  106.                         game();
  107.                     }else if (split.Length == 3) {
  108.                         Program p = FileManager.load(split[1]);
  109.                         FileManager.save(p, split[2], false);
  110.                         FileManager.delete(split[1]);
  111.                         game();
  112.                     }else{
  113.                         game();
  114.                     }
  115.                 }
  116.                 else
  117.                 {
  118.                     game();
  119.                 }
  120.             }catch(Exception e){
  121.                 error(this);
  122.             }
  123.         }
  124.         public String mainScreen()
  125.         {
  126.             Console.Clear();
  127.             p.check(this);
  128.             String levelup = "none";
  129.             if (p.lastLevel > 0)
  130.             {
  131.                 levelup = p.lastLevel.ToString();
  132.             }
  133.             Console.WriteLine("");
  134.             Console.WriteLine("----Monster-Game---V1----");
  135.             Console.WriteLine("==  Save:   "+save);
  136.             Console.WriteLine("-------------------------");
  137.             Console.WriteLine("==  HEALTH: "+p.hp.ToString()+"/"+p.maxHP);
  138.             Console.WriteLine("==  SWORD:  "+p.sd.ToString());
  139.             Console.WriteLine("==  MAGIC:  "+p.md.ToString());
  140.             Console.WriteLine("==  BOW:    "+p.bd.ToString());
  141.             Console.WriteLine("-------------------------");
  142.             Console.WriteLine("== HP-MULTIPLIER:  "+p.hmulti.ToString());
  143.             Console.WriteLine("== DMG-MULTIPLIER: " + p.hmulti.ToString());
  144.             Console.WriteLine("== HP-POTIONS:     "+p.hpotions);
  145.             Console.WriteLine("-------------------------");
  146.             Console.WriteLine("== LEVEL:      "+p.level.ToString());
  147.             Console.WriteLine("== XP:         "+p.xp.ToString());
  148.             Console.WriteLine("== LEVEL UPS:  "+levelup.ToString());
  149.             Console.WriteLine("-------------------------");
  150.             Console.WriteLine("--  FIGHT   |LEVEL UP  --");
  151.             Console.WriteLine("--  NEW GAME|HP POTION --");
  152.             Console.WriteLine("--  SAVE    |LOAD      --");
  153.             Console.WriteLine("--  DELETE  |RENAME    --");
  154.             Console.WriteLine("-------------------------");
  155.             Console.WriteLine("");
  156.             String option = Console.ReadLine().ToLower();
  157.             return option;
  158.         }
  159.         public void levelUp()
  160.         {
  161.             Console.Clear();
  162.             Console.WriteLine("");
  163.             Console.WriteLine("----Monster-Game---V1----");
  164.             Console.WriteLine("==  Save:   " + save);
  165.             Console.WriteLine("-------------------------");
  166.             Console.WriteLine("== LEVEL UPS: " + p.lastLevel);
  167.             Console.WriteLine("-------------------------");
  168.             Console.WriteLine("--       LEVEL UP      --");
  169.             Console.WriteLine("-------------------------");
  170.             Console.WriteLine("--        CANCEL       --");
  171.             Console.WriteLine("-- SWORD BOW  MAGIC HP --");
  172.             Console.WriteLine("-------------------------");
  173.             Console.WriteLine("");
  174.             String option = Console.ReadLine().ToLower();
  175.             if (option == "cancel")
  176.             {
  177.                 game();
  178.             }
  179.             else if (option == "sword")
  180.             {
  181.                 p.sd = p.sd + 1;
  182.                 p.lastLevel = p.lastLevel - 1;
  183.                 p.level = p.level + 1;
  184.             }
  185.             else if (option == "bow")
  186.             {
  187.                 p.bd = p.bd + 1;
  188.                 p.lastLevel = p.lastLevel - 1;
  189.                 p.level = p.level + 1;
  190.             }
  191.             else if (option == "magic")
  192.             {
  193.                 p.md = p.md + 1;
  194.                 p.lastLevel = p.lastLevel - 1;
  195.                 p.level = p.level + 1;
  196.             }
  197.             else if (option == "hp")
  198.             {
  199.                 p.maxHP = p.maxHP + 1;
  200.                 p.hp = p.maxHP;
  201.                 p.lastLevel = p.lastLevel - 1;
  202.                 p.level = p.level + 1;
  203.             }
  204.             game();
  205.         }
  206.         public void gameover()
  207.         {
  208.             Console.Clear();
  209.             Console.WriteLine("");
  210.             Console.WriteLine("----Monster-Game---V1----");
  211.             Console.WriteLine("==  Save:   " + save);
  212.             Console.WriteLine("-------------------------");
  213.             Console.WriteLine("--      GAME OVER      --");
  214.             Console.WriteLine("-------------------------");
  215.             Console.WriteLine("");
  216.             Console.ReadLine();
  217.             FileManager.delete(save);
  218.             Program.Main(null);
  219.         }
  220.         public static void error(Program pr)
  221.         {
  222.             Console.Clear();
  223.             Console.WriteLine("==ERROR==");
  224.             try
  225.             {
  226.                 FileManager.save(pr, pr.save, true);
  227.             }
  228.             catch (Exception e)
  229.             {
  230.  
  231.             }
  232.             Console.ReadLine();
  233.            
  234.             if (pr != null)
  235.             {
  236.                 pr.game();
  237.             }
  238.             else
  239.             {
  240.                 Program.Main(null);
  241.             }
  242.         }
  243.  
  244.         static void Main(string[] args)
  245.         {
  246.             Console.Clear();
  247.             Console.WriteLine("");
  248.             Console.WriteLine("----Monster-Game---V1----");
  249.             Console.WriteLine("--  START  LOAD  LIST  --");
  250.             Console.WriteLine("-------------------------");
  251.             Console.WriteLine("");
  252.             String option = Console.ReadLine();
  253.             option = option.ToLower();
  254.             if (option.StartsWith("start"))
  255.             {
  256.                 try
  257.                 {
  258.                     string[] split = option.Split(' ');
  259.                     Program pg = new Program(split[1]);
  260.                     pg.game();
  261.                     FileManager.save(pg, pg.save, false);
  262.                 }
  263.                 catch (Exception e)
  264.                 {
  265.                     Program.error(null);
  266.                 }
  267.             }
  268.             else if (option == "list")
  269.             {
  270.                 Console.Clear();
  271.                 String op = FileManager.listSaves();
  272.                 if (op.StartsWith("load"))
  273.                 {
  274.                     try
  275.                     {
  276.                         string[] split = op.Split(' ');
  277.                         FileManager.load(split[1]).game();
  278.                     }
  279.                     catch (Exception e)
  280.                     {
  281.                         Program.error(null);
  282.                     }
  283.                 }
  284.                 else if (op == "back")
  285.                 {
  286.                     Program.Main(null);
  287.                 }
  288.                 else
  289.                 {
  290.                     Program.Main(null);
  291.                 }
  292.             }
  293.             else if (option.StartsWith("load"))
  294.             {
  295.                 try
  296.                 {
  297.                     string[] split = option.Split(' ');
  298.                     FileManager.load(split[1]).game();
  299.                 }
  300.                 catch (Exception e)
  301.                 {
  302.                     Program.error(null);
  303.                 }
  304.             }
  305.             else
  306.             {
  307.                 Program.Main(null);
  308.             }
  309.         }
  310.     }
  311. }
Add Comment
Please, Sign In to add comment