557 lines
18 KiB
C#
557 lines
18 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading;
|
|||
|
|
|||
|
namespace RollerWheel
|
|||
|
{
|
|||
|
class Program
|
|||
|
{
|
|||
|
static string[] gapChars = new string[] { " |##############|", " |--------------|" };
|
|||
|
static string[] rollers = new string[] {
|
|||
|
" |##############|", " |### ##|", " |########## ##|", " |### ##|", " |### #########|", " |### ##|", // Two
|
|||
|
" |##############|", " |### ##|", " |########## ##|", " |### ##|", " |########## ##|", " |### ##|", // Three
|
|||
|
" |##############|", " |### ##### ##|", " |### ##### ##|", " |### ##|", " |########## ##|", " |########## ##|", // Four
|
|||
|
" |##############|", " |### ##|", " |### #########|", " |### ##|", " |########## ##|", " |### ##|", // Five
|
|||
|
" |##############|", " |### ##|", " |### #########|", " |### ##|", " |### ##### ##|", " |### ##|", // Six
|
|||
|
" |##############|", " |#### ###|", " |######## ####|", " |####### #####|", " |###### ######|", " |##### #######|" }; // Seven
|
|||
|
static int[] titleBools = new int[] {
|
|||
|
1,0,0,0,0,0,0,1,1, // First Line
|
|||
|
1,0,0,1,1,1,1,1,1,
|
|||
|
1,0,0,0,0,0,0,0,1,
|
|||
|
1,0,0,0,0,0,0,0,1,
|
|||
|
1,0,0,0,0,0,0,0,1,2,
|
|||
|
|
|||
|
1,0,0,1,1,1,1,1,1, // Second Line
|
|||
|
1,0,0,1,1,1,1,1,1,
|
|||
|
1,0,0,1,1,1,0,0,1,
|
|||
|
1,1,1,1,0,0,1,1,1,
|
|||
|
1,0,0,1,1,1,1,1,1,2,
|
|||
|
|
|||
|
1,0,0,0,0,0,0,0,1, // Third Line
|
|||
|
1,0,0,1,1,1,1,1,1,
|
|||
|
1,0,0,1,1,1,0,0,1,
|
|||
|
1,1,1,1,0,0,1,1,1,
|
|||
|
1,0,0,0,0,0,0,0,1,2,
|
|||
|
|
|||
|
1,1,1,1,1,1,0,0,1, // Fourth Line
|
|||
|
1,0,0,1,1,1,1,1,1,
|
|||
|
1,0,0,1,1,1,0,0,1,
|
|||
|
1,1,1,1,0,0,1,1,1,
|
|||
|
1,1,1,1,1,1,0,0,1,2,
|
|||
|
|
|||
|
1,0,0,0,0,0,0,0,1, // Fith Line
|
|||
|
1,0,0,0,0,0,0,1,1,
|
|||
|
1,0,0,0,0,0,0,0,1,
|
|||
|
1,1,1,1,0,0,1,1,1,
|
|||
|
1,0,0,0,0,0,0,0,1,2,
|
|||
|
};
|
|||
|
#if DEBUG
|
|||
|
static bool verbose = false;
|
|||
|
#endif
|
|||
|
static bool drawTitle()
|
|||
|
{
|
|||
|
#if DEBUG
|
|||
|
if (!verbose)
|
|||
|
{
|
|||
|
|
|||
|
#endif
|
|||
|
Console.Clear();
|
|||
|
#if DEBUG
|
|||
|
}
|
|||
|
#endif
|
|||
|
#if DEBUG
|
|||
|
Console.BackgroundColor = ConsoleColor.Red;
|
|||
|
#else
|
|||
|
Console.BackgroundColor = ConsoleColor.Green;
|
|||
|
#endif
|
|||
|
string writeString = "";
|
|||
|
for (int r = 0; r < 45; r++)
|
|||
|
{
|
|||
|
writeString += " ";
|
|||
|
}
|
|||
|
Console.WriteLine(writeString);
|
|||
|
for (int i = 0; i < titleBools.Length; i++)
|
|||
|
{
|
|||
|
if (titleBools[i] == 2)
|
|||
|
{
|
|||
|
Console.Write(Environment.NewLine);
|
|||
|
}
|
|||
|
if (titleBools[i] == 1)
|
|||
|
{
|
|||
|
switch (Console.BackgroundColor)
|
|||
|
{
|
|||
|
case ConsoleColor.Green:
|
|||
|
Console.Write(" ");
|
|||
|
break;
|
|||
|
case ConsoleColor.Black:
|
|||
|
Console.BackgroundColor = ConsoleColor.Green;
|
|||
|
#if DEBUG
|
|||
|
Console.BackgroundColor = ConsoleColor.Red;
|
|||
|
#endif
|
|||
|
Console.Write(" ");
|
|||
|
break;
|
|||
|
#if DEBUG
|
|||
|
case ConsoleColor.Red:
|
|||
|
Console.Write(" ");
|
|||
|
break;
|
|||
|
#endif
|
|||
|
}
|
|||
|
}
|
|||
|
else if (titleBools[i] != 2)
|
|||
|
{
|
|||
|
switch (Console.BackgroundColor)
|
|||
|
{
|
|||
|
case ConsoleColor.Black:
|
|||
|
Console.Write(" ");
|
|||
|
break;
|
|||
|
case ConsoleColor.Green:
|
|||
|
|
|||
|
Console.BackgroundColor = ConsoleColor.Black;
|
|||
|
Console.Write(" ");
|
|||
|
break;
|
|||
|
#if DEBUG
|
|||
|
case ConsoleColor.Red:
|
|||
|
Console.BackgroundColor = ConsoleColor.Black;
|
|||
|
Console.Write(" ");
|
|||
|
break;
|
|||
|
#endif
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
Console.WriteLine(writeString);
|
|||
|
Console.ResetColor();
|
|||
|
#if DEBUG
|
|||
|
Console.ForegroundColor = ConsoleColor.DarkRed;
|
|||
|
Console.WriteLine("DEBUG VERSION ! DEBUG VERSION ! DEBUG VERSION");
|
|||
|
#else
|
|||
|
Console.ForegroundColor = ConsoleColor.DarkGreen;
|
|||
|
#endif
|
|||
|
Console.WriteLine("Slots! A command prompt-based game!");
|
|||
|
Console.WriteLine("Written in C# by Brychan Dempsey");
|
|||
|
Console.WriteLine("");
|
|||
|
drawCommands();
|
|||
|
return true;
|
|||
|
}
|
|||
|
static bool drawCommands()
|
|||
|
{
|
|||
|
Console.ForegroundColor = ConsoleColor.White;
|
|||
|
Console.Write("Press ");
|
|||
|
Console.ForegroundColor = ConsoleColor.Red;
|
|||
|
Console.Write("\'b\'");
|
|||
|
Console.ForegroundColor = ConsoleColor.White;
|
|||
|
Console.Write(" to begin, ");
|
|||
|
Console.ForegroundColor = ConsoleColor.Red;
|
|||
|
Console.Write("\'Esc\'");
|
|||
|
Console.ForegroundColor = ConsoleColor.White;
|
|||
|
Console.WriteLine(" to cancel.");
|
|||
|
Console.Write("Pressing ");
|
|||
|
Console.ForegroundColor = ConsoleColor.Red;
|
|||
|
Console.Write("Spacebar");
|
|||
|
Console.ForegroundColor = ConsoleColor.White;
|
|||
|
Console.WriteLine(" at any point will stop the rollers");
|
|||
|
return true;
|
|||
|
}
|
|||
|
// Character ranges are 0-5, 6-11, 12-17, 18-23, 24-29, 30-35
|
|||
|
static void Main(string[] args)
|
|||
|
{
|
|||
|
ConsoleKeyInfo readKey;
|
|||
|
#if DEBUG
|
|||
|
if(args.Length > 0)
|
|||
|
{
|
|||
|
if (args[0] == "-v")
|
|||
|
{
|
|||
|
verbose = true;
|
|||
|
}
|
|||
|
}
|
|||
|
Console.Title = "Slots! - a C# game by Brychan Dempsey - DEBUG VERSION";
|
|||
|
#else
|
|||
|
Console.Title = "Slots! - a C# game by Brychan Dempsey";
|
|||
|
#endif
|
|||
|
drawTitle();
|
|||
|
redrawnCommands:
|
|||
|
#if DEBUG
|
|||
|
|
|||
|
if (!verbose)
|
|||
|
{
|
|||
|
#endif
|
|||
|
readKey = Console.ReadKey();
|
|||
|
if (readKey.Key == ConsoleKey.B)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
else if (readKey.Key == ConsoleKey.Escape)
|
|||
|
{
|
|||
|
Environment.Exit(0);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Console.WriteLine("Invalid command. Try again:");
|
|||
|
drawCommands();
|
|||
|
goto redrawnCommands;
|
|||
|
}
|
|||
|
#if DEBUG
|
|||
|
}
|
|||
|
#endif
|
|||
|
Thread thread1 = new Thread(new ThreadStart(readingKey));
|
|||
|
thread1.Start();
|
|||
|
|
|||
|
if (doRoller())
|
|||
|
{
|
|||
|
Console.ResetColor();
|
|||
|
Console.WriteLine("Success!");
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Console.WriteLine("Something Went Wrong!");
|
|||
|
}
|
|||
|
int finalone = 0;
|
|||
|
int finaltwo = 0;
|
|||
|
int finalthree = 0;
|
|||
|
if (finalindexone + 9 < rollers.Length)
|
|||
|
{
|
|||
|
finalone = (finalindexone + 9) / 6 + 2;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
finalone = ((finalindexone + 9) - rollers.Length) / 6 + 2;
|
|||
|
}
|
|||
|
if (finalindextwo + 9 < rollers.Length)
|
|||
|
{
|
|||
|
finaltwo = (finalindextwo + 9) / 6 + 2;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
finaltwo = ((finalindextwo + 9) - rollers.Length) / 6 + 2;
|
|||
|
}
|
|||
|
if (finalindexthree + 9 < rollers.Length)
|
|||
|
{
|
|||
|
finalthree = (finalindexthree + 9) / 6 + 2;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
finalthree = ((finalindexthree + 9) - rollers.Length) / 6 + 2;
|
|||
|
}
|
|||
|
Console.WriteLine("Final numbers are: {0} {1} {2}", finalone, finaltwo, finalthree);
|
|||
|
#if DEBUG
|
|||
|
Console.WriteLine("Final numbers are: {0} {1} {2}", finalindexone, finalindextwo, finalindexthree);
|
|||
|
Console.WriteLine("Final numbers are: {0} {1} {2}", (finalindexone + 9)/6, (finalindextwo + 9)/6, (finalindexthree+9)/6);
|
|||
|
#endif
|
|||
|
finalExitPrompt:
|
|||
|
readKey = Console.ReadKey();
|
|||
|
if (readKey.Key == ConsoleKey.Escape)
|
|||
|
{
|
|||
|
Environment.Exit(0);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
goto finalExitPrompt;
|
|||
|
}
|
|||
|
}
|
|||
|
public static void readingKey()
|
|||
|
{
|
|||
|
|
|||
|
while (!threelocked)
|
|||
|
{
|
|||
|
ConsoleKeyInfo readKey = Console.ReadKey();
|
|||
|
if (readKey.Key == ConsoleKey.Spacebar)
|
|||
|
{
|
|||
|
Console.Beep();
|
|||
|
Random rand = new Random();
|
|||
|
//int wait = rand.Next() / 5000000;
|
|||
|
// Thread.Sleep(wait);
|
|||
|
if (onelocked)
|
|||
|
{
|
|||
|
if (twolocked)
|
|||
|
{
|
|||
|
finalindexthree = rollerthreeIndex;
|
|||
|
#if DEBUG
|
|||
|
Console.Write(finalindexthree);
|
|||
|
#endif
|
|||
|
threelocked = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
finalindextwo = rollertwoIndex;
|
|||
|
twolocked = true;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
finalindexone = rolleroneIndex;
|
|||
|
onelocked = true;
|
|||
|
}
|
|||
|
}
|
|||
|
//Thread.Sleep(300);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
static void clearScreen()
|
|||
|
{
|
|||
|
#if DEBUG
|
|||
|
if (!verbose)
|
|||
|
{
|
|||
|
#endif
|
|||
|
Console.SetCursorPosition(0, 0);
|
|||
|
#if DEBUG
|
|||
|
}
|
|||
|
#endif
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Begins rolling the rollers
|
|||
|
/// </summary>
|
|||
|
/// <returns>true if rolling was successful</returns>
|
|||
|
static bool doRoller()
|
|||
|
{
|
|||
|
int firstStarting = 7;
|
|||
|
int secondStarting = 7;
|
|||
|
int thirdStarting = 7;
|
|||
|
|
|||
|
drawDisplay(firstStarting, secondStarting, thirdStarting);
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
static int rolleroneIndex = 0;
|
|||
|
static int rollertwoIndex = 0;
|
|||
|
static int rollerthreeIndex = 0;
|
|||
|
|
|||
|
static int finalindexone = 0;
|
|||
|
static int finalindextwo = 0;
|
|||
|
static int finalindexthree = 0;
|
|||
|
|
|||
|
static bool onelocked = false;
|
|||
|
static bool twolocked = false;
|
|||
|
static bool threelocked = false;
|
|||
|
/// <summary>
|
|||
|
/// Draws the display using the numbers provided
|
|||
|
/// </summary>
|
|||
|
/// <param name="startone">number for the first roller</param>
|
|||
|
/// <param name="starttwo">number for the second roller</param>
|
|||
|
/// <param name="startthree">number for the third roller</param>
|
|||
|
/// <returns>Returns true if successfull</returns>
|
|||
|
static bool drawDisplay(int startone, int starttwo, int startthree)
|
|||
|
{
|
|||
|
createString(startone, starttwo, startthree);
|
|||
|
//for (int r = 0; r < 10000; r++)
|
|||
|
while(!threelocked)
|
|||
|
{
|
|||
|
if (onelocked)
|
|||
|
{
|
|||
|
rolleroneIndex = finalindexone;
|
|||
|
}
|
|||
|
if (twolocked)
|
|||
|
{
|
|||
|
rollertwoIndex = finalindextwo;
|
|||
|
}
|
|||
|
if (threelocked)
|
|||
|
{
|
|||
|
rollerthreeIndex = finalindexthree;
|
|||
|
|
|||
|
}
|
|||
|
clearScreen();
|
|||
|
for (int i = 0; i < 20; i++)
|
|||
|
{
|
|||
|
if (i < 3 || i > 15)
|
|||
|
{
|
|||
|
Console.ForegroundColor = ConsoleColor.DarkGray;
|
|||
|
}
|
|||
|
else if (i < 6 || i > 11)
|
|||
|
{
|
|||
|
Console.ForegroundColor = ConsoleColor.Gray;
|
|||
|
}
|
|||
|
else if (i > 5 && i < 12)
|
|||
|
{
|
|||
|
Console.ForegroundColor = ConsoleColor.White;
|
|||
|
}
|
|||
|
|
|||
|
if (i == 0 || i == 19)
|
|||
|
{
|
|||
|
Console.WriteLine("\t" + gapChars[1] + gapChars[1] + gapChars[1]);
|
|||
|
}
|
|||
|
if ((rolleroneIndex + i) == rollers.Length)
|
|||
|
{
|
|||
|
rolleroneIndex = 0 - i;
|
|||
|
}
|
|||
|
if ((rollertwoIndex + i) == rollers.Length)
|
|||
|
{
|
|||
|
rollertwoIndex = 0 - i;
|
|||
|
}
|
|||
|
if ((rollerthreeIndex + i) == rollers.Length)
|
|||
|
{
|
|||
|
rollerthreeIndex = 0 - i;
|
|||
|
}
|
|||
|
if (i > 0 && i < 19)
|
|||
|
{
|
|||
|
if (i == 10)
|
|||
|
{
|
|||
|
Console.ForegroundColor = ConsoleColor.DarkGray;
|
|||
|
#if DEBUG
|
|||
|
int currentPos = Console.CursorTop;
|
|||
|
Console.WriteLine("--------" + spinFirst(i) + spinSecond(i) + spinThird(i) + "--------\t\t\t");
|
|||
|
if (!verbose)
|
|||
|
{
|
|||
|
Console.SetCursorPosition(0, currentPos);
|
|||
|
Console.WriteLine("--------" + spinFirst(i) + spinSecond(i) + spinThird(i) + "-------- {0} {1} {2}", rolleroneIndex, rollertwoIndex, rollerthreeIndex);
|
|||
|
}
|
|||
|
|
|||
|
#else
|
|||
|
|
|||
|
Console.WriteLine("--------" + spinFirst(i) + spinSecond(i) + spinThird(i) + "--------");
|
|||
|
#endif
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Console.WriteLine("\t" + spinFirst(i) + spinSecond(i) + spinThird(i));
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
if (rolleroneIndex < 0)
|
|||
|
{
|
|||
|
rolleroneIndex = rollers.Length + rolleroneIndex;
|
|||
|
}
|
|||
|
if (rollertwoIndex < 0)
|
|||
|
{
|
|||
|
rollertwoIndex = rollers.Length + rollertwoIndex;
|
|||
|
}
|
|||
|
if (rollerthreeIndex < 0)
|
|||
|
{
|
|||
|
rollerthreeIndex = rollers.Length + rollerthreeIndex;
|
|||
|
}
|
|||
|
int currentPos2 = Console.CursorTop;
|
|||
|
#if DEBUG
|
|||
|
|
|||
|
if (!verbose)
|
|||
|
{
|
|||
|
Console.WriteLine("--------\t\t\t");
|
|||
|
Console.SetCursorPosition(0, currentPos2);
|
|||
|
Console.WriteLine("-------- {0} {1} {2}", rolleroneIndex, rollertwoIndex, rollerthreeIndex);
|
|||
|
}
|
|||
|
|
|||
|
#endif
|
|||
|
|
|||
|
rolleroneIndex += 1;
|
|||
|
rollertwoIndex += 1;
|
|||
|
rollerthreeIndex += 1;
|
|||
|
#if DEBUG
|
|||
|
Thread.Sleep(500);
|
|||
|
#else
|
|||
|
Thread.Sleep(5);
|
|||
|
#endif
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
static string spinFirst(int i)
|
|||
|
{
|
|||
|
if (onelocked)
|
|||
|
{
|
|||
|
return rollers[rolleroneIndex + i];
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return rollers[rolleroneIndex + i];
|
|||
|
}
|
|||
|
}
|
|||
|
static string spinSecond(int i)
|
|||
|
{
|
|||
|
if (twolocked)
|
|||
|
{
|
|||
|
return rollers[rollertwoIndex + i];
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return rollers[rollertwoIndex + i];
|
|||
|
}
|
|||
|
}
|
|||
|
static string spinThird(int i)
|
|||
|
{
|
|||
|
if (threelocked)
|
|||
|
{
|
|||
|
return rollers[rollerthreeIndex + i];
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return rollers[rollerthreeIndex + i];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
static void createString(int firstnumber, int secondnumber, int thirdnumber)
|
|||
|
{
|
|||
|
switch (firstnumber)
|
|||
|
{
|
|||
|
case 2:
|
|||
|
rolleroneIndex = 0;
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
rolleroneIndex = 6;
|
|||
|
break;
|
|||
|
case 4:
|
|||
|
rolleroneIndex = 12;
|
|||
|
break;
|
|||
|
case 5:
|
|||
|
rolleroneIndex = 18;
|
|||
|
break;
|
|||
|
case 6:
|
|||
|
rolleroneIndex = 24;
|
|||
|
break;
|
|||
|
case 7:
|
|||
|
rolleroneIndex = 30;
|
|||
|
break;
|
|||
|
}
|
|||
|
switch (secondnumber)
|
|||
|
{
|
|||
|
case 2:
|
|||
|
rollertwoIndex = 0;
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
rollertwoIndex = 6;
|
|||
|
break;
|
|||
|
case 4:
|
|||
|
rollertwoIndex = 12;
|
|||
|
break;
|
|||
|
case 5:
|
|||
|
rollertwoIndex = 18;
|
|||
|
break;
|
|||
|
case 6:
|
|||
|
rollertwoIndex = 24;
|
|||
|
break;
|
|||
|
case 7:
|
|||
|
rollertwoIndex = 30;
|
|||
|
break;
|
|||
|
}
|
|||
|
switch (thirdnumber)
|
|||
|
{
|
|||
|
case 2:
|
|||
|
rollerthreeIndex = 0;
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
rollerthreeIndex = 6;
|
|||
|
break;
|
|||
|
case 4:
|
|||
|
rollerthreeIndex = 12;
|
|||
|
break;
|
|||
|
case 5:
|
|||
|
rollerthreeIndex = 18;
|
|||
|
break;
|
|||
|
case 6:
|
|||
|
rollerthreeIndex = 24;
|
|||
|
break;
|
|||
|
case 7:
|
|||
|
rollerthreeIndex = 30;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|