Advertisement
Guest User

Pudding Mountain Miner

a guest
Dec 2nd, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.52 KB | None | 0 0
  1. //Created by Nicholas Rodine (aka CloneDeath)
  2. //Do whatever you want with this,
  3. //claim it as your own, publish it on steam, I don't care
  4.  
  5. //this was compiled with Microsoft Visual Studio 2010 for C#
  6.  
  7. //Should work fine for windows, the airplane and bomb WILL be fucked up on linux w/ mono
  8. //if you are running it on linux/mono, you can figure out how to change the characters
  9.  
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using System.Threading;
  14.  
  15. namespace PuddingMountainMiner {
  16.     class Program {
  17.         static int GoldAt = 0;
  18.         static Random Rand = new Random();
  19.         static int[] Mountain;
  20.         static bool GameOver = false;
  21.         static int AirplaneX = 0;
  22.         static int AirplaneY = 0;
  23.         static int GameSpeed = 30;
  24.         static bool Winner = false;
  25.         static int Score = 0;
  26.        
  27.  
  28.         static int GroundLevel {
  29.             get {
  30.                 return Console.WindowHeight - 3;
  31.             }
  32.         }
  33.  
  34.         static void SetChar(int x, int y, char C) {
  35.             if (x < Console.WindowWidth && y < Console.WindowHeight && x >= 0 && y >= 0) {
  36.                 Console.SetCursorPosition(x, y);
  37.                 Console.Write(C);
  38.             }
  39.         }
  40.  
  41.         static void ClearScreen() {
  42.             Console.Clear();
  43.             Console.BackgroundColor = ConsoleColor.White;
  44.  
  45.             for (int x = 0; x < Console.WindowWidth; x++) {
  46.                 for (int y = 0; y < Console.WindowHeight; y++) {
  47.                     SetChar(x, y, ' ');
  48.                 }
  49.             }
  50.         }
  51.  
  52.         static void ResetAirplane(){
  53.             AirplaneX = 0;
  54.             AirplaneY = Rand.Next(4, 11);
  55.         }
  56.  
  57.         static void Initialize() {
  58.             Console.CursorVisible = false;
  59.             Console.Title = "Pudding Mountain Miner";
  60.  
  61.             Console.SetWindowSize(40, 30);
  62.             Console.SetBufferSize(40, 30);
  63.         }
  64.  
  65.         static void RedrawMountain(int i) {
  66.             for (int h = 0; h < 15; h++) //We're just clearing a 15 tall column
  67.             {
  68.                 if (h <= Mountain[i]) {
  69.                     Console.BackgroundColor = ConsoleColor.DarkRed;
  70.                 } else {
  71.                     Console.BackgroundColor = ConsoleColor.White;
  72.                 }
  73.                 SetChar(i, GroundLevel - h - 1, ' ');
  74.             }
  75.         }
  76.  
  77.         static void BuildTerrain() {
  78.             //Ground Level
  79.             Console.BackgroundColor = ConsoleColor.DarkYellow;
  80.             for (int i = 0; i < Console.WindowWidth; i++) {
  81.                 SetChar(i, GroundLevel, ' ');
  82.             }
  83.  
  84.             //Generate GOLD
  85.             GoldAt = Rand.Next(Console.WindowWidth);
  86.             Console.ForegroundColor = ConsoleColor.Yellow;
  87.             SetChar(GoldAt, GroundLevel, '$');
  88.  
  89.             //Generate mountains
  90.             Mountain = new int[Console.WindowWidth];
  91.             for (int i = 0; i < Console.WindowWidth; i++) {
  92.                 Mountain[i] = Rand.Next(2, 7) + Rand.Next(2, 7);
  93.                 RedrawMountain(i);
  94.             }
  95.         }
  96.  
  97.         static void AirplaneTravel() {
  98.             Console.BackgroundColor = ConsoleColor.White;
  99.             Console.ForegroundColor = ConsoleColor.Black;
  100.  
  101.             //Clear Current Location
  102.             for (int y = AirplaneY - 1; y <= AirplaneY; y++) {
  103.                 for (int x = AirplaneX - 1; x <= AirplaneX + 1; x++) {
  104.                     SetChar(x, y, ' ');
  105.                 }
  106.             }
  107.  
  108.             if (++AirplaneX >= Console.WindowWidth) {
  109.                 ResetAirplane();
  110.             }
  111.  
  112.             SetChar(AirplaneX, AirplaneY, '█'); //219
  113.             SetChar(AirplaneX + 1, AirplaneY, '▄'); //220
  114.             SetChar(AirplaneX - 1, AirplaneY, '▒'); //177
  115.             SetChar(AirplaneX - 1, AirplaneY - 1, '▒'); //177
  116.         }
  117.  
  118.         static void DropBomb() {
  119.             Score++;
  120.             for (int i = AirplaneY+1; i <= GroundLevel; i++) {
  121.                 SetChar(AirplaneX, i, '♦');
  122.                 Thread.Sleep(GameSpeed);
  123.                 SetChar(AirplaneX, i, ' ');
  124.                 int BombHeight = GroundLevel - i -1;
  125.                 if (Mountain[AirplaneX] >= BombHeight) {
  126.                     Mountain[AirplaneX]--;
  127.                     if (Mountain[AirplaneX] < -1) {
  128.                         GameOver = true;
  129.                         if (AirplaneX == GoldAt) {
  130.                             Winner = true;
  131.                         } else {
  132.                             Winner = false;
  133.                         }
  134.                     }
  135.                     break;
  136.                 }
  137.             }
  138.         }
  139.  
  140.         static void GameLoop() {
  141.             while (!GameOver) {
  142.                 Thread.Sleep(GameSpeed);
  143.                 if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Spacebar) {
  144.                     DropBomb();
  145.                 }
  146.  
  147.                 while(Console.KeyAvailable){
  148.                     Console.ReadKey(true);
  149.                 }
  150.  
  151.                 AirplaneTravel();
  152.             }
  153.         }
  154.  
  155.         static void GameEnd(){
  156.             ClearScreen();
  157.             Console.SetCursorPosition(0, 0);
  158.             Console.ForegroundColor = ConsoleColor.Black;
  159.  
  160.             Console.WriteLine("You are a " + (Winner?"Winner!":"Loser!"));
  161.             Console.WriteLine("Final Score: " + Score);
  162.             Console.WriteLine("To play again, press 'Enter'.\nPress any other key to exit.");
  163.         }
  164.  
  165.         static void Main(string[] args) {
  166.             Initialize();
  167.            
  168.             do {
  169.                 ClearScreen();
  170.                 Score = 0;
  171.                 GameOver = false;
  172.                 ResetAirplane();
  173.  
  174.                 BuildTerrain();
  175.                 GameLoop();
  176.                 GameEnd();
  177.             } while (Console.ReadKey(true).Key == ConsoleKey.Enter);
  178.  
  179.             Console.ReadKey(true);
  180.         }
  181.     }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement