Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace MatiWejściówka
- {
- interface iMapa
- {
- public void generate();
- public void list();
- public void show();
- }
- public class Mapa : iMapa
- {
- public int rozmiar;
- public int lvle;
- public Random rnd = new Random();
- public int randomseed;
- List<String> ListaElemtow = new List<String>();
- public Mapa(int rozmiar)
- {
- this.rozmiar = rozmiar;
- }
- public void generate()
- {
- char[,] tmp_mapa = new char[this.rozmiar, this.rozmiar];
- for(int i=1;i<this.rozmiar;i++)
- {
- for(int j=1;j<this.rozmiar;j++)
- {
- randomseed = rnd.Next(1, 8);
- if (randomseed == 1 || randomseed == 2) // dodawanie trawy
- {
- Point tmp_point = new Point(i, j);
- Grass tmp_grass = new Grass(tmp_point.x, tmp_point.y, 'G');
- tmp_mapa[i, j] = tmp_grass.icon;
- ListaElemtow.Add(tmp_grass.Print());//dodawanie do listy elemetow
- }
- else if (randomseed == 3 || randomseed == 4) //dodawanie drzew
- {
- Point tmp_point = new Point(i, j);
- Tree tmp_tree = new Tree(tmp_point.x, tmp_point.y, 'T');
- tmp_mapa[i, j] = tmp_tree.icon;
- ListaElemtow.Add(tmp_tree.Print()); //dodawanie do listy elemetow
- }
- else if (randomseed == 5 || randomseed == 6) // dodawanie kamieni
- {
- Point tmp_point = new Point(i, j);
- Rock tmp_rock = new Rock(tmp_point.x, tmp_point.y, 'R');
- tmp_mapa[i, j] = tmp_rock.icon;
- ListaElemtow.Add(tmp_rock.Print());//dodawanie do listy elemetow
- }
- else if (randomseed == 7 ) // ograniczenie szans na wystopienie przeciwnika
- {
- Point tmp_point = new Point(i, j);
- Enemy tmp_enemy = new Enemy(tmp_point.x, tmp_point.y, 'E',lvle = rnd.Next(1,11),"Testowy_Przecinik");
- tmp_mapa[i, j] = tmp_enemy.icon;
- ListaElemtow.Add(tmp_enemy.Print());//dodawanie do listy elemetow
- }
- // mozliwosc dalszej dobudowy
- }
- }
- //show wbudowany w generate
- Console.WriteLine("MAPA:");
- for (int i = 0; i < tmp_mapa.GetLength(0); i++)
- {
- for (int j = 0; j < tmp_mapa.GetLength(1); j++)
- {
- Console.Write(string.Format("{0} ", tmp_mapa[i, j]));
- }
- Console.Write(Environment.NewLine + Environment.NewLine);
- }
- Console.ReadLine();
- }
- public void list()
- {
- ListaElemtow.ForEach(Console.WriteLine);
- }
- public void show()// show jest wbudowany w generate nie mialem pomyslu
- {
- }
- }
- public class Point
- {
- public int x;
- public int y;
- public Point(int x, int y)
- {
- this.x = x;
- this.y = y;
- }
- public string Print()
- {
- return "Punkt :" + this.x + "-" + this.y;
- }
- }
- public class MapElement : Point
- {
- public char icon;
- public MapElement(int x, int y,char icon) : base(x, y)
- {
- this.icon = icon;
- }
- }
- public class Grass : MapElement
- {
- public Grass(int x, int y, char icon) : base(x, y, icon)
- {
- }
- public string Print()
- {
- this.icon = 'G';
- return "Punkt " + this.icon+ "| Cordinates " + "x:"+ this.x + " y:"+this.y;
- }
- }
- public class Tree : MapElement
- {
- public Tree(int x, int y, char icon) : base(x, y, icon)
- {
- }
- public string Print()
- {
- this.icon = 'T';
- return "Punkt " + this.icon + "| Cordinates " + "x:"+ this.x + " y:" + this.y;
- }
- }
- public class Rock : MapElement
- {
- public Rock(int x, int y, char icon) : base(x, y, icon)
- {
- }
- public string Print()
- {
- this.icon = 'R';
- return "Punkt " + this.icon+ "| Cordinates " + "x:"+this.x + " y:" + this.y;
- }
- }
- 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)
- {
- int lvl;
- string name;
- public Enemy(int x, int y, char icon,int lvl,string name) : base(x, y, icon)
- {
- this.lvl = lvl;
- this.name = name;
- }
- public string Print()
- {
- this.icon = 'E';
- return "Punkt " + this.icon +"| Cordinates " +"x:" + this.x + " y:" + this.y;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Mapa Nowa1 = new Mapa(10);
- Nowa1.generate();
- Nowa1.list();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement