Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Created by Nicholas Rodine (aka CloneDeath)
- //Do whatever you want with this,
- //claim it as your own, publish it on steam, I don't care
- //this was compiled with Microsoft Visual Studio 2010 for C#
- //Should work fine for windows, the airplane and bomb WILL be fucked up on linux w/ mono
- //if you are running it on linux/mono, you can figure out how to change the characters
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Threading;
- namespace PuddingMountainMiner {
- class Program {
- static int GoldAt = 0;
- static Random Rand = new Random();
- static int[] Mountain;
- static bool GameOver = false;
- static int AirplaneX = 0;
- static int AirplaneY = 0;
- static int GameSpeed = 30;
- static bool Winner = false;
- static int Score = 0;
- static int GroundLevel {
- get {
- return Console.WindowHeight - 3;
- }
- }
- static void SetChar(int x, int y, char C) {
- if (x < Console.WindowWidth && y < Console.WindowHeight && x >= 0 && y >= 0) {
- Console.SetCursorPosition(x, y);
- Console.Write(C);
- }
- }
- static void ClearScreen() {
- Console.Clear();
- Console.BackgroundColor = ConsoleColor.White;
- for (int x = 0; x < Console.WindowWidth; x++) {
- for (int y = 0; y < Console.WindowHeight; y++) {
- SetChar(x, y, ' ');
- }
- }
- }
- static void ResetAirplane(){
- AirplaneX = 0;
- AirplaneY = Rand.Next(4, 11);
- }
- static void Initialize() {
- Console.CursorVisible = false;
- Console.Title = "Pudding Mountain Miner";
- Console.SetWindowSize(40, 30);
- Console.SetBufferSize(40, 30);
- }
- static void RedrawMountain(int i) {
- for (int h = 0; h < 15; h++) //We're just clearing a 15 tall column
- {
- if (h <= Mountain[i]) {
- Console.BackgroundColor = ConsoleColor.DarkRed;
- } else {
- Console.BackgroundColor = ConsoleColor.White;
- }
- SetChar(i, GroundLevel - h - 1, ' ');
- }
- }
- static void BuildTerrain() {
- //Ground Level
- Console.BackgroundColor = ConsoleColor.DarkYellow;
- for (int i = 0; i < Console.WindowWidth; i++) {
- SetChar(i, GroundLevel, ' ');
- }
- //Generate GOLD
- GoldAt = Rand.Next(Console.WindowWidth);
- Console.ForegroundColor = ConsoleColor.Yellow;
- SetChar(GoldAt, GroundLevel, '$');
- //Generate mountains
- Mountain = new int[Console.WindowWidth];
- for (int i = 0; i < Console.WindowWidth; i++) {
- Mountain[i] = Rand.Next(2, 7) + Rand.Next(2, 7);
- RedrawMountain(i);
- }
- }
- static void AirplaneTravel() {
- Console.BackgroundColor = ConsoleColor.White;
- Console.ForegroundColor = ConsoleColor.Black;
- //Clear Current Location
- for (int y = AirplaneY - 1; y <= AirplaneY; y++) {
- for (int x = AirplaneX - 1; x <= AirplaneX + 1; x++) {
- SetChar(x, y, ' ');
- }
- }
- if (++AirplaneX >= Console.WindowWidth) {
- ResetAirplane();
- }
- SetChar(AirplaneX, AirplaneY, '█'); //219
- SetChar(AirplaneX + 1, AirplaneY, '▄'); //220
- SetChar(AirplaneX - 1, AirplaneY, '▒'); //177
- SetChar(AirplaneX - 1, AirplaneY - 1, '▒'); //177
- }
- static void DropBomb() {
- Score++;
- for (int i = AirplaneY+1; i <= GroundLevel; i++) {
- SetChar(AirplaneX, i, '♦');
- Thread.Sleep(GameSpeed);
- SetChar(AirplaneX, i, ' ');
- int BombHeight = GroundLevel - i -1;
- if (Mountain[AirplaneX] >= BombHeight) {
- Mountain[AirplaneX]--;
- if (Mountain[AirplaneX] < -1) {
- GameOver = true;
- if (AirplaneX == GoldAt) {
- Winner = true;
- } else {
- Winner = false;
- }
- }
- break;
- }
- }
- }
- static void GameLoop() {
- while (!GameOver) {
- Thread.Sleep(GameSpeed);
- if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Spacebar) {
- DropBomb();
- }
- while(Console.KeyAvailable){
- Console.ReadKey(true);
- }
- AirplaneTravel();
- }
- }
- static void GameEnd(){
- ClearScreen();
- Console.SetCursorPosition(0, 0);
- Console.ForegroundColor = ConsoleColor.Black;
- Console.WriteLine("You are a " + (Winner?"Winner!":"Loser!"));
- Console.WriteLine("Final Score: " + Score);
- Console.WriteLine("To play again, press 'Enter'.\nPress any other key to exit.");
- }
- static void Main(string[] args) {
- Initialize();
- do {
- ClearScreen();
- Score = 0;
- GameOver = false;
- ResetAirplane();
- BuildTerrain();
- GameLoop();
- GameEnd();
- } while (Console.ReadKey(true).Key == ConsoleKey.Enter);
- Console.ReadKey(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement