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;
- namespace battle_royal_lista
- {
- class Program
- {
- static void Main(string[] args)
- {
- 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
- List<string> Player_Names = new List<string>();//this will be used to rememvber the players names
- List<int> Player_Hp = new List<int>();//this will be used to rememvber the players HP
- 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
- List<bool> is_dead = new List<bool>();//I use this list to see if a player is dead
- Random RanGen = new Random();//this is my generic random nuber generator
- bool NotDone = true;//I use this bool to see if the user is done with the player naming menu
- int winner = 0;//I use this int to remember who the last player standing was
- while (NotDone)//Untill the user is done with the player naming menu this will loop a new player
- {
- Player_Hp.Add(50); //here I add a player to the hp list and add 50 hp to the current player
- bool NotPassed = true;//I use this to see if the user has entered a valid player name
- string input;//I use this string as a buffer before actually setting the players name
- while(NotPassed && NotDone)//I loop this if the player enters an inncorrect else I will just run it once per player
- {
- Console.WriteLine("please write player " + (player + 1) + "'s name or press enter to continue");//tell the user what to do
- input = Console.ReadLine();//I set input to the users name suggestion
- NotPassed = input.Any(char.IsSeparator);//I check if the user suggestied name contains any separators making it invalid
- if (input == "")//I check if the user only pressed enter by checking if they left the player naming field empty
- {
- if (Player_Names.Count < 2)//I check if the user have entered less than two players
- {
- Console.WriteLine("please add 2 or more player names");//If the user have entered too fiew names I tell them to write extra names
- }
- else
- {
- NotDone = false;//If they have entered enough names I set Notdone to false getting the user out of the naming menu
- }
- }
- if (NotPassed && NotDone)//here I chek if the name the entered is invalid and have not just pressed enter
- {
- 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
- }
- else
- {
- if (input != "")
- {
- Player_Names.Add(input);//here I add input to the player names list giving the current player a name
- is_dead.Add(false);//here I set the current players is_dead atribute to false
- }
- }
- }
- player++;//here I set player to +1 to add an extra player
- }
- 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
- {
- Console.WriteLine("player" + (i + 1) + ":" + Player_Names[i]);
- }
- 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
- {
- player = 0;//here I set player to 0 to start over with player 0 hitting
- for (int i = 0; i < Player_Names.Count; i++)//here I go thrugh every player and let them hit a random player
- {
- if (is_dead[player] == false)//here I chek if the current player is alive else I skip their turn
- {
- int hit_player = RanGen.Next(0,(Player_Names.Count - 1));//here I get a random player for the current player to hit
- 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
- {
- hit_player++;//here I add one to who the hit player is
- 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
- {
- hit_player = 0;
- }
- }
- int hit = RanGen.Next(1, 11);//here I get the damage for the current player it can be from 1 to 10
- Player_Hp[hit_player] = Player_Hp[hit_player] - hit;//here I set the hit players hp to his hp - the hit damage
- 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
- if (Player_Hp[hit_player] <= 0)//here I check if the hit player died
- {
- Dead_players.Add(hit_player);//here I add the dead hit player to the dead scoreboard
- is_dead[hit_player] = true;//here I set the player as dead
- Console.WriteLine(Player_Names[hit_player] + " is the " + Dead_players.Count + " one to die");//here I tell the user that the hit player died
- }
- }
- 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
- {
- winner = player;
- }
- player++;//here I cycle to the next player to hit
- }
- Console.WriteLine("round");//here I sugest to the user that one round has passed
- }
- Console.WriteLine("match");//here I sugest to the user that the game is over
- for (int i = 0; i < Dead_players.Count; i++)//here I scroll thrugh all the players to show who died first and last
- {
- Console.WriteLine("the " + (i+1) +" one to die was " + Player_Names[Dead_players[i]]);
- }
- Console.WriteLine("and the winner is " + Player_Names[winner]);//here I proclaim the winner
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment