Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace RandomRacer
- {
- class Program
- {
- static void Main(string[] args)
- {
- string gameTitle = @"
- ::::::::: ::: :::: ::: ::::::::: :::::::: ::: :::
- :+: :+: :+: :+: :+:+: :+: :+: :+: :+: :+: :+:+: :+:+:
- +:+ +:+ +:+ +:+ :+:+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+:+ +:+
- +#++:++#: +#++:++#++: +#+ +:+ +#+ +#+ +:+ +#+ +:+ +#+ +:+ +#+
- +#+ +#+ +#+ +#+ +#+ +#+#+# +#+ +#+ +#+ +#+ +#+ +#+
- #+# #+# #+# #+# #+# #+#+# #+# #+# #+# #+# #+# #+#
- ### ### ### ### ### #### ######### ######## ### ###
- ::::::::: ::: :::::::: :::::::::: :::::::::
- :+: :+: :+: :+: :+: :+: :+: :+: :+:
- +:+ +: +:+ +:+ +:+ +:+ +:+ +:+
- +#++:++#: +#++:++#++: +#+ +#++:++# +#++:++#:
- +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+
- #+# #+# #+# #+# #+# #+# #+# #+# #+#
- ### ### ### ### ######## ########## ### ###
- ";
- Console.WriteLine();
- Console.WriteLine(gameTitle);
- Console.WriteLine();
- Console.WriteLine("\n\t\tPlay against the computer in a very random race game.");
- Console.WriteLine("\t\t H = human player C = computer player");
- Console.WriteLine();
- PressAnyKey("\n\t\t\t Press any key to continue ...");
- ClearScreen();
- Play();
- }
- static int wins = 0;
- static int losses = 0;
- static void Play()
- {
- string[] numbers = new string[50];
- string[] numbers2 = new string[50];
- bool win = false;
- bool play = true;
- bool tie = false;
- string[] player = new string[]
- {
- "H","-","-","-","-","-","-","-","-","-",
- "-","-","-","-","-","-","-","-","-","-",
- "-","-","-","-","-","-","-","-","-","-",
- "-","-","-","-","-","-","-","-","-","-",
- "-","-","-","-","-","-","-","-","-","-",
- };
- string[] computer = new string[]
- {
- "C","-","-","-","-","-","-","-","-","-",
- "-","-","-","-","-","-","-","-","-","-",
- "-","-","-","-","-","-","-","-","-","-",
- "-","-","-","-","-","-","-","-","-","-",
- "-","-","-","-","-","-","-","-","-","-",
- };
- for (int i = 0; i < player.Length; i++)
- {
- numbers[i] = player[i];
- }
- for (int i = 0; i < computer.Length; i++)
- {
- numbers2[i] = computer[i];
- }
- ConsoleKeyInfo input;
- int count = 0;
- int value = 0;
- Random random = new Random();
- value = random.Next(0, 6);
- Console.WriteLine("\n{0}", string.Join("", numbers));
- Console.WriteLine("\n|---------|---------|---------|---------|---------|");
- Console.WriteLine("\n{0}", string.Join("", numbers2));
- while (play)
- {
- input = Console.ReadKey(true);
- if (input.Key != ConsoleKey.PrintScreen)
- {
- value = random.Next(0, 7);
- count = 0;
- while (count != value||play)
- {
- string temp = numbers[numbers.Length - 1];
- if (temp == "H")
- {
- play = false;
- win = true;
- continue;
- }
- for (int i = numbers.Length - 1; i > 0; i--)
- {
- numbers[i] = numbers[i - 1];
- }
- numbers[0] = temp;
- count++;
- }
- value = random.Next(0, 7);
- count = 0;
- while (count != value||play)
- {
- string temp2 = numbers2[numbers2.Length - 1];
- if (temp2 == "C")
- {
- if (win == true)
- {
- tie = true;
- }
- play = false;
- continue;
- }
- for (int i = numbers2.Length - 1; i > 0; i--)
- {
- numbers2[i] = numbers2[i - 1];
- }
- numbers2[0] = temp2;
- count++;
- }
- Console.Clear();
- Console.SetCursorPosition(0, 0);
- Console.WriteLine("\n{0}", string.Join("", numbers));
- Console.WriteLine("\n|---------|---------|---------|---------|---------|");
- Console.WriteLine("\n{0}", string.Join("", numbers2));
- }
- }
- playAnother(numbers, numbers2, win, tie);
- }
- static void playAnother(string[] numbers, string[] numbers2, bool win, bool tie)
- {
- //Asks the player if they want to play another game.
- string anotherGame = "y";
- while (true)
- {
- string outcome;
- if (tie)
- {
- outcome = " YOU TIE!";
- }
- else
- {
- outcome = win ? " YOU WIN!" : " YOU LOSE!";
- }
- Console.Clear();
- Console.SetCursorPosition(0, 0);
- Console.WriteLine("\n{0}", string.Join("", numbers) + (outcome));
- Console.WriteLine("\n|---------|---------|---------|---------|---------|");
- Console.WriteLine("\n{0}", string.Join("", numbers2));
- Console.Write("\n\tPlay another game? Enter y|n ==> ");
- anotherGame = Console.ReadLine();
- if (anotherGame.Equals("y"))
- {
- ClearScreen();
- Play();
- }
- else if (anotherGame.Equals("n"))
- {
- Exit();
- }
- else
- {
- Console.WriteLine("ERROR: You must enter one of these characters: y, n");
- }
- }
- }
- static void Exit()
- {
- //Exits the game.
- Console.WriteLine();
- Console.WriteLine("\tThank you for playing!");
- Console.WriteLine();
- PressAnyKey("\tPress any key to exit ...");
- Environment.Exit(0);
- }
- static void ClearScreen()
- {
- //Clears the screen.
- Console.Clear();
- }
- static void PressAnyKey(string prompt)
- {
- //Reads the input when the player is asked to "press any key".
- Console.Write(prompt);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement