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;
- namespace Help
- {
- class Program
- {
- class Player
- {
- public string name;
- public int winCount;
- public int lastRoll;
- public bool turn;
- public Player(string Name)
- {
- name = Name;
- }
- }
- class TennisGame
- {
- static Random rand = new Random();
- private bool game;
- private int wins;
- private Player winner;
- public static int GetScore()
- {
- int score = rand.Next(7);
- return score;
- }
- public Player Game(Player player1, Player player2)
- {
- player1.turn = true;
- player2.turn = false;
- game = true;
- while (game == true)
- {
- if (player1.turn == true && player2.turn == false && wins != 5)
- {
- var roll = GetScore();
- if (roll==6)
- {
- player1.winCount++;
- wins++;
- Console.WriteLine(player1.name + " " + roll + " " + " - " + " " + player2.lastRoll + " " + player2.name);
- }
- player1.lastRoll = roll;
- player1.turn = false;
- player2.turn = true;
- }
- if (player2.turn == true && player1.turn == false && wins != 5)
- {
- var roll = GetScore();
- if (roll == 6)
- {
- player2.winCount++;
- wins++;
- if (wins == 5)
- {
- game = false;
- }
- Console.WriteLine(player1.name + " " + player1.lastRoll + " " + " - " + " " + roll + " " + player2.name);
- }
- player2.lastRoll = roll;
- player2.turn = false;
- player1.turn = true;
- }
- if(wins == 5)
- {
- if (player1.winCount > player2.winCount)
- {
- Console.WriteLine(player1.name + " Won!");
- winner = player1;
- }
- else
- {
- Console.WriteLine(player2.name + " Won!");
- winner = player2;
- }
- game = false;
- }
- }
- return winner;
- }
- static void Main(string[] args)
- {
- var p1 = 0;
- var p2 = 0;
- for (int i = 0; i < 1000; i++)
- {
- TennisGame game = new TennisGame();
- var player = game.Game(new Player("Nitcho"), new Player("Mathias"));
- if (player.name == "Nitcho")
- p1++;
- else
- p2++;
- }
- Console.WriteLine("Nitcho: " + p1 + " - " + p2 + " Mathias");
- Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement