Last active
August 29, 2015 14:11
-
-
Save pahaz/0283a97460d329eace15 to your computer and use it in GitHub Desktop.
Simple clicker game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace ClickerGame | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.Title = "Simple clicker game"; | |
int x = 17, y = 0; | |
int width = 36, height = 25; | |
DateTime beginWait = DateTime.Now; | |
ConsoleKeyInfo keyPressed; | |
int[][] img; | |
while (true) | |
{ | |
img = makeFill(width, height, 1); | |
img[x][y] = 4; | |
Console.Clear(); | |
draw(img); | |
Console.SetCursorPosition(0, 0); | |
if (Console.KeyAvailable) | |
{ | |
keyPressed = Console.ReadKey(); | |
if (keyPressed.Key == ConsoleKey.LeftArrow) | |
{ | |
x -= 1; | |
} | |
else if (keyPressed.Key == ConsoleKey.RightArrow) | |
{ | |
x += 1; | |
} | |
else if (keyPressed.Key == ConsoleKey.UpArrow) | |
{ | |
y -= 1; | |
} | |
else if (keyPressed.Key == ConsoleKey.DownArrow) | |
{ | |
y += 1; | |
} | |
} | |
else | |
{ | |
y += 1; | |
Thread.Sleep(100); | |
} | |
x = (x + width) % width; | |
if (y >= height || y < 0) { break; } | |
} | |
var seconds = DateTime.Now.Subtract(beginWait).TotalSeconds; | |
Console.Clear(); | |
Console.BackgroundColor = ConsoleColor.DarkRed; | |
Console.ForegroundColor = ConsoleColor.DarkYellow; | |
draw(makeFill(width, height, 0)); | |
Console.SetCursorPosition(0, 0); | |
Console.WriteLine(String.Format("\n\n BEAD BEAD ... YOU SCORE: {0} \n press 'space' to exit", seconds)); | |
do | |
{ | |
keyPressed = Console.ReadKey(); | |
Console.SetCursorPosition(0, 0); | |
} | |
while (keyPressed.Key != ConsoleKey.Spacebar); | |
} | |
static void drawPalette() | |
{ | |
Console.WriteLine(" == PALETTE == "); | |
for (int i = 0; i < 16; i++) | |
{ | |
if (i < 10) { Console.Write(" "); } | |
else { Console.Write(" "); } | |
Console.Write(i); | |
Console.Write(":"); | |
Console.Write(intToChar(i)); | |
Console.WriteLine(":"); | |
Console.WriteLine(); | |
} | |
} | |
static int[][] makeFill(int width, int height, int color) | |
{ | |
int[][] img = new int[width][]; | |
for (int i = 0; i < width; i++) | |
{ | |
img[i] = new int[height]; | |
for (int j = 0; j < height; j++) | |
{ | |
img[i][j] = color; | |
} | |
} | |
return img; | |
} | |
static void draw(int[][] img) | |
{ | |
int width = img.Length; | |
int height = img[0].Length; | |
string textImg = ""; | |
for (int j = 0; j < height; j++) | |
{ | |
for (int i = 0; i < width; i++) | |
{ | |
textImg += (intToChar(img[i][j])); | |
} | |
textImg += '\n'; | |
} | |
Console.WriteLine(textImg); | |
} | |
static char intToChar(int i) | |
{ | |
char c = (char)0; | |
if (i == 00) | |
{ | |
c = ' '; | |
} | |
else if (i == 01) | |
{ | |
c = '░'; | |
} | |
else if (i == 02) | |
{ | |
c = '▒'; | |
} | |
else if (i == 03) | |
{ | |
c = '▓'; | |
} | |
else if (i == 04) | |
{ | |
c = '█'; | |
} | |
else if (i == 05) | |
{ | |
c = '│'; | |
} | |
else if (i == 06) | |
{ | |
c = '┌'; | |
} | |
else if (i == 07) | |
{ | |
c = '┐'; | |
} | |
else if (i == 08) | |
{ | |
c = '└'; | |
} | |
else if (i == 09) | |
{ | |
c = '┘'; | |
} | |
else if (i == 10) | |
{ | |
c = '─'; | |
} | |
else if (i == 11) | |
{ | |
c = '┴'; | |
} | |
else if (i == 12) | |
{ | |
c = '┬'; | |
} | |
else if (i == 13) | |
{ | |
c = '├'; | |
} | |
else if (i == 14) | |
{ | |
c = '┼'; | |
} | |
else if (i == 15) | |
{ | |
c = '┤'; | |
} | |
/* | |
0 1 2 3 4 5 6 7 8 9 A B C D E F | |
B0 ░ ▒ ▓ │ ┤ ╡ ╢ ╖ ╕ ╣ ║ ╗ ╝ ╜ ╛ ┐ | |
C0 └ ┴ ┬ ├ ─ ┼ ╞ ╟ ╚ ╔ ╩ ╦ ╠ ═ ╬ ╧ | |
D0 ╨ ╤ ╥ ╙ ╘ ╒ ╓ ╫ ╪ ┘ ┌ █ ▄ ▌ ▐ ▀ | |
*/ | |
return c; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment