Skip to content

Instantly share code, notes, and snippets.

@Zolomon
Created October 1, 2010 08:04
Show Gist options
  • Select an option

  • Save Zolomon/605904 to your computer and use it in GitHub Desktop.

Select an option

Save Zolomon/605904 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace WhyFight
{
class Program
{
private static Thread _horizontalThread;
private static Thread _verticalThread;
private static Thread _animateThread;
private static Thread _stopThread;
private static int WIDTH = 80;
private static int HEIGHT = 25;
private static string speakRight = @" \| ";
private static string speakLeft = @" |/ ";
private static string head = @"-O O-";
private static string torsoAttack = @" |-\/-| ";
private static string torsoParry = @" |-/\-| ";
private static string legsBackward = @" |\ |\ ";
private static string legsForward = @" /| /| ";
private static int x = 20;
private static int y = 5;
private static bool goingLeft = false;
private static bool goingUp = false;
private static string xSpace = "";
static void Main(string[] args)
{
_horizontalThread = new Thread(MoveX);
_horizontalThread.Start();
_verticalThread = new Thread(MoveY);
_verticalThread.Start();
_stopThread = new Thread(StopFight);
_stopThread.Start();
_animateThread = new Thread(Animate);
_animateThread.Start();
}
private static void CreateBubble(string text, string position)
{
SetColor(ConsoleColor.Black, ConsoleColor.Yellow);
string line = "";
for (int i = 0; i < text.Length + 6; i++)
{
line += "-";
}
Console.WriteLine(String.Format("{0},{1}.", xSpace, line));
Console.WriteLine(String.Format("{0}| {1} |", xSpace, text));
Console.WriteLine(String.Format("{0}`{1}´", xSpace, line.Remove(1,2).Insert(1," ")));
Console.WriteLine(String.Format("{0}{1}", xSpace, position));
ResetColor();
}
private static void Animate()
{
while (true)
{
WIDTH = Console.WindowWidth;
HEIGHT = Console.WindowHeight;
PrintBackAttack();
Thread.Sleep(50);
Console.Clear();
PrintBackParry();
Thread.Sleep(50);
Console.Clear();
PrintForwardAttack();
Thread.Sleep(50);
Console.Clear();
PrintForwardParry();
Thread.Sleep(50);
Console.Clear();
}
}
private static void StopFight()
{
while (true)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo cki = Console.ReadKey(true);
if (cki.Key == ConsoleKey.Enter)
{
_verticalThread.Abort();
_horizontalThread.Abort();
}
}
}
}
private static void MoveX()
{
while (true)
{
if (goingLeft)
{
x--;
if (x <= WIDTH * 0.1f)
goingLeft = false;
}
else
{
x++;
if (x >= WIDTH * 0.8f)
goingLeft = true;
}
xSpace = "";
for (int i = 0; i < x; i++)
{
xSpace += " ";
}
Console.Title = xSpace.Length.ToString();
Thread.Sleep(100);
}
}
private static void MoveY()
{
while (true)
{
if (goingUp)
{
y--;
if (y <= HEIGHT * 0.2f)
goingUp = false;
}
else
{
y++;
if (y >= HEIGHT * 0.8f)
goingUp = true;
}
Thread.Sleep(100);
}
}
private static void Draw(string head, string torso, string legs)
{
for (int i = 0; i < y; i++)
{
Console.WriteLine();
}
CreateBubble("You bastard!", speakLeft);
Console.WriteLine(String.Format("{0}{1}", xSpace, head));
Console.WriteLine(String.Format("{0}{1}", xSpace, torso));
Console.WriteLine(String.Format("{0}{1}", xSpace, legs));
}
private static void PrintBackAttack()
{
Draw(head, torsoAttack, legsBackward);
}
private static void PrintBackParry()
{
Draw(head, torsoParry, legsBackward);
}
private static void PrintForwardAttack()
{
Draw(head, torsoAttack, legsForward);
}
private static void PrintForwardParry()
{
Draw(head, torsoParry, legsForward);
}
private static void SetColor(ConsoleColor backgroundColor, ConsoleColor foregroundColor)
{
Console.BackgroundColor = backgroundColor;
Console.ForegroundColor = foregroundColor;
}
private static void ResetColor()
{
Console.ResetColor();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment