Hi
I have a problem with dice game.
So I have a dice game , but I want to see the picture of the dice every time the player throws the dice not only the number..
I dont know how to make it, do I need to rewrite the random function? Or i can keep it and write there something like if dice number=1 then console.writeline picture?
Anyway here is the code I hope someone can help me :) and sorry for my bad English.

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

namespace DiceGame
{
    class Program
    {
        static void Main(string[] args)
        {Random r = new Random();
            int points1 = 0, points2 = 0;
            int game1 = 0, game2 = 0, number = 0;
            do
            {
                Console.Clear();
                Console.WriteLine("Player 1:");
                for (int i = 0; i < 4; i++)
                {
                    number = r.Next(1, 7);
                    Console.WriteLine(number);
                    game1 += number;
                }
                Console.WriteLine("=" + game1.ToString() + "\n");
                Console.WriteLine("Player 2:");
                for (int i = 0; i < 4; i++)
                {
                    number = r.Next(1, 7);
                    Console.WriteLine(number);
                    game2 += number;
                }
                Console.WriteLine("=" + game2.ToString() + "\n");
                if (game1 > game2)
                {
                    Console.WriteLine("Player  1 wins");
                    points1++;
                }
                else
                {
                    Console.WriteLine("Player  2 wins");
                    points2++;
                }
                Console.WriteLine("Player 1: " + points1.ToString() + " Player 2: " + points2.ToString());
                Console.WriteLine("Write: 'end' to quit the game, everything else to continue.");
            } while (!(Console.ReadLine().ToLower() == "end"));
            Console.Clear();
            Console.WriteLine("Player 1: " + points1.ToString() + " Player 2: " + points2.ToString());
            Console.WriteLine(((points1 > points2) ? "Player  1 wins'" : "Player  2 wins!") + " Congratulations!");
        
        }
    }
}

I would suggest you implement a DrawDice() method that takes a number as an argument, and draws the dice accordingly. Then you can call it with your random number :)

If you wanna see the image put some images (those you need9 into project - into the Resources).
Then you can create a switch statement, and based on an integer you will show appropriate image.
Or simply create an image from some file on the disc (by specifing the path to the image)

like:

int num = 1; //pass value to this variable
            Image img;
            switch (num)
            {
                case 1:  img = Bitmap.FromFile("path to image 1"); break;
                case 2: img = Bitmap.FromFile("path to image 2"); break;
                case 3: img = Bitmap.FromFile("path to image 3"); break;
                //and so on..
            }

This code will be used AFTER you will get the number (from 1 to 6) from some random class.
And use the image on the control (on some button and background image).

Edited 4 Years Ago by Mitja Bonca: n/a

ddanbe : Thats not the problem I have the dice drawn ... but thanks :)
skatamic: Well I must say I really dont know how to do what you just said Im just a beginner in C# so this dont help me a lot ... I know that I need to make a public void draDice but then I dont know...

If you wanna see the image put some images (those you need9 into project - into the Resources).
Then you can create a switch statement, and based on an integer you will show appropriate image.
Or simply create an image from some file on the disc (by specifing the path to the image)

like:

int num = 1; //pass value to this variable
            Image img;
            switch (num)
            {
                case 1:  img = Bitmap.FromFile("path to image 1"); break;
                case 2: img = Bitmap.FromFile("path to image 2"); break;
                case 3: img = Bitmap.FromFile("path to image 3"); break;
                //and so on..
            }

This code will be used AFTER you will get the number (from 1 to 6) from some random class.
And use the image on the control (on some button and background image).

Thank you very much this is exactly what I need :)

If you wanna see the image put some images (those you need9 into project - into the Resources).
Then you can create a switch statement, and based on an integer you will show appropriate image.
Or simply create an image from some file on the disc (by specifing the path to the image)

like:

int num = 1; //pass value to this variable
            Image img;
            switch (num)
            {
                case 1:  img = Bitmap.FromFile("path to image 1"); break;
                case 2: img = Bitmap.FromFile("path to image 2"); break;
                case 3: img = Bitmap.FromFile("path to image 3"); break;
                //and so on..
            }

This code will be used AFTER you will get the number (from 1 to 6) from some random class.
And use the image on the control (on some button and background image).

I don't think this will work in a console application...

I don't think this will work in a console application...

nope, images will not do in console. Didnt even noticed that apparently. Only read his post.

This question has already been answered. Start a new discussion instead.