6 Replies - 17435 Views - Last Post: 06 May 2009 - 10:38 AM Rate Topic: -----

#1 itsme8018  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-May 09

Simple C# Dice Game

Post icon  Posted 04 May 2009 - 01:48 PM

Hey all

I've got this dice game that i'm trying to make. It basically a dice version of golf. Each player rolls 3 dice until they roll a double. Each roll before the double is achieved counts as a stroke. Once a double is rolled i want the score for that hole to be displayed on the console.

At the moment im still working with notepad and the basic SDK command prompt as this is all i understand.

I've attempted some of the code so far but would really appreciate some help finishing it off (in simple terms if possible)

Thanks in advance!


using System;

namespace dicegame1
{

public static void Main()
{
	Random ran = new Random();
	
	int player1 = 0;
	int player2 = 0;
	int player1RoundScore = 0;
	int player2RoundScore = 0;
	
	bool player1RoundScore = false;
	bool player2RoundScore = false;
	
	int roundNumber = 1;
	
	// Random dice rolling //
	{
	int diceOne = ran.Next(1,7);
	int diceTwo = ran.Next(1,7);
	int diceThree = ran.Next(1,7);
	}
	{
	if (diceOne == diceTwo || diceTwo == diceThree || diceOne == diceThree)
	}
	
}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Simple C# Dice Game

#2 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 63
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: Simple C# Dice Game

Posted 04 May 2009 - 04:09 PM

What do you need help with?
Was This Post Helpful? 0
  • +
  • -

#3 SixOfEleven  Icon User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: Simple C# Dice Game

Posted 04 May 2009 - 04:40 PM

View Postpapuccino1, on 4 May, 2009 - 03:09 PM, said:

What do you need help with?


I think the problem is trying to figure out how to make the loops. Wasn't sure so I didn't reply. :D
Was This Post Helpful? 0
  • +
  • -

#4 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 63
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: Simple C# Dice Game

Posted 04 May 2009 - 05:19 PM

View Postitsme8018, on 4 May, 2009 - 12:48 PM, said:

Hey all

I've got this dice game that i'm trying to make. It basically a dice version of golf. Each player rolls 3 dice until they roll a double. Each roll before the double is achieved counts as a stroke. Once a double is rolled i want the score for that hole to be displayed on the console.

At the moment im still working with notepad and the basic SDK command prompt as this is all i understand.

I've attempted some of the code so far but would really appreciate some help finishing it off (in simple terms if possible)

Thanks in advance!


using System;

namespace dicegame1
{

public static void Main()
{
	Random ran = new Random();
	
	int player1 = 0;
	int player2 = 0;
	int player1RoundScore = 0;
	int player2RoundScore = 0;
	
	bool player1RoundScore = false;
	bool player2RoundScore = false;
	
	int roundNumber = 1;
	
	// Random dice rolling //
	{
	int diceOne = ran.Next(1,7);
	int diceTwo = ran.Next(1,7);
	int diceThree = ran.Next(1,7);
	}
	{
	if (diceOne == diceTwo || diceTwo == diceThree || diceOne == diceThree)
	}
	
}
}



If I'm not mistaken I think you could wrap the random dice rolling between a do while loop. I'm too drunk right now to type in some code. Don't ask me how I have impecable writing though. xD

Edit: I'm gonna pop another cold one in about 2 sexonds.

This post has been edited by papuccino1: 04 May 2009 - 05:27 PM

Was This Post Helpful? 0
  • +
  • -

#5 itsme8018  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-May 09

Re: Simple C# Dice Game

Posted 05 May 2009 - 04:25 AM

Hey, Thanks for your replies

A loop so the dice keep rolling until i roll a double sounds cool, how would i do this? and how would i get the score for each player (i.e number of rolls before a double) to display on the console?

Is there anything else i need to do to complete this cos i thought i needed to do loads but i may be mistaken?

Any snippets of code you can provide would be greatly appreciated! :)
Was This Post Helpful? 0
  • +
  • -

#6 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 63
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: Simple C# Dice Game

Posted 05 May 2009 - 04:52 AM

Hi there, hang over done with now.

while (VictoryStatus == false)
{
	  // Place your dice throwing here dude.

		 // if (any dice equals victory)
					VictoryStatus = true;
}



That should work, and it looks incredibly sexy. The VictoryStatus thing is a boolean variable.

This post has been edited by papuccino1: 05 May 2009 - 04:53 AM

Was This Post Helpful? 0
  • +
  • -

#7 frostyraver  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 195
  • Joined: 21-April 09

Re: Simple C# Dice Game

Posted 06 May 2009 - 10:38 AM

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Doubble_Roll
{
	class Program
	{
		static void Main(string[] args)
		{
			// Int previous roll
			int previousroll;
			int randomnumber;
			int count = 0;

			//Set up randomizer
			Random randy = new Random((int)DateTime.Now.Ticks);

			previousroll = randy.Next(0, 10);
			Console.WriteLine("This will count and finish when it hits a different number.");
			Console.Write("The number to be the same is: " + previousroll);
			Console.ReadLine();

			// Do loop untill number = previous roll
			do
			{
				count++;
				randomnumber = randy.Next(0, 10);
				Console.WriteLine("Number is: "+randomnumber);
				if (randomnumber == previousroll)
				{
					randomnumber = previousroll;
				}
			} while (previousroll != randomnumber);

			// Display output while finished
			Console.WriteLine("------------------------------");
			Console.WriteLine("Inital number is: " + previousroll);
			Console.WriteLine("The number rolled it: " + randomnumber);
			Console.Write("It took " + count + " rolls to achive this!");
			Console.ReadLine();
		}
	}
}



I think this is what you were trying to achieve, hell, I even added a counter in for you :).

This post has been edited by frostyraver: 06 May 2009 - 11:00 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1