Hi Everyone,
This is my first post on this forum. I am pretty new to programming so any help is greatly valued here. Was hoping someone could steer me in the right direction with this Dice-Poker style program I am trying to write in C#.
So far I am able store random numbers between 1 and 6 in two arrays(compRoll and userRoll) and print the results.
Where I'm stuck right now is how to use a function to find matching elements in the array itself. Then storing the number of matches, even their values so that I can print whether there are 2 of a kind, 3 of a kind, etc. The player with more matches wins. In the event of a tie between the comp and user I would just need to measure the value of the matches to determine the winner. In an all out tie I guess you just re-roll.
If you have any suggestions on how I can find the matches in the array, then use them to determine the winner, I'd be very grateful.
If I am posting this in the wrong place kindly point me to the right place. Thanks for reading this.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Project_3
/*Dice Game by Brett
* Computer rolls five dice and user rolls five dice.
* Rank: 5 of a kind > 4 of a kind > 3 of a kind > 2 of a kind.
* If both computer and user have a pair, higher dice value wins.
* If both pair values are same then next highest number in the hand wins.
* If all of both computer and user values are identical, Tie game.
* If either player doesn't at least have a pair highest number wins.*/
{
class Program
{
static void Main(string[] args)
{
const int DICE = 5;
int[] compRoll = new int[DICE];
int[] userRoll = new int[DICE];
int x = 0;
ComputerRoll(x,compRoll,compHand,DICE);
UserRoll(x,userRoll,userHand,DICE);
}
static void ComputerRoll(int x,int[] compRoll,int DICE)
{
Random RandNum = new Random();
Console.Write("{0,-20}","Computer Rolled: ");
for (x = 0;x < DICE;x++)
{
compRoll[x] = RandNum.Next(1, 7);
Console.Write("{0,-2}",compRoll[x]);
}
}
static void UserRoll(int x,int[] userRoll,int DICE)
{
Random RandNum = new Random();
Console.Write("\n\n{0,-20}", "You Rolled: ");
for (x = 0; x < DICE; x++)
{
userRoll[x] = RandNum.Next(1, 7);
Console.Write("{0,-2}", userRoll[x]);
}
}
}
}