Jump to content
RealModScene
Daniel

visual c# rock paper scissors :P

Recommended Posts

Sooo just learning c# and made this for fun :p heres the source code and download for the console app :)

 

 

using System;using System.Collections.Generic;using System.Text; namespace RockPaperScissors{    class Program    {        static void Main(string[] args)        {            Console.Title = "Rock Paper Scissors";            string userChoice = "**&&**";            int computerChoice, loseCount = 0, tieCount = 0;            bool QUIT = false;            double winPercent = 100.0, gameCount = 0.0, winCount = 0.0;            Random computer = new Random();            Console.Clear();            Console.WriteLine("ROCK PAPER SCISSORS");             do            {                Console.Write("Enter choice, or enter QUIT to quit: ");                userChoice = Convert.ToString(Console.ReadLine());                ++gameCount;                if (userChoice.ToUpper() == "QUIT")                {                    break;                }                computerChoice = computer.Next(1, 4); // 1 is Rock, 2 is Paper, 3 is Scissors                 switch (userChoice.ToUpper())                {                    case "ROCK":                        if (computerChoice == 1)                        {                            Console.WriteLine("You chose {0} and the computer chose Rock. It was a tie!", userChoice);                            ++tieCount;                        }                        else if (computerChoice == 2)                        {                            Console.WriteLine("You chose {0} and the computer chose Paper. You win!", userChoice);                            ++winCount;                        }                        else if (computerChoice == 3)                        {                            Console.WriteLine("You chose {0} and the computer chose Scissors. You lose!", userChoice);                            ++loseCount;                        }                        break;                    case "PAPER":                        if (computerChoice == 1)                        {                            Console.WriteLine("You chose {0} and the computer chose Rock. You win!", userChoice);                            ++winCount;                        }                        else if (computerChoice == 2)                        {                            Console.WriteLine("You chose {0} and the computer chose Paper. It was a tie!", userChoice);                            ++tieCount;                        }                        else                        {                            Console.WriteLine("You chose {0} and the computer chose Scissors. You lose!", userChoice);                            ++loseCount;                        }                        break;                    case "SCISSORS":                        if (computerChoice == 1)                        {                            Console.WriteLine("You chose {0} and the computer chose Rock. You lose!", userChoice);                            ++loseCount;                        }                        else if (computerChoice == 2)                        {                            Console.WriteLine("You chose {0} and the computer chose Paper. You win!", userChoice);                            ++winCount;                        }                        else                        {                            Console.WriteLine("You chose {0} and the computer chose Scissors. It was a tie!", userChoice);                            ++tieCount;                        }                        break;                    default:                        {                            break;                        }                 }            } while (QUIT == false);             if (gameCount > 1)            {                Console.Clear();                Console.WriteLine("Giving up?");                Console.WriteLine("{0} game(s) played. You won {1} game(s). You lost {2} game(s). {3} game(s) were a tie.", gameCount, winCount, loseCount, tieCount);                winPercent = (winCount / gameCount) * 100;                Console.WriteLine("You won {0:f2}% of the games you played.", winPercent);                Console.WriteLine("Thanks for playing!");                Console.ReadKey();            }        }    }}

Just copy and past it into whatever builder you use and it should format it correctly so dw about the lines being split in two...

heres the download for the already bult console app :) https://mega.co.nz/#!epRVRYSL!ePibxiFjrjiIQxS97F3ZbhG0xicxKXvmzwQLvODXvDo

 

What do you guys think? :)

Share this post


Link to post
Share on other sites

Sooo just learning c# and made this for fun :p heres the source code and download for the console app :)

 

 

using System;using System.Collections.Generic;using System.Text; namespace RockPaperScissors{    class Program    {        static void Main(string[] args)        {            Console.Title = "Rock Paper Scissors";            string userChoice = "**&&**";            int computerChoice, loseCount = 0, tieCount = 0;            bool QUIT = false;            double winPercent = 100.0, gameCount = 0.0, winCount = 0.0;            Random computer = new Random();            Console.Clear();            Console.WriteLine("ROCK PAPER SCISSORS");             do            {                Console.Write("Enter choice, or enter QUIT to quit: ");                userChoice = Convert.ToString(Console.ReadLine());                ++gameCount;                if (userChoice.ToUpper() == "QUIT")                {                    break;                }                computerChoice = computer.Next(1, 4); // 1 is Rock, 2 is Paper, 3 is Scissors                 switch (userChoice.ToUpper())                {                    case "ROCK":                        if (computerChoice == 1)                        {                            Console.WriteLine("You chose {0} and the computer chose Rock. It was a tie!", userChoice);                            ++tieCount;                        }                        else if (computerChoice == 2)                        {                            Console.WriteLine("You chose {0} and the computer chose Paper. You win!", userChoice);                            ++winCount;                        }                        else if (computerChoice == 3)                        {                            Console.WriteLine("You chose {0} and the computer chose Scissors. You lose!", userChoice);                            ++loseCount;                        }                        break;                    case "PAPER":                        if (computerChoice == 1)                        {                            Console.WriteLine("You chose {0} and the computer chose Rock. You win!", userChoice);                            ++winCount;                        }                        else if (computerChoice == 2)                        {                            Console.WriteLine("You chose {0} and the computer chose Paper. It was a tie!", userChoice);                            ++tieCount;                        }                        else                        {                            Console.WriteLine("You chose {0} and the computer chose Scissors. You lose!", userChoice);                            ++loseCount;                        }                        break;                    case "SCISSORS":                        if (computerChoice == 1)                        {                            Console.WriteLine("You chose {0} and the computer chose Rock. You lose!", userChoice);                            ++loseCount;                        }                        else if (computerChoice == 2)                        {                            Console.WriteLine("You chose {0} and the computer chose Paper. You win!", userChoice);                            ++winCount;                        }                        else                        {                            Console.WriteLine("You chose {0} and the computer chose Scissors. It was a tie!", userChoice);                            ++tieCount;                        }                        break;                    default:                        {                            break;                        }                 }            } while (QUIT == false);             if (gameCount > 1)            {                Console.Clear();                Console.WriteLine("Giving up?");                Console.WriteLine("{0} game(s) played. You won {1} game(s). You lost {2} game(s). {3} game(s) were a tie.", gameCount, winCount, loseCount, tieCount);                winPercent = (winCount / gameCount) * 100;                Console.WriteLine("You won {0:f2}% of the games you played.", winPercent);                Console.WriteLine("Thanks for playing!");                Console.ReadKey();            }        }    }}

Just copy and past it into whatever builder you use and it should format it correctly so dw about the lines being split in two...

heres the download for the already bult console app :) https://mega.co.nz/#!epRVRYSL!ePibxiFjrjiIQxS97F3ZbhG0xicxKXvmzwQLvODXvDo

 

What do you guys think? :)

 

Can you upload to another host? That site is being stubborn.. :), I'd like to test it out. 

Share this post


Link to post
Share on other sites

Convert.ToString(Console.ReadLine());
^ the above code is useless... when you do Console.ReadLine() the return value is already a string, converting a string to a string is pointless don't you think? :)

 

** edit: **

 

http://www.sendspace.com/file/adf77n <--- for anyone that wants to try it out, here's a compilation to exe (which you can run directly with no install) and some updated/cleaned up source code [including the entire project]

Edited by Swizzy

Share this post


Link to post
Share on other sites

Thanks Swizzy.

 

@Daniel, I was playing this and was thinking this could be fun if it kept track of wins, ties and losses, and had a set goal of wins before the game ends (similar to Super Mario War), also some graphics would be cool.

 

EDIT: A Tic Tac Toe game would be great too, simple homebrew games that people could play with their friends, even add highscores and what-not

Edited by gangrel_1313

Share this post


Link to post
Share on other sites

Thanks Swizzy. @Daniel, I was playing this and was thinking this could be fun if it kept track of wins, ties and losses, and had a set goal of wins before the game ends (similar to Super Mario War), also some graphics would be cool. EDIT: A Tic Tac Toe game would be great too, simple homebrew games that people could play with their friends, even add highscores and what-not

I could potentially make it open animations of scissors paper rock with not to much trouble, and I think I have a few people who could help with animating or atleast making a template or something. Blender isn't to hard when younger used to it also tic tac toe sound cool, a bit harder though.. Also to have highscores online would be really annoying but maybe just stored on the computer could be coolSent from my iPhone using Tapatalk

Share this post


Link to post
Share on other sites

I could potentially make it open animations of scissors paper rock with not to much trouble, and I think I have a few people who could help with animating or atleast making a template or something. Blender isn't to hard when younger used to it also tic tac toe sound cool, a bit harder though.. Also to have highscores online would be really annoying but maybe just stored on the computer could be coolSent from my iPhone using Tapatalk

 

I wasn't necessarily talking about online play at all, I was talking about on one console, however having Link incorporated into the game for online play would be neat, but disable hi-scores for online

Share this post


Link to post
Share on other sites

I wasn't necessarily talking about online play at all, I was talking about on one console, however having Link incorporated into the game for online play would be neat, but disable hi-scores for online

You do realize this is a PC based application/game right? the "console" is well CMD...

Share this post


Link to post
Share on other sites

You do realize this is a PC based application/game right? the "console" is well CMD...

 

I guess I misinterpreted his use of the word "console", I do realize that now, I was a little confused as to why it was an EXE now I know..:p

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...