Репозиторий для лекций
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

105 lines
1.9 KiB

using System;
using TEC.Model;
namespace TEC
{
public class Game
{
private Player[] players;
public Game(Player[] inputPlayers)
{
this.players = inputPlayers;
}
public enum Movement
{
Up = 1,
Down = 2,
Forward = 3,
Backward = 4
}
public void MoveMainPlayer(Movement move)
{
if (this.players.Length <= 0) { return; }
int lastPosX = this.players[0].GetPositionX();
int lastPosY = this.players[0].GetPositionY();
if (move == Movement.Forward)
{
this.players[0].SetPosition(lastPosX + 1, lastPosY);
}
if (move == Movement.Backward)
{
this.players[0].SetPosition(lastPosX - 1, lastPosY);
}
CheckConditions();
PrintField();
}
public delegate void eventPlayersOnSamePointDelegate();
public event eventPlayersOnSamePointDelegate eventPlayersOnSamePoint;
public void CheckConditions()
{
if (this.players.Length > 1)
{
if (this.players[0].GetPositionX() == this.players[1].GetPositionX() &&
this.players[0].GetPositionY() == this.players[1].GetPositionY() )
{
if (this.eventPlayersOnSamePoint != null)
{
this.eventPlayersOnSamePoint();
}
}
}
}
public void PrintField()
{
Console.Clear();
string[] lines = new string[20];
for (int i = 0; i < 20; i++)
{
string line = string.Empty;
for (int j = 0; j < 75; j++)
{
string c = ".";
foreach(Player player in players)
{
if (player.GetPositionX() == j && player.GetPositionY() == i)
{
c = "#";
if (player is Alien)
{
c = "@";
}
}
}
line = line + c;
}
lines[i] = line;
}
for (int i = lines.Length - 1; i >= 0; i--)
{
Console.WriteLine(lines[i]);
}
for(int p = 0; p < players.Length; p++)
{
Console.WriteLine("Игрок №" + (p+1) + " - " + players[p].name);
}
}
}
}