Arena
potřebuji poradit
C# .NET
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Arena
{
class Program
{
static void Main(string[] args)
{
Kostka kostka = new Kostka(10);
Bojovnik bojovnik = new Bojovnik("Zalgoren",100,20,10, kostka);
Bojovnik enemy = new Bojovnik("Gandalf", 100, 20, 10, kostka);
Console.WriteLine("Jméno vašeho bojovníka: "+bojovnik);
Console.WriteLine("Jméno nepřátelského bojovníka: " + enemy);
while (bojovnik.Alive()&& enemy.Alive())
{
bojovnik.Charge(enemy);
Console.WriteLine(bojovnik.ReturnLastMessage());
Console.WriteLine(enemy.ReturnLastMessage());
Console.WriteLine(enemy +": "+ enemy.GraphicLife());
Console.WriteLine("");
if (enemy.Alive())
{
enemy.Charge(bojovnik);
Console.WriteLine(enemy.ReturnLastMessage());
Console.WriteLine(bojovnik.ReturnLastMessage());
Console.WriteLine(bojovnik + ": " + bojovnik.GraphicLife());
Console.WriteLine("");
if(!bojovnik.Alive())
{
Console.WriteLine(enemy.ReturnLastMessage());
Console.WriteLine(bojovnik.ReturnLastMessage());
Console.ReadKey();
Environment.Exit(0);
}
}
else if(!enemy.Alive())
{
Console.WriteLine(bojovnik.ReturnLastMessage());
Console.WriteLine(enemy.ReturnLastMessage());
Console.ReadKey();
Environment.Exit(0);
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Arena
{
class Kostka
{
Random random = new Random();
int pocetSten;
public Kostka()
{
pocetSten = 6;
VratPocetSten();
}
public Kostka(int pocetSten)
{
this.pocetSten = pocetSten;
}
public int VratPocetSten()
{
return pocetSten;
}
public int Hod()
{
return random.Next(1, pocetSten+1);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Arena
{
class Bojovnik
{
private string message;
private int maxHealth;
private string name;
private int health;
private int attack;
private int defence;
private Kostka kostka;//Deklarace proměnných
private void SetMessage(string message)
{
this.message = message;
}
public Bojovnik(string name, int health, int attack, int defence, Kostka kostka)
{
this.name = name;
this.health = health;
this.attack = attack;
this.defence = defence;
this.maxHealth = health;
this.kostka = kostka;
}
public void Defend(int hit)
{
int wound = hit - (defence+kostka.Hod());
if (wound > 0)
{
health = health - wound;
message = String.Format("{0} utrpěl poškození {1} hp", name, wound);
if (health <= 0)
{
health = 0;
message += " a zemřel";
Console.ReadKey();
Environment.Exit(0);
}
}
else
{
message = String.Format("{0} odrazil útok", name);
SetMessage(message);
}
}
public void Charge(Bojovnik enemy)
{
int hit = attack + kostka.Hod();
SetMessage(String.Format("{0} útočí s úderem za {1} hp", name, hit));
enemy.Defend(hit);
}
public override string ToString()
{
return name;
}
public string GraphicLife()
{
string g = null;
int every = 20;
double count = Math.Round(((double)health / maxHealth) * every);
if(health == 0)
{
count = 1;
}
for (int i = 0; i < count; i++)
{
g += "█";
}
return g;
}
public bool Alive()
{
return (health > 0);
}
public string ReturnLastMessage()
{
return message;
}
}
}
Nefunguje mi zobrazení zpráv na konci bitvy
Neformátovaný
Přidáno: 3.10.2015
Expirace: Neuvedeno