TheBulgarianWolf

Archery

Feb 4th, 2021
767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.99 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace Archery
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Enter the targets separated by | : ");
  11.             int[] targets = Console.ReadLine().Split("|").Select(int.Parse).ToArray();
  12.             string command;
  13.             int points = 0;
  14.             while ((command = Console.ReadLine()) != "Game over")
  15.             {
  16.                 string[] commandArr = command.Split(" ");
  17.                 if (commandArr[0] == "Shoot")
  18.                 {
  19.                     string[] shooting = commandArr[1].Split("@");
  20.                     int index = int.Parse(shooting[1]);
  21.                     int length = int.Parse(shooting[2]);
  22.                     if (shooting[0] == "Left")
  23.                     {
  24.                         if (index >= 0 || index < targets.Length)
  25.                         {
  26.                             for (int i = 0; i < length; i++)
  27.                             {
  28.                                 index--;
  29.                                 if (index == -1)
  30.                                 {
  31.                                     index = targets.Length - 1;
  32.                                 }
  33.                             }
  34.  
  35.                         }
  36.                         if (targets[index] >= 5)
  37.                         {
  38.                             targets[index] -= 5;
  39.                             points += 5;
  40.                         }
  41.                         else
  42.                         {
  43.                             points += targets[index];
  44.                             targets[index] = 0;
  45.                         }
  46.  
  47.                     }
  48.                     else if (shooting[0] == "Right")
  49.                     {
  50.                         if (index >= 0 || index < targets.Length)
  51.                         {
  52.                             for (int i = 0; i < length; i++)
  53.                             {
  54.                                 index++;
  55.                                 if (index == targets.Length)
  56.                                 {
  57.                                     index = 0;
  58.                                 }
  59.                             }
  60.  
  61.                         }
  62.                         if (targets[index] >= 5)
  63.                         {
  64.                             targets[index] -= 5;
  65.                             points += 5;
  66.                         }
  67.                         else
  68.                         {
  69.                             points += targets[index];
  70.                             targets[index] = 0;
  71.                         }
  72.                     }
  73.                 }
  74.                 else if (commandArr[0] == "Reverse")
  75.                 {
  76.                     Array.Reverse(targets);
  77.                 }
  78.             }
  79.  
  80.             foreach (int target in targets)
  81.             {
  82.                 Console.Write($"{{{target}}} - ");
  83.             }
  84.             Console.WriteLine("Points: " + points);
  85.             Console.ReadLine();
  86.         }
  87.     }
  88. }
  89.  
Add Comment
Please, Sign In to add comment