Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/CourseApp/bin/Debug/net6.0/CourseApp.dll",
"args": [],
"cwd": "${workspaceFolder}/CourseApp",
"console": "integratedTerminal",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"**/.svn": true,
"**/CVS": true,
"**/.DS_Store": true,
"CourseApp": true,
"CourseApp.Tests":true,
"CourseApp": false,
"CourseApp.Tests":false,
"WebApplication":true
}
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/CourseApp/CourseApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/CourseApp/CourseApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/CourseApp/CourseApp.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
152 changes: 152 additions & 0 deletions CourseApp/Game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
namespace CourseApp
{
using System;
using System.Collections.Generic;

public class Game
{
public static void Start()
{
int p_number = AskNumber();
List<Player> playerList = PlayerListGenerator(p_number);
PlayGame(playerList);
}

private static void PlayGame(List<Player> playerList)
{
for (int i = 1; playerList.Count != 1; i++)
{
Logger.WriteRound(i);
RandomizeList(playerList);
PlayRound(playerList);
}

Logger.WriteWinner(playerList[0]);
}

private static void PlayRound(List<Player> playerList)
{
for (int i = 0; i < playerList.Count / 2; i++)
{
Player[] fightMembers = { playerList[i * 2], playerList[(i * 2) + 1] };
Logger.WriteFight(fightMembers);
playerList[i * 2] = PlayFight(fightMembers);
}

for (int i = 1; i < playerList.Count; i++)
{
playerList.RemoveAt(i);
}
}

private static Player PlayFight(Player[] fightMembers)
{
for (int i = 0; true; i++)
{
var playerStatus = fightMembers[i % 2].CheckStatus();
Logger.WriteAction(fightMembers[i % 2], playerStatus);
bool checkDeath = fightMembers[i % 2].CheckDeath();
if (checkDeath)
{
fightMembers[(i + 1) % 2].Update();
return fightMembers[(i + 1) % 2];
}

if (playerStatus.Contains(Tuple.Create("Заворожение", .0f)))
{
continue;
}

Tuple<string, float> playerAction = PlayerDoAction(fightMembers[i % 2]);
Logger.WriteAction(fightMembers[i % 2], fightMembers[(i + 1) % 2], playerAction);
if ((playerAction.Item1 != "наносит урон") && (playerAction.Item1 != "Удар возмездия"))
{
fightMembers[(i + 1) % 2].SetDebaff(playerAction.Item1);
}

checkDeath = fightMembers[(i + 1) % 2].GetDamage(playerAction.Item2);
if (checkDeath)
{
Logger.WriteDeath(fightMembers[(i + 1) % 2]);
fightMembers[i % 2].Update();
return fightMembers[i % 2];
}
}
}

private static Tuple<string, float> PlayerDoAction(Player inputP)
{
Random rnd = new Random();
int chosen = rnd.Next(0, 4);
switch (chosen)
{
case 0:
return inputP.Ability();
default:
return inputP.Attack();
}
}

private static int AskNumber()
{
while (true)
{
Console.WriteLine("Введите четное количество игроков:");
int p_number = Convert.ToInt32(Console.ReadLine());
if (p_number <= 0)
{
Console.WriteLine("Число игроков должно быть больше 0!");
}
else if (p_number % 2 != 0)
{
Console.WriteLine("Число игроков должно быть четным!");
}
else
{
return p_number;
}
}
}

private static void RandomizeList(List<Player> input)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а зачем? может просто рэндомно из списка брать?

{
Random rnd = new Random();
for (int i = 0; i < input.Count; i++)
{
int chosen = rnd.Next(i, input.Count);
(input[i], input[chosen]) = (input[chosen], input[i]);
}
}

private static List<Player> PlayerListGenerator(int count)
{
List<Player> playerList = new List<Player>();
for (int i = 0; i < count; i++)
{
playerList.Add(PlayerGenerator());
}

return playerList;
}

private static Player PlayerGenerator()
{
string[] names = { "Вальлиикт", "Йоророу", "Бенинэл", "Билелгар", "Вилдровер", "Бреновуд", "Труеон", "Филдис", "Грейнерэл", "Бертэам", "Ирвдес", "Франкернон", "Куртдитор" };
Random rnd = new Random();
int health = (int)rnd.NextInt64(1, 64);
int strength = (int)rnd.NextInt64(1, 64);
int chouse = (int)rnd.NextInt64(0, 3);
switch (chouse)
{
case 0:
return new Knight(health, strength, names[rnd.Next(names.Length)]);
case 1:
return new Mage(health, strength, names[rnd.Next(names.Length)]);
case 2:
return new Archer(health, strength, names[rnd.Next(names.Length)]);
default:
return new Knight(health, strength, names[rnd.Next(names.Length)]);
}
}
}
}
30 changes: 30 additions & 0 deletions CourseApp/GameClasses/Archer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace CourseApp
{
using System;

public class Archer : Player
{
public Archer(int health, int strength, string name)
: base(health, strength, name, "Огненная стрела", 1)
{
}

public override string ToString()
{
return "(Лучник) " + Name;
}

public override Tuple<string, float> Ability()
{
if (AbilityLeft > 0)
{
AbilityLeft--;
return Tuple.Create(AbilityName, 0.0f);
}
else
{
return Attack();
}
}
}
}
30 changes: 30 additions & 0 deletions CourseApp/GameClasses/Knight.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace CourseApp
{
using System;

public class Knight : Player
{
public Knight(int health, int strength, string name)
: base(health, strength, name, "Удар возмездия", 1)
{
}

public override string ToString()
{
return "(Рыцарь) " + Name;
}

public override Tuple<string, float> Ability()
{
if (AbilityLeft > 0)
{
AbilityLeft--;
return Tuple.Create(AbilityName, (float)Math.Round(Strength * 1.3f, 2));
}
else
{
return Attack();
}
}
}
}
30 changes: 30 additions & 0 deletions CourseApp/GameClasses/Mage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace CourseApp
{
using System;

public class Mage : Player
{
public Mage(int health, int strength, string name)
: base(health, strength, name, "Заворожение", 1)
{
}

public override string ToString()
{
return "(Маг) " + Name;
}

public override Tuple<string, float> Ability()
{
if (AbilityLeft > 0)
{
AbilityLeft--;
return Tuple.Create(AbilityName, 0.0f);
}
else
{
return Attack();
}
}
}
}
67 changes: 67 additions & 0 deletions CourseApp/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
namespace CourseApp
{
using System;
using System.Collections.Generic;

public static class Logger
{
public static void WriteWinner(Player winner)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У кого логгер копировали?

{
Console.WriteLine($"{winner.ToString()} ПОБЕДИЛ!");
}

public static void WriteRound(int round)
{
Console.WriteLine($"Раунд {round}.");
}

public static void WriteFight(Player[] fightMembers)
{
Console.WriteLine($"{fightMembers[0].ToString()} VS {fightMembers[1].ToString()}");
}

public static void WriteAction(Player firstP, Player secondP, Tuple<string, float> playerAction)
{
switch (playerAction.Item1)
{
case "наносит урон":
Console.WriteLine($"{firstP.ToString()} наносит урон {playerAction.Item2} противнику {secondP.ToString()}");
break;
case "Удар возмездия":
Console.WriteLine($"{firstP.ToString()} применяет ({playerAction.Item1}) и наносит урон {playerAction.Item2} противнику {secondP.ToString()}");
break;
case "Огненная стрела":
Console.WriteLine($"{firstP.ToString()} применяет ({playerAction.Item1}) по противнику {secondP.ToString()}");
break;
case "Заворожение":
Console.WriteLine($"{firstP.ToString()} применяет ({playerAction.Item1}) по противнику {secondP.ToString()}");
break;
}
}

public static void WriteAction(Player inputP, List<Tuple<string, float>> playerStatus)
{
foreach (var debaff in playerStatus)
{
switch (debaff.Item1)
{
case "Огненная стрела":
Console.WriteLine($"{inputP.ToString()} получает периодический урон {debaff.Item2} от ({debaff.Item1})");
break;
case "Заворожение":
Console.WriteLine($"{inputP.ToString()} пропускает ход из-за ({debaff.Item1})");
break;
case "PlayerIsDied":
WriteDeath(inputP);
break;
}
}
}

public static void WriteDeath(Player inputP)
{
Console.WriteLine($"{inputP.ToString()} погибает");
Console.WriteLine();
}
}
}
Loading