Advertisement
allerost

Snake....

Sep 16th, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Threading;
  7.  
  8. namespace MovePlayer
  9. {
  10.    
  11.     class Program
  12.     {
  13.          
  14.         //Två int variabler som kan innehålla heltal.
  15.         //Vi kommer att använda dessa för att uppdatera vår spelares position
  16.        
  17.         public static int x = 10;
  18.         public static int y = 10;
  19.         public static int x2 = 20;
  20.         public static int y2 = 20;
  21.         //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.
  22.         public static char player = '☺';
  23.         public static char enemy = 'E';
  24.  
  25.         public static ConsoleKeyInfo tangent;
  26.  
  27.         static void Main(string[] args)
  28.         {
  29.             Intro();
  30.             Thread.Sleep(6000);
  31.  
  32.             RitaUtSpelaren();
  33.             RitaUtFienden();
  34.  
  35.             while (0 < 100)
  36.             {
  37.                 //Här väljer jag att skriva en funktion för att flytta min spelar.
  38.                 FlyttaSpelaren();
  39.                
  40.                 //Här väljer jag att göra en funktion som ritar ut spelaren efter att den har flyttats.
  41.                 RitaUtSpelaren();
  42.                 RitaUtFienden();
  43.             }
  44.         }
  45.         public static void FlyttaSpelaren()
  46.         {
  47.             tangent = Console.ReadKey();
  48.             //Här inne kommer jag ha koden för att flytta min spelare
  49.             //För att kunna komma åt min position alltså mitt X och Y måste jag göra dessa public static
  50.             if (tangent.Key == ConsoleKey.LeftArrow && x > 0)
  51.             {
  52.                 x--;
  53.             }
  54.             else if (tangent.Key == ConsoleKey.RightArrow && x < 79)
  55.             {
  56.                 x++;
  57.             }
  58.             else if (tangent.Key == ConsoleKey.UpArrow && y > 0)
  59.             {
  60.                 y--;
  61.             }
  62.             else if (tangent.Key == ConsoleKey.DownArrow && y < 24)
  63.             {
  64.                 y++;
  65.             }
  66.  
  67.             if (x == x2 && y == y2)
  68.             {
  69.                 Console.Clear();
  70.                
  71.                 Console.ReadKey();
  72.                
  73.             }
  74.  
  75.            
  76.         }
  77.         private static void RitaUtSpelaren()
  78.         {
  79.             Console.Clear();
  80.             Console.SetCursorPosition(x, y);
  81.             Console.Write(player);
  82.             Console.SetCursorPosition(0, 0);
  83.         }
  84.         private static void RitaUtFienden()
  85.         {
  86.             Console.SetCursorPosition(x2, y2);
  87.             Console.Write(enemy);
  88.             Console.SetCursorPosition(0, 0);
  89.         }
  90.         public static void Intro()
  91.         {
  92.            
  93.             Console.WriteLine("        Hello And Welcome To My Simple Game!");
  94.             Thread.Sleep(2000);
  95.             Console.WriteLine("");
  96.             Console.WriteLine("");
  97.             Console.WriteLine("The Game Is Easy To manouver.");
  98.             Thread.Sleep(1500);
  99.             Console.WriteLine("You move the character using the following!");
  100.             Thread.Sleep(2500);
  101.             Console.ForegroundColor = ConsoleColor.Green;
  102.             Console.WriteLine("Go left by using the left arrow key! <--");
  103.             Console.WriteLine("");
  104.             Console.WriteLine("Go right by using the riht arrow key! -->");
  105.             Console.WriteLine("");
  106.             Console.WriteLine("Go down by using the down arrow key!");
  107.             Console.WriteLine("");
  108.             Console.WriteLine("Go up by using the up arrow key!");
  109.             Console.WriteLine("");
  110.             Console.ForegroundColor = ConsoleColor.White;
  111.         }
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement