Added code from other games
This commit is contained in:
25
Console Games/Ascii Showdown/ASCII Showdown.sln
Normal file
25
Console Games/Ascii Showdown/ASCII Showdown.sln
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.27428.2015
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASCII Showdown", "ASCII Showdown\ASCII Showdown.csproj", "{C3742581-795D-4CC3-A0EE-8CDC818E7ECB}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{C3742581-795D-4CC3-A0EE-8CDC818E7ECB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C3742581-795D-4CC3-A0EE-8CDC818E7ECB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{C3742581-795D-4CC3-A0EE-8CDC818E7ECB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C3742581-795D-4CC3-A0EE-8CDC818E7ECB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {31CA0659-13BC-49BE-9D74-DE142BD9AEFC}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
132
Console Games/Ascii Showdown/ASCII Showdown/AIMove.cs
Normal file
132
Console Games/Ascii Showdown/ASCII Showdown/AIMove.cs
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ASCII_Showdown {
|
||||||
|
class AIMove {
|
||||||
|
//you can have it fire a horizontal line of bullets, or fire every third step, or fire a bunch in a straight line
|
||||||
|
//give it shooting patterns that it can cycle through based on situation
|
||||||
|
|
||||||
|
List<int> lastDirection = new List<int>(); //0 left, 1 right
|
||||||
|
List<int> lastMode = new List<int>(); //last movetype stored in last index
|
||||||
|
Random rnd = new Random();
|
||||||
|
|
||||||
|
int type = 0;
|
||||||
|
int iterationsOfType = 0;
|
||||||
|
|
||||||
|
bool lineOfSight = true;
|
||||||
|
int lastKnownPos = 0;
|
||||||
|
|
||||||
|
public int cX { get; set; }
|
||||||
|
public int cY { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public char[,] moveCPU(char[,] grid, int width, int uX, int uY) {
|
||||||
|
if (grid[uX, uY - 2] == '█') { //checks if user is hiding
|
||||||
|
uX = lastKnownPos;
|
||||||
|
lineOfSight = false;
|
||||||
|
} else {
|
||||||
|
lineOfSight = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
type = getAItype(grid, width, uX, uY);
|
||||||
|
|
||||||
|
if (type == 0) {
|
||||||
|
return grid;
|
||||||
|
} else if (type == 1) { //defensive, retreat and shoot every 8th
|
||||||
|
if (iterationsOfType % 8 == 0) {
|
||||||
|
grid[cX, cY + 1] = '▼';
|
||||||
|
}
|
||||||
|
if (iterationsOfType % 4 == 0) {
|
||||||
|
if (cX < uX) {
|
||||||
|
grid = moveRight(grid, width);
|
||||||
|
} else {
|
||||||
|
grid = moveLeft(grid, width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (type == 2) { //aggressive
|
||||||
|
|
||||||
|
} else if (type == 3) { //try to break walls
|
||||||
|
|
||||||
|
} else if (type == 4) { //try to block off player
|
||||||
|
|
||||||
|
} else if (type == 5) { //retreat and not shoot
|
||||||
|
|
||||||
|
} else if (type == 6) { //blanket shot
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
iterationsOfType++;
|
||||||
|
|
||||||
|
/* string lastdir = "";
|
||||||
|
for (int i = 0; i < lastDirection.Count; i++) {
|
||||||
|
lastdir += lastDirection[i];
|
||||||
|
}
|
||||||
|
string lastmode = "";
|
||||||
|
for (int i = 0; i < lastMode.Count; i++) {
|
||||||
|
lastmode += lastMode[i];
|
||||||
|
}
|
||||||
|
Console.SetCursorPosition(0, 22);
|
||||||
|
Console.WriteLine("Last direction: " + lastdir);
|
||||||
|
Console.WriteLine("Last mode: " + lastmode);
|
||||||
|
Console.WriteLine("Iterations of mode: " + iterationsOfType); */
|
||||||
|
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getAItype(char[,] grid, int width,int uX, int uY) {
|
||||||
|
if (lastMode.Count > 1 && lastMode[lastMode.Count - 1] != lastMode[lastMode.Count - 2]) {
|
||||||
|
iterationsOfType = 0;
|
||||||
|
}
|
||||||
|
if (!lineOfSight) {
|
||||||
|
wonder(grid, width);
|
||||||
|
lastMode.Add(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
lastMode.Add(1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private char[,] wonder(char[,] grid, int width) {
|
||||||
|
if (iterationsOfType % 8 == 0) {
|
||||||
|
int shoot = rnd.Next(1, 5);
|
||||||
|
int move = rnd.Next(0, 2);
|
||||||
|
if (shoot == 1) {
|
||||||
|
grid[cX, cY + 1] = '▼';
|
||||||
|
}
|
||||||
|
if (move == 1) {
|
||||||
|
grid = moveLeft(grid, width);
|
||||||
|
} else {
|
||||||
|
grid = moveRight(grid, width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iterationsOfType++;
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
|
||||||
|
private char[,] moveLeft(char[,] grid, int width) {
|
||||||
|
if (cX - 1 > 0) {
|
||||||
|
lastDirection.Add(0);
|
||||||
|
grid[cX, cY] = ' ';
|
||||||
|
cX--;
|
||||||
|
grid[cX, cY] = '☻';
|
||||||
|
}
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
private char[,] moveRight(char[,] grid, int width) {
|
||||||
|
if (cX + 1 < width - 1) {
|
||||||
|
lastDirection.Add(1);
|
||||||
|
grid[cX, cY] = ' ';
|
||||||
|
cX++;
|
||||||
|
grid[cX, cY] = '☻';
|
||||||
|
}
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
lastDirection.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{C3742581-795D-4CC3-A0EE-8CDC818E7ECB}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<RootNamespace>ASCII_Showdown</RootNamespace>
|
||||||
|
<AssemblyName>ASCII Showdown</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="AIMove.cs" />
|
||||||
|
<Compile Include="Draw.cs" />
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="App.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
||||||
6
Console Games/Ascii Showdown/ASCII Showdown/App.config
Normal file
6
Console Games/Ascii Showdown/ASCII Showdown/App.config
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<startup>
|
||||||
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||||
|
</startup>
|
||||||
|
</configuration>
|
||||||
119
Console Games/Ascii Showdown/ASCII Showdown/Draw.cs
Normal file
119
Console Games/Ascii Showdown/ASCII Showdown/Draw.cs
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ASCII_Showdown {
|
||||||
|
class Draw {
|
||||||
|
public int width { get; set; }
|
||||||
|
public int height { get; set; }
|
||||||
|
public int indent { get; set; }
|
||||||
|
|
||||||
|
public void drawGrid(char[,] grid, int indent) {
|
||||||
|
try {
|
||||||
|
Console.SetCursorPosition(indent, indent - 3);
|
||||||
|
|
||||||
|
for (int j = 0; j < height; j++) {
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
if (grid[i, j] == '☺') {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
} else if (grid[i, j] == '☻') {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
} else {
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
}
|
||||||
|
Console.Write(grid[i, j]);
|
||||||
|
}
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.SetCursorPosition(indent, j + indent - 2);
|
||||||
|
}
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
public void drawStats(int chealth, int uhealth, int bullets, int walls, bool boost) {
|
||||||
|
try {
|
||||||
|
int drawX = width + indent + 10;
|
||||||
|
|
||||||
|
Console.SetCursorPosition(drawX, 6);
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
|
||||||
|
Console.WriteLine("╔════════════════╗");
|
||||||
|
Console.SetCursorPosition(drawX, 7);
|
||||||
|
if (chealth > 9) {
|
||||||
|
Console.WriteLine("║CPU healh: {0} ║", chealth);
|
||||||
|
} else {
|
||||||
|
Console.WriteLine("║CPU healh: {0} ║", chealth);
|
||||||
|
}
|
||||||
|
Console.SetCursorPosition(drawX, 8);
|
||||||
|
Console.WriteLine("╚════════════════╝");
|
||||||
|
|
||||||
|
Console.SetCursorPosition(drawX, 14);
|
||||||
|
Console.WriteLine("╔════════════════╗");
|
||||||
|
Console.SetCursorPosition(drawX, 15);
|
||||||
|
if (uhealth > 9) {
|
||||||
|
Console.WriteLine("║Health: {0} ║", uhealth);
|
||||||
|
} else {
|
||||||
|
Console.WriteLine("║Health: {0} ║", uhealth);
|
||||||
|
}
|
||||||
|
Console.SetCursorPosition(drawX, 16);
|
||||||
|
if (bullets > 99) {
|
||||||
|
Console.WriteLine("║Bullets: {0} ║", bullets);
|
||||||
|
} else if (bullets > 9) {
|
||||||
|
Console.WriteLine("║Bullets: {0} ║", bullets);
|
||||||
|
} else {
|
||||||
|
Console.WriteLine("║Bullets: {0} ║", bullets);
|
||||||
|
}
|
||||||
|
Console.SetCursorPosition(drawX, 17);
|
||||||
|
if (walls > 9) {
|
||||||
|
Console.WriteLine("║Walls: {0} ║", walls);
|
||||||
|
} else {
|
||||||
|
Console.WriteLine("║Walls: {0} ║", walls);
|
||||||
|
}
|
||||||
|
Console.SetCursorPosition(drawX, 18);
|
||||||
|
if (boost) {
|
||||||
|
Console.Write("║Boost: ");
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.Write("ON");
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
Console.Write(" ║");
|
||||||
|
Console.WriteLine();
|
||||||
|
} else {
|
||||||
|
Console.Write("║Boost: ");
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.Write("OFF");
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
Console.Write(" ║");
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
Console.SetCursorPosition(drawX, 19);
|
||||||
|
Console.WriteLine("╚════════════════╝");
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateGrid(char[,] grid, char[,] oldGrid, int indent) {
|
||||||
|
try {
|
||||||
|
for (int j = 0; j < height; j++) {
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
if (grid[i, j] != oldGrid[i, j]) {
|
||||||
|
if (grid[i, j] == '☺') {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
} else if (grid[i, j] == '☻') {
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
} else {
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
}
|
||||||
|
Console.SetCursorPosition(i + indent, j + indent - 3);
|
||||||
|
Console.Write(grid[i, j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateStats(int chealth, int uhealth, int bullets, int walls, bool boost) {
|
||||||
|
int drawX = width + indent + 10;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
389
Console Games/Ascii Showdown/ASCII Showdown/Program.cs
Normal file
389
Console Games/Ascii Showdown/ASCII Showdown/Program.cs
Normal file
@@ -0,0 +1,389 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace ASCII_Showdown {
|
||||||
|
class Program {
|
||||||
|
static void Main(string[] args) {
|
||||||
|
Console.OutputEncoding = Encoding.UTF8;
|
||||||
|
|
||||||
|
Console.CursorVisible = false;
|
||||||
|
Program start = new Program();
|
||||||
|
start.initializeGame();
|
||||||
|
Console.ReadKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Dictionary<Point, char> dic = new Dictionary<Point, char>();
|
||||||
|
|
||||||
|
Random rnd = new Random();
|
||||||
|
Draw draw = new Draw();
|
||||||
|
AIMove ai = new AIMove();
|
||||||
|
|
||||||
|
int uhealth = 10, chealth = 30, bullets = 500, walls = 20;
|
||||||
|
bool boost = false;
|
||||||
|
int boostime = 100, cooldown = 200, boostimeon = 0, cooldowntime = 200;
|
||||||
|
|
||||||
|
int width = 40;
|
||||||
|
int height = 20;
|
||||||
|
int indent = 5;
|
||||||
|
|
||||||
|
int uX;
|
||||||
|
int uY;
|
||||||
|
|
||||||
|
public int cX;
|
||||||
|
public int cY;
|
||||||
|
|
||||||
|
int WINNER = 0;
|
||||||
|
char[,] grid;
|
||||||
|
char[,] oldGrid;
|
||||||
|
static readonly string defaultGrid =
|
||||||
|
"████████████████████████████████████████" + // █: wall
|
||||||
|
"█ ☻ █" + // ☻: cpu
|
||||||
|
"█ █" + // ☺: user
|
||||||
|
"█ █" + // ▲: user's bullet
|
||||||
|
"█ █" + // ▼: cpu's bullet
|
||||||
|
"█ █" + //boomerang(array): boomerang
|
||||||
|
"█ █" + //wall(array): user's wall
|
||||||
|
"█ █" +
|
||||||
|
"█ █" +
|
||||||
|
"█ █" +
|
||||||
|
"█ █" +
|
||||||
|
"█ █" +
|
||||||
|
"█ █" +
|
||||||
|
"█ █" +
|
||||||
|
"█ █" +
|
||||||
|
"█ █" +
|
||||||
|
"█ █" +
|
||||||
|
"█ █" +
|
||||||
|
"█ ☺ █" +
|
||||||
|
"████████████████████████████████████████";
|
||||||
|
|
||||||
|
|
||||||
|
private void initializeGame() {
|
||||||
|
Console.Clear();
|
||||||
|
Console.SetWindowSize(80, 30);
|
||||||
|
|
||||||
|
ai.reset();
|
||||||
|
|
||||||
|
draw.width = width;
|
||||||
|
draw.height = height;
|
||||||
|
draw.indent = indent;
|
||||||
|
|
||||||
|
grid = new char[width, height];
|
||||||
|
|
||||||
|
bool boost = false;
|
||||||
|
|
||||||
|
grid = stringToArray(defaultGrid);
|
||||||
|
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
for (int j = 0; j < height; j++) {
|
||||||
|
if (grid[i, j] == '☺') {
|
||||||
|
uX = i;
|
||||||
|
uY = j;
|
||||||
|
} else if (grid[i, j] == '☻') {
|
||||||
|
cX = i;
|
||||||
|
cY = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("The game has successfully loaded!");
|
||||||
|
Console.WriteLine("To play:");
|
||||||
|
Console.WriteLine("W or up arrow to shoot");
|
||||||
|
Console.WriteLine("A or left arrow to move left");
|
||||||
|
Console.WriteLine("D or right arrow to move right");
|
||||||
|
Console.WriteLine("O to use your boost powerup this will only last for 5 seconds with a 10 second cooldown");
|
||||||
|
Console.WriteLine("P to place a wall this will only be able to survive 4 enemy or freindly shots before breaking");
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine("Press any key to continue...");
|
||||||
|
Console.ReadKey();
|
||||||
|
Console.Clear();
|
||||||
|
|
||||||
|
draw.drawGrid(grid, indent);
|
||||||
|
draw.drawStats(chealth, uhealth, bullets, walls, boost);
|
||||||
|
gameLoop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void gameLoop() {
|
||||||
|
while (WINNER == 0) {
|
||||||
|
oldGrid = getOldGrid(grid);
|
||||||
|
|
||||||
|
if (boost) {
|
||||||
|
boostimeon++;
|
||||||
|
if (boostimeon == boostime) {
|
||||||
|
boost = false;
|
||||||
|
boostimeon = 0;
|
||||||
|
cooldown = 0;
|
||||||
|
}
|
||||||
|
} else if (cooldown < cooldowntime) {
|
||||||
|
cooldown++;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ConsoleKeyInfo> keys = new List<ConsoleKeyInfo>();
|
||||||
|
while (Console.KeyAvailable) {
|
||||||
|
var key = Console.ReadKey(true);
|
||||||
|
keys.Add(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
moveColideandStuff();
|
||||||
|
|
||||||
|
ai.cX = cX;
|
||||||
|
ai.cY = cY;
|
||||||
|
grid = ai.moveCPU(grid, width, uX, uY);
|
||||||
|
cX = ai.cX;
|
||||||
|
cY = ai.cY;
|
||||||
|
|
||||||
|
keyPressed(keys);
|
||||||
|
|
||||||
|
//game logic calls
|
||||||
|
|
||||||
|
if (bullets == 0 || uhealth == 0) {
|
||||||
|
WINNER = 2;
|
||||||
|
break;
|
||||||
|
} else if (chealth == 0) {
|
||||||
|
WINNER = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckAndResetWindowSize();
|
||||||
|
draw.updateGrid(grid, oldGrid, indent);
|
||||||
|
draw.drawStats(chealth, uhealth, bullets, walls, boost);
|
||||||
|
Thread.Sleep(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
uhealth = 10;
|
||||||
|
chealth = 40;
|
||||||
|
bullets = 500;
|
||||||
|
walls = 20;
|
||||||
|
WINNER = 0;
|
||||||
|
|
||||||
|
if (WINNER == 1) {
|
||||||
|
Console.Clear();
|
||||||
|
Console.WriteLine("You win!");
|
||||||
|
Console.WriteLine("Press any key to continue");
|
||||||
|
Console.ReadKey();
|
||||||
|
initializeGame();
|
||||||
|
} else {
|
||||||
|
Console.Clear();
|
||||||
|
Console.WriteLine("You loose :(");
|
||||||
|
Console.WriteLine("Press any key to continue");
|
||||||
|
Console.ReadKey();
|
||||||
|
initializeGame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void keyPressed(List<ConsoleKeyInfo> keys) {
|
||||||
|
try {
|
||||||
|
if (keys.Count >= 1) {
|
||||||
|
var key = keys[keys.Count - 1];
|
||||||
|
|
||||||
|
switch (key.KeyChar) {
|
||||||
|
case 'W':
|
||||||
|
case 'w':
|
||||||
|
if (boost) {
|
||||||
|
grid[uX - 1, uY - 1] = '▲';
|
||||||
|
grid[uX, uY - 1] = '▲';
|
||||||
|
grid[uX + 1, uY - 1] = '▲';
|
||||||
|
bullets += -3;
|
||||||
|
} else {
|
||||||
|
grid[uX, uY - 1] = '▲';
|
||||||
|
bullets--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
|
case 'd':
|
||||||
|
if (uX + 1 < width - 1) {
|
||||||
|
grid[uX, uY] = ' ';
|
||||||
|
grid[uX + 1, uY] = '☺';
|
||||||
|
uX++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'A':
|
||||||
|
case 'a':
|
||||||
|
if (uX - 1 > 0) {
|
||||||
|
grid[uX, uY] = ' ';
|
||||||
|
grid[uX - 1, uY] = '☺';
|
||||||
|
uX--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'P':
|
||||||
|
case 'p':
|
||||||
|
if (walls > 0 && grid[uX, uY - 2] != '█') {
|
||||||
|
grid[uX, uY - 2] = '█';
|
||||||
|
walls--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'O':
|
||||||
|
case 'o':
|
||||||
|
if (boost) {
|
||||||
|
boost = false;
|
||||||
|
boostimeon = 0;
|
||||||
|
} else if (!boost && cooldown == cooldowntime) {
|
||||||
|
cooldown = 0;
|
||||||
|
boost = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (key.Key) {
|
||||||
|
case ConsoleKey.UpArrow:
|
||||||
|
if (boost) {
|
||||||
|
grid[uX - 1, uY - 1] = '▲';
|
||||||
|
grid[uX, uY - 1] = '▲';
|
||||||
|
grid[uX + 1, uY - 1] = '▲';
|
||||||
|
bullets += -3;
|
||||||
|
} else {
|
||||||
|
grid[uX, uY - 1] = '▲';
|
||||||
|
bullets--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ConsoleKey.RightArrow:
|
||||||
|
if (uX + 1 < width - 1) {
|
||||||
|
grid[uX, uY] = ' ';
|
||||||
|
grid[uX + 1, uY] = '☺';
|
||||||
|
uX++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ConsoleKey.LeftArrow:
|
||||||
|
if (uX - 1 > 0) {
|
||||||
|
grid[uX, uY] = ' ';
|
||||||
|
grid[uX - 1, uY] = '☺';
|
||||||
|
uX--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ConsoleKey.Spacebar:
|
||||||
|
if (boost) {
|
||||||
|
grid[uX - 1, uY - 1] = '▲';
|
||||||
|
grid[uX, uY - 1] = '▲';
|
||||||
|
grid[uX + 1, uY - 1] = '▲';
|
||||||
|
bullets += -3;
|
||||||
|
} else {
|
||||||
|
grid[uX, uY - 1] = '▲';
|
||||||
|
bullets--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void moveColideandStuff() {
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
for (int j = 0; j < height; j++) {
|
||||||
|
if (grid[i, j] == '▲') { //if the target is a user bullet
|
||||||
|
if (j > 1) { //if the target is not on a border
|
||||||
|
if (grid[i, j - 1] == '█' && j > 1) { //if the target has hit a wall which isnt the border, damage wall
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
grid[i, j - 1] = '▓';
|
||||||
|
} else if (grid[i, j - 1] == '▓') { //wall dameging
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
grid[i, j - 1] = '▒';
|
||||||
|
} else if (grid[i, j - 1] == '▒') {
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
grid[i, j - 1] = '░';
|
||||||
|
} else if (grid[i, j - 1] == '░') {
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
grid[i, j - 1] = '*';
|
||||||
|
} else if (grid[i, j - 1] == '☻') { //if the target has hit the CPU
|
||||||
|
chealth--;
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
flashScreenEnemyHit();
|
||||||
|
} else { //if else, move forward
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
grid[i, j - 1] = '▲';
|
||||||
|
}
|
||||||
|
} else { //if the target is on a wall, destroy it
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
}
|
||||||
|
} else if (grid[i, j] == '▼') { //if the target is a CPU bullet
|
||||||
|
if (j < height - 2) { //if the target is not on a lower border
|
||||||
|
if (grid[i, j + 1] == '█' && j > 1) { //if the target has hit a wall which isnt the border, damage wall
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
grid[i, j + 1] = '▓';
|
||||||
|
} else if (grid[i, j + 1] == '▓') { //wall dameging
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
grid[i, j + 1] = '▒';
|
||||||
|
} else if (grid[i, j + 1] == '▒') {
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
grid[i, j + 1] = '░';
|
||||||
|
} else if (grid[i, j + 1] == '░') {
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
grid[i, j + 1] = '*';
|
||||||
|
} else if (grid[i, j + 1] == '☺') { //if the target has hit the user
|
||||||
|
uhealth--;
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
flashScreenPlayerHit();
|
||||||
|
} else { //if else, move forward
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
grid[i, j + 1] = 'v';
|
||||||
|
}
|
||||||
|
} else { //if the target is on a wall, destroy it
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
}
|
||||||
|
} else if (grid[i, j] == '*') { //if its an explosion, delete it
|
||||||
|
grid[i, j] = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
for (int j = 0; j < height; j++) {
|
||||||
|
if (grid[i, j] == 'v') {
|
||||||
|
grid[i, j] = '▼';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private char[,] stringToArray(string toload) {
|
||||||
|
for (int i = 0; i < height; i++) {
|
||||||
|
for (int j = 0; j < width; j++) {
|
||||||
|
grid[j, i] = toload[i * width + j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return grid;
|
||||||
|
}
|
||||||
|
|
||||||
|
private char[,] getOldGrid(char[,] currentGrid) {
|
||||||
|
char[,] oldGrid = new char[width, height];
|
||||||
|
for (int i = 0; i < width; i++) {
|
||||||
|
for (int j = 0; j < height; j++) {
|
||||||
|
oldGrid[i, j] = currentGrid[i, j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return oldGrid;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void flashScreenEnemyHit() {
|
||||||
|
Console.Clear();
|
||||||
|
Console.BackgroundColor = ConsoleColor.Red;
|
||||||
|
Console.Clear();
|
||||||
|
Console.BackgroundColor = ConsoleColor.Black;
|
||||||
|
Console.Clear();
|
||||||
|
draw.drawGrid(grid, indent);
|
||||||
|
draw.drawStats(chealth, uhealth, bullets, walls, boost);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void flashScreenPlayerHit() {
|
||||||
|
Console.Clear();
|
||||||
|
Console.BackgroundColor = ConsoleColor.Green;
|
||||||
|
Console.Clear();
|
||||||
|
Console.BackgroundColor = ConsoleColor.Black;
|
||||||
|
Console.Clear();
|
||||||
|
draw.drawGrid(grid, indent);
|
||||||
|
draw.drawStats(chealth, uhealth, bullets, walls, boost);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckAndResetWindowSize() {
|
||||||
|
try {
|
||||||
|
if (Console.WindowWidth != 80 || Console.WindowHeight != 30) {
|
||||||
|
Console.SetWindowSize(80, 30);
|
||||||
|
Console.Clear();
|
||||||
|
draw.drawGrid(grid, indent);
|
||||||
|
draw.drawStats(chealth, uhealth, bullets, walls, boost);
|
||||||
|
}
|
||||||
|
} catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("ASCII Showdown")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("ASCII Showdown")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("c3742581-795d-4cc3-a0ee-8cdc818e7ecb")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
BIN
Console Games/Ascii Showdown/special charicters.txt
Normal file
BIN
Console Games/Ascii Showdown/special charicters.txt
Normal file
Binary file not shown.
Reference in New Issue
Block a user