Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace MatiWejściówka
  5. {
  6.     interface iMapa
  7.     {
  8.         public void generate();
  9.         public void list();
  10.         public void show();
  11.     }
  12.     public class Mapa : iMapa
  13.     {
  14.         public int rozmiar;
  15.         public int lvle;
  16.  
  17.         public Random rnd = new Random();
  18.         public int randomseed;
  19.      
  20.         List<String> ListaElemtow = new List<String>();
  21.  
  22.         public Mapa(int rozmiar)
  23.         {
  24.             this.rozmiar = rozmiar;
  25.            
  26.         }
  27.        
  28.         public void generate()
  29.         {
  30.  
  31.            
  32.             char[,] tmp_mapa = new char[this.rozmiar, this.rozmiar];
  33.            
  34.             for(int i=1;i<this.rozmiar;i++)
  35.             {
  36.                 for(int j=1;j<this.rozmiar;j++)
  37.                 {
  38.                     randomseed = rnd.Next(1, 8);
  39.                     if (randomseed == 1 || randomseed == 2) // dodawanie trawy
  40.                     {
  41.                         Point tmp_point = new Point(i, j);
  42.                         Grass tmp_grass = new Grass(tmp_point.x, tmp_point.y, 'G');
  43.  
  44.                         tmp_mapa[i, j] = tmp_grass.icon;
  45.  
  46.                         ListaElemtow.Add(tmp_grass.Print());//dodawanie do listy elemetow
  47.  
  48.                     }
  49.                     else if (randomseed == 3 || randomseed == 4) //dodawanie drzew
  50.                     {
  51.                         Point tmp_point = new Point(i, j);
  52.                         Tree tmp_tree = new Tree(tmp_point.x, tmp_point.y, 'T');
  53.  
  54.                         tmp_mapa[i, j] = tmp_tree.icon;
  55.                         ListaElemtow.Add(tmp_tree.Print()); //dodawanie do listy elemetow
  56.  
  57.                     }
  58.                     else if (randomseed == 5 || randomseed == 6) // dodawanie kamieni
  59.                     {
  60.                         Point tmp_point = new Point(i, j);
  61.                         Rock tmp_rock = new Rock(tmp_point.x, tmp_point.y, 'R');
  62.  
  63.                         tmp_mapa[i, j] = tmp_rock.icon;
  64.                         ListaElemtow.Add(tmp_rock.Print());//dodawanie do listy elemetow
  65.  
  66.                     }
  67.                     else if (randomseed == 7 ) // ograniczenie szans na wystopienie przeciwnika
  68.                     {
  69.                         Point tmp_point = new Point(i, j);
  70.                         Enemy tmp_enemy = new Enemy(tmp_point.x, tmp_point.y, 'E',lvle = rnd.Next(1,11),"Testowy_Przecinik");
  71.  
  72.                         tmp_mapa[i, j] = tmp_enemy.icon;
  73.                         ListaElemtow.Add(tmp_enemy.Print());//dodawanie do listy elemetow
  74.                        
  75.                     }
  76.                     // mozliwosc dalszej dobudowy
  77.                    
  78.                 }
  79.              
  80.             }
  81.             //show wbudowany w generate
  82.             Console.WriteLine("MAPA:");
  83.             for (int i = 0; i < tmp_mapa.GetLength(0); i++)
  84.             {
  85.                 for (int j = 0; j < tmp_mapa.GetLength(1); j++)
  86.                 {
  87.                     Console.Write(string.Format("{0} ", tmp_mapa[i, j]));
  88.                 }
  89.                 Console.Write(Environment.NewLine + Environment.NewLine);
  90.             }
  91.             Console.ReadLine();
  92.  
  93.         }
  94.  
  95.         public void list()
  96.         {
  97.             ListaElemtow.ForEach(Console.WriteLine);
  98.            
  99.         }
  100.  
  101.  
  102.         public void show()// show jest wbudowany w generate nie mialem pomyslu
  103.         {
  104.            
  105.            
  106.         }
  107.     }
  108.    
  109.     public class Point
  110.     {
  111.         public int x;
  112.         public int y;
  113.  
  114.         public Point(int x, int y)
  115.         {
  116.             this.x = x;
  117.             this.y = y;
  118.         }
  119.  
  120.         public string Print()
  121.         {
  122.             return "Punkt :" + this.x + "-" + this.y;
  123.         }
  124.     }
  125.     public class MapElement : Point
  126.     {
  127.         public char icon;
  128.  
  129.         public MapElement(int x, int y,char icon) : base(x, y)
  130.         {
  131.             this.icon = icon;
  132.         }
  133.     }
  134.     public class Grass : MapElement
  135.     {
  136.  
  137.         public Grass(int x, int y, char icon) : base(x, y, icon)
  138.         {
  139.         }
  140.         public string Print()
  141.         {
  142.             this.icon = 'G';
  143.             return "Punkt " + this.icon+ "| Cordinates " + "x:"+ this.x + " y:"+this.y;
  144.         }
  145.     }
  146.     public class Tree : MapElement
  147.     {
  148.  
  149.         public Tree(int x, int y, char icon) : base(x, y, icon)
  150.         {
  151.         }
  152.         public string Print()
  153.         {
  154.             this.icon = 'T';
  155.             return "Punkt " + this.icon + "| Cordinates " + "x:"+ this.x + " y:" + this.y;
  156.         }
  157.     }
  158.     public class Rock : MapElement
  159.     {
  160.  
  161.         public Rock(int x, int y, char icon) : base(x, y, icon)
  162.         {
  163.         }
  164.         public string Print()
  165.         {
  166.             this.icon = 'R';
  167.             return "Punkt " + this.icon+ "| Cordinates " + "x:"+this.x + " y:" + this.y;
  168.         }
  169.     }
  170.     public class Enemy : MapElement// Enemy dzieciczy po Map element bo tak jak np. Kamien jest obiektem mapy i ma cechy wspolne z resztą(x,y,icon)                
  171.     {
  172.         int lvl;
  173.         string name;
  174.         public Enemy(int x, int y, char icon,int lvl,string name) : base(x, y, icon)
  175.         {
  176.             this.lvl = lvl;
  177.             this.name = name;
  178.         }
  179.         public string Print()
  180.         {
  181.             this.icon = 'E';
  182.             return "Punkt " + this.icon +"| Cordinates " +"x:" + this.x + " y:" + this.y;
  183.         }
  184.     }
  185.  
  186.     class Program
  187.     {
  188.         static void Main(string[] args)
  189.         {
  190.             Mapa Nowa1 = new Mapa(10);
  191.             Nowa1.generate();
  192.             Nowa1.list();
  193.             Console.ReadKey();
  194.         }
  195.     }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement