gammeflamme

Shitty battle royal

Nov 3rd, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.58 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.  
  7. namespace battle_royal_lista
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             int player = 0;//the players in my game are represented by a number that I use in lists to connect atibutes to the number/player
  15.             List<string> Player_Names = new List<string>();//this will be used to rememvber the players names
  16.             List<int> Player_Hp = new List<int>();//this will be used to rememvber the players HP
  17.             List<int> Dead_players = new List<int>();//I use this to see how many players are dead and to see who died in what order
  18.             List<bool> is_dead = new List<bool>();//I use this list to see if a player is dead
  19.             Random RanGen = new Random();//this is my generic random nuber generator
  20.             bool NotDone = true;//I use this bool to see if the user is done with the player naming menu
  21.             int winner = 0;//I use this int to remember who the last player standing was
  22.  
  23.             while (NotDone)//Untill the user is done with the player naming menu this will loop a new player
  24.             {
  25.  
  26.                 Player_Hp.Add(50); //here I add a player to the hp list and add 50 hp to the current player
  27.                
  28.                 bool NotPassed = true;//I use this to see if the user has entered a valid player name
  29.              
  30.                 string input;//I use this string as a buffer before actually setting the players name
  31.                 while(NotPassed && NotDone)//I loop this if the player enters an inncorrect else I will just run it once per player
  32.                 {
  33.  
  34.                     Console.WriteLine("please write player " + (player + 1) + "'s name or press enter to continue");//tell the user what to do
  35.                     input = Console.ReadLine();//I set input to the users name suggestion
  36.  
  37.  
  38.                     NotPassed = input.Any(char.IsSeparator);//I check if the user suggestied name contains any separators making it invalid
  39.  
  40.                     if (input == "")//I check if the user only pressed enter by checking if they left the player naming field empty
  41.                     {
  42.                         if (Player_Names.Count < 2)//I check if the user have entered less than two players
  43.                         {
  44.                             Console.WriteLine("please add 2 or more player names");//If the user have entered too fiew names I tell them to write extra names
  45.                         }
  46.                         else
  47.                         {
  48.                             NotDone = false;//If they have entered enough names I set Notdone to false getting the user out of the naming menu
  49.                         }
  50.                     }
  51.  
  52.                     if (NotPassed && NotDone)//here I chek if the name the entered is invalid and have not just pressed enter
  53.                     {
  54.                         Console.WriteLine("Please make sure the Name of player " + (player + 1) + " does not contain any separators such as space and tab");//i tell the user to entrer a name without separators
  55.                     }
  56.                     else
  57.                     {
  58.                         if (input != "")
  59.                         {
  60.                             Player_Names.Add(input);//here I add input to the player names list giving the current player a name
  61.                             is_dead.Add(false);//here I set the current players is_dead atribute to false  
  62.  
  63.                         }
  64.                     }
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.                 }
  72.                
  73.                 player++;//here I set player to +1 to add an extra player
  74.                
  75.  
  76.             }
  77.  
  78.            
  79.             for(int i = 0; i < (player - 1); i++)//here I list all the current players names and numbers, not their player int number cause that starts on 0 and I dont want player 0
  80.             {
  81.                
  82.                 Console.WriteLine("player" + (i + 1) + ":" + Player_Names[i]);
  83.             }
  84.  
  85.             while (Dead_players.Count <= Player_Names.Count - 2)//here I test if the amount of dead players is les than the total amount of players - 1 to see if there is only one player left standing and if so enter the next round
  86.             {
  87.  
  88.                
  89.                 player = 0;//here I set player to 0 to start over with player 0 hitting
  90.                 for (int i = 0; i < Player_Names.Count; i++)//here I go thrugh every player and let them hit a random player
  91.                 {
  92.                     if (is_dead[player] == false)//here I chek if the current player is alive else I skip their turn
  93.                     {
  94.                         int hit_player = RanGen.Next(0,(Player_Names.Count - 1));//here I get a random player for the current player to hit
  95.                         while (hit_player == player || is_dead[hit_player] == true)//here I chek if the random hit player is dead or if the current player so the current player tries to hit himself or someone who is dead
  96.                         {
  97.                             hit_player++;//here I add one to who the hit player is
  98.                             if(hit_player >= Player_Names.Count)//here I chek if the next player is over the number of players in the hit_player list and set it to 0 to start over
  99.                             {
  100.                                 hit_player = 0;
  101.                             }
  102.                            
  103.                         }
  104.                         int hit = RanGen.Next(1, 11);//here I get the damage for the current player it can be from 1 to 10
  105.                         Player_Hp[hit_player] = Player_Hp[hit_player] - hit;//here I set the hit players hp to his hp - the hit damage
  106.  
  107.  
  108.                         Console.WriteLine(Player_Names[player] + " hit " + Player_Names[hit_player] + " for " + hit + " damage. " + Player_Names[hit_player] + " now have " + Player_Hp[hit_player] + " hp left");//here i say who hit and who got hit an how much hp he has
  109.                         if (Player_Hp[hit_player] <= 0)//here I check if the hit player died
  110.                         {
  111.                             Dead_players.Add(hit_player);//here I add the dead hit player to the dead scoreboard
  112.                             is_dead[hit_player] = true;//here I set the player as dead
  113.                             Console.WriteLine(Player_Names[hit_player] + " is the " + Dead_players.Count + " one to die");//here I tell the user that the hit player died
  114.                         }
  115.                     }
  116.                     if (Dead_players.Count > Player_Names.Count - 2)//here I test if the amount of dead players is les than the total amount of players - 1 to see if there is only one player left standing and if so I set the current player to the winner
  117.                     {
  118.                         winner = player;
  119.                     }
  120.                         player++;//here I cycle to the next player to hit
  121.                 }
  122.                 Console.WriteLine("round");//here I sugest to the user that one round has passed
  123.                
  124.             }
  125.             Console.WriteLine("match");//here I sugest to the user that the game is over
  126.             for (int i = 0; i < Dead_players.Count; i++)//here I scroll thrugh all the players to show who died first and last
  127.             {
  128.                 Console.WriteLine("the " + (i+1) +" one to die was " + Player_Names[Dead_players[i]]);
  129.             }
  130.             Console.WriteLine("and the winner is " + Player_Names[winner]);//here I proclaim the winner
  131.                 Console.ReadLine();
  132.  
  133.         }
  134.  
  135.  
  136.  
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment