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;
- using System.Threading;
- namespace HeroGames
- {
- class Program
- {
- public static int introSpeed = 0;
- public static int points = 0;
- //Två int variabler som kan innehålla heltal.
- //Vi kommer att använda dessa för att uppdatera vår spelares position
- public static int x = 10;
- public static int y = 10;
- public static int x2 = 38;
- public static int y2 = 15;
- public static int kills = 0;
- //public static int x2 = 20;
- //public static int y2 = 20;
- //När man gör något public static gör man så att man kan komma åt och ändra värdena på dessa variabler ifrån andra ställen.
- public static char player = '☺';
- public static Random random = new Random();
- public static ConsoleKeyInfo tangent;
- static void Main(string[] args)
- {
- Enemy bob = new Enemy(20, 20);
- do
- {
- points++;
- } while (bob.alive == false);
- Intro();
- Thread.Sleep(5000);
- RitaUtSpelaren();
- bob.RitaUtFienden();
- while (true)
- {
- //Här väljer jag att skriva en funktion för att flytta min spelar.
- if (10 == 10)
- {
- if (points >= 400)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- }
- Console.SetCursorPosition(55, 0);
- Console.Write("Steps taken : {0}" , points);
- Console.SetCursorPosition(0, 0);
- }
- Console.ForegroundColor = ConsoleColor.White;
- FlyttaSpelaren();
- Points(bob);
- if (points == 500)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(" GAME OVER!");
- Console.WriteLine(" You have done your 500 moves.");
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(" Total amout of bob's killed are: {0}!",kills);
- Thread.Sleep(5000);
- break;
- }
- //kollar om bob är död
- CheckCollision(bob);
- //om bob är död
- if (!bob.alive)
- {
- //pausa spelet och informera spelarn
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(" You've killed Bob!");
- Console.ForegroundColor = ConsoleColor.White;
- Thread.Sleep(500);
- Console.Clear();
- kills++;
- bob = new Enemy(random.Next(0, 78), random.Next(0, 24));
- }
- //om bob inte är död
- //rita ut dom igen
- RitaUtSpelaren();
- bob.RitaUtFienden();
- }
- }
- public static void FlyttaSpelaren()
- {
- tangent = Console.ReadKey();
- //Här inne kommer jag ha koden för att flytta min spelare
- //För att kunna komma åt min position alltså mitt X och Y måste jag göra dessa public static
- if (tangent.Key == ConsoleKey.LeftArrow && x > 0)
- {
- x--;
- }
- else if (tangent.Key == ConsoleKey.RightArrow && x < 79)
- {
- x++;
- }
- else if (tangent.Key == ConsoleKey.UpArrow && y > 0)
- {
- y--;
- }
- else if (tangent.Key == ConsoleKey.DownArrow && y < 24)
- {
- y++;
- }
- }
- public static void CheckCollision(Enemy e)
- {
- if (x == e.x && y == e.y)
- e.alive = false;
- }
- private static void RitaUtSpelaren()
- {
- Console.Clear();
- Console.SetCursorPosition(5, 5);
- Console.SetCursorPosition(x, y);
- Console.Write(player);
- Console.SetCursorPosition(0, 0);
- }
- public static void Points(Enemy e)
- {
- points++;
- }
- public static void Intro()
- {
- Console.WriteLine(" Hello And Welcome To My Simple Game!");
- Thread.Sleep(introSpeed);
- Console.WriteLine("");
- Console.WriteLine("");
- Console.WriteLine("The Game Is Easy To manouver.");
- Thread.Sleep(introSpeed);
- Console.WriteLine("You move the character using the following!");
- Thread.Sleep(introSpeed);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Go left by using the left arrow key! <--");
- Console.WriteLine("");
- Console.WriteLine("Go right by using the riht arrow key! -->");
- Console.WriteLine("");
- Console.WriteLine("Go down by using the down arrow key!");
- Console.WriteLine("");
- Console.WriteLine("Go up by using the up arrow key!");
- Console.WriteLine("");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine(" You have 500 moves to kills as many bobs as you can!");
- Console.WriteLine(" Best Of Luck!");
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace HeroGames
- {
- class Enemy
- {
- char picture = 'E';
- int health;
- public int x;
- public int y;
- public bool alive = true;
- public Enemy(int X, int Y)
- {
- x = X;
- y = Y;
- }
- public Enemy(int X, int Y, int Health)
- {
- x = X;
- y = Y;
- health = Health;
- }
- public void Walk()
- {
- }
- public void Attack()
- {
- }
- public void Die()
- {
- }
- public void RitaUtFienden()
- {
- if (alive)
- {
- Console.SetCursorPosition(x, y);
- Console.Write(picture);
- Console.SetCursorPosition(0, 0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement