public List<Player> Read()
        {
            string name;
            bool won;
            try
            {
                using (FileStream log = new FileStream(fileName, FileMode.OpenOrCreate))
                {
                    using (StreamReader reader = new StreamReader(log))
                    {
                        using (var csvReader = new CsvReader(reader))
                        {
                            while (csvReader.Read())
                            {
                                name = csvReader.GetField<string>(0);
                                won = csvReader.GetField<bool>(1);
                                Player player = new Player(name, won);
                                players.Add(player);
                            }
                        }
                    
                    }
      
                }
                return players;
            }
            catch (Exception)
            {
                Console.WriteLine("Sorry, no scores have been recorded yet");
                return players;
            }

        }
        static void Main(string[] args)
        { 

            List<int> highScore = new List<int>()
            { 0 };
            Display display = new Display();

            string p1Name = display.player1Name;
            string p2Name = display.player2Name;
            Player player1 = new Player(p1Name, 0, highScore,0,0);
            Player player2 = new Player(p2Name, 0, highScore, 0, 0);

            MyFileWriter fileWriter = new MyFileWriter("Rock_Paper_Scissors.txt");
            fileWriter.WriteToFile(player1);
            fileWriter.WriteToFile(player2);        


            
            




            
            
            
            
            
            

        }
Exemple #3
0
        static void Main(string[] args)
        {
            Random myRand = new Random();
            int length = 100; //sets the number of times the game will be played before declaring a winner
            
            Player Player1 = new Player();
            Player Player2 = new Player();

            for (int i = 0; i < length; i++)
            {
                Player1.Act(myRand);
                Player2.Act(myRand);
                Game.Fight(Player1, Player2);
            }

            string winner = "";
            if (Player1.Score > Player2.Score)
            {
                winner = "Player 1 is the Champion!!";
            }
            else if (Player1.Score < Player2.Score)
            {
                winner = "Player 2 is the Champion!!";
            }
            else
            {
                winner = "You're both Champions!!";
            }

            Console.WriteLine(string.Format("\nWe have a winner!! {0}", winner));
            Console.WriteLine(string.Format("Player 1: {0}, Player 2: {1}", Player1.Score, Player2.Score));

            //pause
            Console.ReadLine();
        }
		private void Write(string fileName, Player player)
		{
			string winners = $"{player.name}, {player.won}";
			using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write))
			using (StreamWriter sw = new StreamWriter(fs))
			{ sw.WriteLine(winners); sw.Dispose(); }
		}
 public RunGame()
 {
     scissor = new Scissor("Scissor");
     paper = new Paper("Paper");
     rock = new Rock("Rock");
     spock = new Spock("Spock");
     lizard = new Lizard("Lizard");
     player = new Player();
     ai = new AI();
     display = new Display();
 }
Exemple #6
0
 public static void startComputerGame()
 {
     var computerPlayerOne = new Player ("COMPUTER REGGIE");
     var computerPlayerTwo = new Player ("COMPUTER BERNARD");
     var game = new Game (computerPlayerOne, computerPlayerTwo);
     game.playerOne.throwGesture();
     playerTurn (game.playerOne);
     playerTurn (game.playerTwo);
     revealWinner (game);
     playAgain ();
 }
        public void WriteToFile(Player player)
        {
            File.AppendAllText(this.path, string.Format(@"
Player: {0}
score: {1} 
highScore: {2}
wins: {3}
losses: {4}
",player.playerName, player.score, player.highScore[0].ToString(), player.wins, player.losses)); 


        }
Exemple #8
0
 public static void startOnePlayerGame()
 {
     Console.WriteLine ("Enter your name:");
     var player = new Player (Console.ReadLine ());
     var computerPlayer = new Player ();
     var game = new Game (player, computerPlayer);
     Console.WriteLine ("Choose rock, paper or scissors");
     game.playerOne.throwGesture(Console.ReadLine ());
     Console.WriteLine (game.playerOne.name + " chooses " + game.playerOne.gesture);
     playerTurn (game.playerTwo);
     revealWinner (game);
     playAgain ();
 }
Exemple #9
0
 public string TheFight(Player playerOne, Player playerTwo) {
     if (playerOne.Act() == playerTwo.Act()) {
         return "It's a draw!";
     } else if (playerOne.Act() == "Scissors" && playerTwo.Act() == "Paper") {
         return String.Format("Player {0} wins with {1} against {2}", playerOne.PlayerNum, playerOne.Act(), playerTwo.Act());
     } else if (playerTwo.Act() == "Scissors" && playerOne.Act() == "Paper") {
         return String.Format("Player {0} wins with {1} against {2}", playerTwo.PlayerNum, playerTwo.Act(), playerOne.Act());
     } else if (playerOne.Act() == "Rock" && playerTwo.Act() == "Scissors") {
         return String.Format("Player {0} wins with {1} against {2}", playerOne.PlayerNum, playerOne.Act(), playerTwo.Act());
     } else if (playerTwo.Act() == "Rock" && playerOne.Act() == "Scissors") {
         return String.Format("Player {0} wins with {1} against {2}", playerTwo.PlayerNum, playerTwo.Act(), playerOne.Act());
     } else if (playerOne.Act() == "Paper" && playerTwo.Act() == "Rock") {
         return String.Format("Player {0} wins with {1} against {2}", playerOne.PlayerNum, playerOne.Act(), playerTwo.Act());
     } else {
         return String.Format("Player {0} wins with {1} against {2}", playerTwo.PlayerNum, playerTwo.Act(), playerOne.Act());
     } 
 }
        static void Main(string[] args)
        {
            int player1Wins=0;
            int player2Wins=0;
            int player1Loss=0;
            int player2Loss=0;
            string player1Name;
            string player2Name;
            string AI = "AI";
            string human = "human";

            Console.WriteLine("playign against AI or human?");
            String chosenOponent = (Console.ReadLine());

            if (chosenOponent=="Human")
            {

                GetHandSign newHandSign = new GetHandSign(null);
                HandSign handSign = new HandSign(null);
                CompairHandSignChoises chosensigns = new CompairHandSignChoises();
                Player player1 = new Player("Adam", handSign.GetUserInputHandSign(), player1Wins, player1Loss);
                Player player2 = new Player("fred", handSign.GetUserInputHandSign(), player2Wins, player2Loss);
                Console.WriteLine("player1 chose " + player1.currentHandSign.chosenSign);
                Console.WriteLine("player2 chose {0}", player2.currentHandSign.chosenSign);
                chosensigns.CompairHandSigns(player1.currentHandSign, player2.currentHandSign);
            }
            else if (chosenOponent=="AI")
            {
                Random RandomNumber = new Random();
                int AIHandSign = RandomNumber.Next(5);
                GetHandSign newHandSign = new GetHandSign(null);
                HandSign handSign = new HandSign(null);
                CompairHandSignChoises chosensigns = new CompairHandSignChoises();
                Player player1 = new Player("Adam", handSign.GetUserInputHandSign(), player1Wins, player1Loss);
                Player player2 = new Player("fred", handSign.GetAIHandSign(AIHandSign), player2Wins, player2Loss);
                Console.WriteLine("player1 chose "+ player1.currentHandSign.chosenSign);
                Console.WriteLine("player2 chose {0}",player2.currentHandSign.chosenSign);
            }

           
            




        }
Exemple #11
0
        public static void PlayGames(int numOfRounds) {
            Random choice = new Random();
            Game newGame = new Game();

            Player playerOne;
            Player playerTwo;
            //Console.WriteLine(newGame.TheFight(playerOne, playerTwo));

            //Console.WriteLine("Player {0} uses {1}", playerOne.PlayerNum, playerOne.Act());
            //Console.WriteLine("Player {0} uses {1}", playerTwo.PlayerNum, playerTwo.Act());

            int playerOneWins = 0;
            int playerTwoWins = 0;
            int ties = 0;
            string result;
            int rounds = numOfRounds;

            for (var i = 0; i < rounds; i++) {
                playerOne = new Player(1, choice.Next(3));
                playerTwo = new Player(2, choice.Next(3));

                result = newGame.TheFight(playerOne, playerTwo);
                if (result[7] == '1') {
                    playerOneWins++;
                } else if (result[7] == '2') {
                    playerTwoWins++;
                } else {
                    ties++;
                }
            }
            Console.WriteLine("Ties {0}", ties);
            Console.WriteLine("Player One Wins {0}", playerOneWins);
            Console.WriteLine("Player Two Wins {0}", playerTwoWins);
            Console.WriteLine("/////////////////////");
            if (ties > playerOneWins && ties > playerTwoWins) {
                Console.WriteLine("The Ties have it.");
            } else if (playerOneWins > playerTwoWins) {
                Console.WriteLine("Player One Wins with " + playerOneWins + " rounds!");
            } else {
                Console.WriteLine("Player Two Wins with " + playerTwoWins + " rounds!");
            }
        }
Exemple #12
0
	    public Game(Player playerOne, Player playerTwo)
	    {
		    PlayerOne = playerOne;
		    PlayerTwo = playerTwo;
	    }
		public FileWriter(Game game)
		{
            playerOne = game.PlayerOne;
			playerTwo = game.PlayerTwo;
		}
Exemple #14
0
		public void DetermineWinningPlayer(Player player)
		{
			string value = choice.DetermineWinningChoice(player.choice);
			Console.WriteLine(value);
		}
        private void WriteOutcome(Player winner, Player loser)
        {
            string verb = winner.Choice.Defeats[loser.Choice.SelectedOption];
            string outcome = String.Format("{3} ({0}) {1} {4} ({2})",
                winner.Choice.SelectedOption,
                verb,
                loser.Choice.SelectedOption,
                winner.Name,
                loser.Name);
            Console.WriteLine(outcome);

            WriteStandings();
            Console.WriteLine();
        }
Exemple #16
0
 public static void Fight(Player p1, Player p2)
 {
     switch (p1.Move)
     {
         case PlayerMove.Rock:
             switch (p2.Move)
             {                       
                 case PlayerMove.Rock:                       //tie
                     p1.Score += 1;
                     p2.Score += 1;
                     Console.WriteLine("Tie! You both got Rock!");
                     break;
                 case PlayerMove.Paper:                      //Player 2
                     p1.Score -= 2;
                     p2.Score += 2;
                     Console.WriteLine("Player 2 wins with Paper over Rock!");
                     break;
                 default:                                    //Player 1
                     p1.Score += 2;
                     p2.Score -= 2;
                     Console.WriteLine("Player 1 wins with Rock over Scissors!");
                     break;
             }
             break;
         case PlayerMove.Paper:
             switch (p2.Move)
             {
                 case PlayerMove.Rock:                       //Player 1
                     p1.Score += 2;
                     p2.Score -= 2;
                     Console.WriteLine("Player 1 wins with Paper over Rock!");
                     break;
                 case PlayerMove.Paper:                      //tie
                     p1.Score += 1;
                     p2.Score += 1;
                     Console.WriteLine("Tie! You both got Paper!");
                     break;
                 default:                                    //Player 2
                     p1.Score -= 2;
                     p2.Score += 2;
                     Console.WriteLine("Player 2 wins with Scissors over Paper!");
                     break;
             }
             break;
         default:
             switch (p2.Move)
             {
                 case PlayerMove.Rock:                       //Player 2
                     p1.Score -= 2;
                     p2.Score += 2;
                     Console.WriteLine("Player 2 wins with Rock over Scissors!");
                     break;
                 case PlayerMove.Paper:                      //Player 1
                     p1.Score += 2;
                     p2.Score -= 2;
                     Console.WriteLine("Player 1 wins with Scissors over Paper!");
                     break;
                 default:                                    //tie
                     p1.Score += 1;
                     p2.Score += 1;
                     Console.WriteLine("Tie! You both got Scissors!");
                     break;
             }
             break;
     }
 }
 private void AiPlayer()
 {
     playerTwoAI = new Player("AiPlayer", (Items.Item)Random());
 }
Exemple #18
0
        public void VsComputer()
        {
            display = new Display();
            player = new Player();
            ai = new AI("AI");
            rock = new Rock("Rock");
            paper = new Paper("Paper");
            scissors = new Scissors("Scissors");
            bool gameActive = true;

            while (gameActive == true)
            {
                display.OutputToFile("ScoresVsAI.txt");
                Console.WriteLine("New game? yes/no");
                string userContinue = Console.ReadLine().ToLower();
                Console.Clear();
                display.DisplayScoreBoardVsAI();

                if (userContinue == "no")
                {
                    display.OutputToFile("ScoresVsAI.txt");
                    break;
                }

                if (userContinue == "yes")
                {
                    ai.AITurn();
                    player.Player1Input();
                    Console.WriteLine(Environment.NewLine);

                    //rock
                    if (ai.aiChoice == "rock")
                    {
                        if (player.player1Choice == "rock")
                        {
                            Console.WriteLine("The {0} chose {1}", ai.Name, rock.Name);
                            Console.WriteLine("It is a tie.\r\n");
                        }
                        else if (player.player1Choice == "paper")
                        {
                            display.player1Score++;
                            Console.WriteLine("The {0} chose {1}", ai.Name, rock.Name);
                            paper.DisplayWin(player.player1Choice, ai.aiChoice);
                            Console.WriteLine("You win!\r\n");
                        }
                        else if (player.player1Choice == "scissors")
                        {
                            display.aiScore++;
                            Console.WriteLine("The {0} chose {1}", ai.Name, rock.Name);
                            scissors.DisplayLoss(player.player1Choice, ai.aiChoice);
                            Console.WriteLine("{0} wins!\r\n",ai.Name);
                        }
                        else
                        {
                            Console.WriteLine("You must choose Rock, Paper, or Scissors!\r\n");
                        }

                    }
                    //paper
                    else if (ai.aiChoice == "paper")
                    {
                        if (player.player1Choice == "rock")
                        {
                            Console.WriteLine("The {0} chose {1}", ai.Name, rock.Name);
                            rock.DisplayLoss(player.player1Choice, ai.aiChoice);
                            Console.WriteLine("{0} wins!\r\n",ai.Name);
                            display.aiScore++;
                        }
                        else if (player.player1Choice == "paper")
                        {
                            Console.WriteLine("The {0} chose {1}", ai.Name, paper.Name);
                            Console.WriteLine("It is a tie\r\n");                            

                        }
                        else if (player.player1Choice == "scissors")
                        {
                            Console.WriteLine("The {0} chose {1}", ai.Name, paper.Name);
                            scissors.DisplayWin(player.player1Choice, ai.aiChoice);
                            Console.WriteLine("You win!\r\n");
                            display.player1Score++;

                        }
                        else
                        {
                            Console.WriteLine("You must choose Rock, Paper, or Scissors!\r\n");
                        }
                    }

                    //scissors
                    else if (ai.aiChoice == "scissors")
                    {
                        if (player.player1Choice == "rock")
                        {
                            //ai scissors, you rock = win
                            display.player1Score++;
                            Console.WriteLine("The {0} chose {1}", ai.Name, scissors.Name);
                            rock.DisplayWin(player.player1Choice, ai.aiChoice);
                            Console.WriteLine("You win!\r\n");
                        }
                        else if (player.player1Choice == "paper")
                        {
                            //ai scissors, you paper = lose
                            display.aiScore++;
                            Console.WriteLine("The {0} chose {1}", ai.Name, scissors.Name);
                            paper.DisplayLoss(player.player1Choice, ai.aiChoice);
                            Console.WriteLine("{0} wins!\r\n", ai.Name);
                        
                        }
                        else if (player.player1Choice == "scissors")
                        {
                            Console.WriteLine("The {0} chose {1}", ai.Name, scissors.Name);
                            Console.WriteLine("It is a tie\r\n");
                        }
                        else
                        {
                            Console.WriteLine("You must choose Rock, Paper, or Scissors!\r\n");
                        }

                    }
                }
            }
        }
 private void PlayerOneMenu()
 {
     //New One Player Game
     playerOneChoice = playerOneMenu.CreateMenu();
     playerOne = new Player(playerOneName, (Items.Item)playerOneChoice);
 }
        private void PlayerTwoMenu()
        {
            playerTwoChoice = playerTwoMenu.CreateMenu();
            playerTwo = new Player(playerTwoName, (Items.Item)playerTwoChoice);

        }
 private Game CreateGame(Player one, Player two)
 {
     Game newGame = new Game(one, two);
     return newGame;
 }
Exemple #22
0
 public static void playerTurn(Player player)
 {
     player.throwGesture();
     Console.WriteLine (player.name + " chooses " + player.gesture);
 }
Exemple #23
0
 // Pass Object as a Parameter?
 // What Data Type???
 // cannot be Object type because the Act() method would be blocked.
 //
 public void Fight( Player Player1, Player Player2 )
 {
     Player1.Act();
     Player2.Act();
 }