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 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 ConsoleKeyInfo tangent;
- static void Main(string[] args)
- {
- Enemy bob = new Enemy(20, 20);
- do
- {
- points++;
- } while (bob.alive == false);
- Intro();
- Thread.Sleep(600);
- RitaUtSpelaren();
- bob.RitaUtFienden();
- while (0 < 100)
- {
- //Här väljer jag att skriva en funktion för att flytta min spelar.
- FlyttaSpelaren();
- //Här väljer jag att göra en funktion som ritar ut spelaren efter att den har flyttats.
- RitaUtSpelaren();
- CheckCollision(bob);
- bob.RitaUtFienden();
- Points(bob);
- }
- }
- 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 (e.alive)
- {
- if (x == e.x && y == e.y)
- {
- e.alive = false;
- if (!e.alive)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(" You killed the first Bob! Only four left!");
- Console.ForegroundColor = ConsoleColor.White;
- Thread.Sleep(500);
- Console.Clear();
- Enemy bob2 = new Enemy(38, 15);
- RitaUtSpelaren();
- bob2.RitaUtFienden();
- while (0 < 100)
- {
- //Här väljer jag att skriva en funktion för att flytta min spelar.
- FlyttaSpelaren();
- //Här väljer jag att göra en funktion som ritar ut spelaren efter att den har flyttats.
- RitaUtSpelaren();
- CheckCollision(bob2);
- bob2.RitaUtFienden();
- Points(bob2);
- if (e.alive)
- {
- if (x2 == e.x && y2 == e.y)
- {
- e.alive = false;
- if (!e.alive)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(" You killed the second Bob! Only three left!");
- Console.ForegroundColor = ConsoleColor.White;
- Thread.Sleep(1000);
- Console.Clear();
- Enemy bob3 = new Enemy(12, 3);
- }
- }
- }
- }
- }
- }
- }
- }
- private static void RitaUtSpelaren()
- {
- Console.Clear();
- Console.SetCursorPosition(5, 5);
- Console.Write(points);
- 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;
- }
- }
- }
- 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