C# Board game

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 6186 Views - Last Post: 05 May 2010 - 10:49 PM Rate Topic: -----

#1 Guest_JeanPaul*


Reputation:

C# Board game

Posted 04 May 2010 - 09:17 AM

To whom it may concern,

I am trying to make a board game but I got no idea from where to start.

The thing im trying to do is that when u press the dice(the dice is a random number) button, the small black box moves according to the number from the random number.
Posted Image


Example.

if when i press the dice 10 pops up. the black box goes on the 10th box.
Posted Image

Thanks in advance,
Jean

Is This A Good Question/Topic? 0

Replies To: C# Board game

#2 MentalFloss  Icon User is offline

  • Not really an expert anymore...
  • member icon

Reputation: 433
  • View blog
  • Posts: 1,157
  • Joined: 02-September 09

Re: C# Board game

Posted 04 May 2010 - 09:44 AM

And... what's the problem?

You haven't given us much to work with here.

Can you show your code that you have so far?
Was This Post Helpful? 0
  • +
  • -

#3 Guest_Jean*


Reputation:

Re: C# Board game

Posted 04 May 2010 - 09:51 AM

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

      
        private void Dice_Click(object sender, EventArgs e)
        {
            Random dice = new Random();
            int dice2 = dice.Next(2, 12);
           

            if (dice2 == 2)
            {
                pictureBox22.Location = pictureBox4.Location;

            }
            if (dice2 == 3)
            {
                pictureBox22.Location = pictureBox5.Location;
            }
            if (dice2 == 4)
            {
                pictureBox22.Location = pictureBox6.Location;
            }
           
       }
    }
}


I need something that when i press the dice a random number from 2-12 will move the picture box to the amount of number

as shown above..

but i need to repeat the sequence..
i can do the first move with ifs from 2-12 but what about if its already on picture box 5?

thanks

This post has been edited by JackOfAllTrades: 04 May 2010 - 10:03 AM
Reason for edit:: Added code tags.

Was This Post Helpful? 0

#4 MentalFloss  Icon User is offline

  • Not really an expert anymore...
  • member icon

Reputation: 433
  • View blog
  • Posts: 1,157
  • Joined: 02-September 09

Re: C# Board game

Posted 04 May 2010 - 09:59 AM

You need to wrap your code in "[code]" tags for future reference.

Anyway, I have a couple more questions.

For the occupied squares, will it always be this black square inside a blue square? Or do you intend to eventually have different colored pieces?

Do you eventually want to make this a fully functional board game with multiple players and such? Or is this simply a small exercise to get a black square to move around a board?
Was This Post Helpful? 0
  • +
  • -

#5 Guest_Jean*


Reputation:

Re: C# Board game

Posted 04 May 2010 - 10:06 AM

View PostMentalFloss, on 04 May 2010 - 08:59 AM, said:

You need to wrap your code in "[code]" tags for future reference.

Anyway, I have a couple more questions.

For the occupied squares, will it always be this black square inside a blue square? Or do you intend to eventually have different colored pieces?

Do you eventually want to make this a fully functional board game with multiple players and such? Or is this simply a small exercise to get a black square to move around a board?


i intend to have 2-4 different pictures pieces. this is just a simulation for the real thing.

Do you eventually want to make this a fully functional board game with multiple players and such? Yes
Was This Post Helpful? 0

#6 MentalFloss  Icon User is offline

  • Not really an expert anymore...
  • member icon

Reputation: 433
  • View blog
  • Posts: 1,157
  • Joined: 02-September 09

Re: C# Board game

Posted 04 May 2010 - 10:21 AM

Then I would make each square on the board intelligent from the start. Then the board would manage each square.

Perhaps this could be a square:

public class Square
{
    public bool IsOccupied { get { return (Occupants.Count > 0); }
    public List<Player> Occupants { get; private set; }

    public int Position { get; private set; }

    public Square(int position)
    {
        Position = position;
        Occupants = new List<Player>();
    }

    public void Occupy(Player player)
    {
        Occupants.Add(player);
    }

    public void Leave(Player player)
    {
        Occupants.Remove(player);
    }
}



Now, since you have the position, you would just swap out the picturebox they are currently on with an empty blue one (like you have above) and then take the dice roll added to their current position and swap that square out with a rendered square that has a player in it.

To accomplish this, maybe the game board would have a dictionary of squares. On the roll, after getting the total, you grab the Square stored at that key and swap it out with an occupied square. Each roll you'd do this.

Does this make sense?

EDIT:
The more I think about this, the more I hate the idea. I think I need to actually make a prototype of this to provide any form of "good" advice.

This post has been edited by MentalFloss: 04 May 2010 - 10:29 AM

Was This Post Helpful? 0
  • +
  • -

#7 Guest_jean*


Reputation:

Re: C# Board game

Posted 04 May 2010 - 10:36 AM

im sry didnt understand nearly anything of that :/
Was This Post Helpful? 0

#8 MentalFloss  Icon User is offline

  • Not really an expert anymore...
  • member icon

Reputation: 433
  • View blog
  • Posts: 1,157
  • Joined: 02-September 09

Re: C# Board game

Posted 04 May 2010 - 11:10 AM

So, each game square is a panel. Each player token is a picturebox. Add the picturebox to the panel and place it based on how many occupants are already there. When a player leaves, reshuffle the layout of the occupants.

Does that make sense?
Was This Post Helpful? 0
  • +
  • -

#9 Guest_Jean*


Reputation:

Re: C# Board game

Posted 04 May 2010 - 11:40 AM

View PostMentalFloss, on 04 May 2010 - 10:10 AM, said:

So, each game square is a panel. Each player token is a picturebox. Add the picturebox to the panel and place it based on how many occupants are already there. When a player leaves, reshuffle the layout of the occupants.

Does that make sense?


The squares are also picture boxes..

let me give u an example....

can i upload to rapidshare and u see the program? in that case here is the .exe program (http://rapidshare.com/files/383527635/WindowsFormsApplication1.exe.html)

The below is an example with manual moving..

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public bool isDragging = false;
        public int oldX, oldY;
        public bool isDragging2 = false;
        public int oldX2, oldY2;
        public Form1()
        {
            InitializeComponent();
            pictureBox22.MouseDown += new MouseEventHandler( pictureBox22_MouseDown);
             pictureBox22.MouseUp += new MouseEventHandler( pictureBox22_MouseUp);
             pictureBox22.MouseMove += new MouseEventHandler( pictureBox22_MouseMove);
             pictureBox22.Cursor = Cursors.Hand;

        }

        #region pictureBox22
        private void  pictureBox22_MouseDown(object sender, MouseEventArgs e)
        {
            isDragging = true;
            oldX = e.X;
            oldY = e.Y;
        }

        private void pictureBox22_MouseMove(object sender, MouseEventArgs e)
        {
            if (isDragging)
            {
                 pictureBox22.Top =  pictureBox22.Top + (e.Y - oldY);

                 pictureBox22.Left = pictureBox22.Left + (e.X - oldX);
            }
        }

        private void pictureBox22_MouseUp(object sender, MouseEventArgs e)
        {
            isDragging = false;


        }
        #endregion
        


        private void Dice_Click(object sender, EventArgs e)
        {
            Random dice = new Random();
            int dice2 = dice.Next(2, 12);
            MessageBox.Show(Convert.ToString(dice2));


        }



    }

}



now i need this to be as i said before.. press the dice a number pop ups example 5.. and the little black square moves 5 spaces on the Blue boxes.
Was This Post Helpful? 0

#10 Guest_jean*


Reputation:

Re: C# Board game

Posted 04 May 2010 - 11:42 AM

An example is the Ludo game if you know what i mean..

and sry for double posting cant edit my own as guest
Was This Post Helpful? 0

#11 MentalFloss  Icon User is offline

  • Not really an expert anymore...
  • member icon

Reputation: 433
  • View blog
  • Posts: 1,157
  • Joined: 02-September 09

Re: C# Board game

Posted 04 May 2010 - 11:50 AM

No, I'm telling you to make the squares panels because they can maintain a collection of controls (which will be your picturebox players).

Here is an attached demo. Excuse any code bugs that pop up. It was a quick slap together.

The demo is a form with a panel on it. There are 4 buttons which each represent a color. When you press a button, it populates the square with that color by creating a picturebox and adding it to the panel. Just imagine that the whole board game is a collection of these panels.

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#12 Guest_Jean*


Reputation:

Re: C# Board game

Posted 04 May 2010 - 12:03 PM

View PostMentalFloss, on 04 May 2010 - 10:50 AM, said:

No, I'm telling you to make the squares panels because they can maintain a collection of controls (which will be your picturebox players).

Here is an attached demo. Excuse any code bugs that pop up. It was a quick slap together.

The demo is a form with a panel on it. There are 4 buttons which each represent a color. When you press a button, it populates the square with that color by creating a picturebox and adding it to the panel. Just imagine that the whole board game is a collection of these panels.

yes i understood what u meant but i dont know how i could use this into my requirements.

This is due to the fact that i dont want the panel to change the colour.. as each picturebox(example the blue boxes) will have its own name written on it...

Lets try working from scratch as this is not going the way i intend to go...

is there a way i could contact u directly example .. skype/xfire/msn/googletalk anything else?

Thanks for your patience.
Was This Post Helpful? 0

#13 MentalFloss  Icon User is offline

  • Not really an expert anymore...
  • member icon

Reputation: 433
  • View blog
  • Posts: 1,157
  • Joined: 02-September 09

Re: C# Board game

Posted 04 May 2010 - 12:09 PM

No. Just post your requirements in full on here and we'll go from there. You'll have the benefit of all users viewing it instead of just me.
I simply don't have time to work that heavily on this project with you at this time. Sorry.
Was This Post Helpful? 0
  • +
  • -

#14 Guest_Jean*


Reputation:

Re: C# Board game

Posted 04 May 2010 - 12:13 PM

View PostMentalFloss, on 04 May 2010 - 11:09 AM, said:

No. Just post your requirements in full on here and we'll go from there. You'll have the benefit of all users viewing it instead of just me.
I simply don't have time to work that heavily on this project with you at this time. Sorry.


Oh, k. I'm sry.

K then.

First of all did u see the rapidshare link i gave? and did u run it..

I just need that to work automatically each time i press the dice.

Example:
1) Press Dice.(example: 5)
2) Move Black Box 5 spaces into Blue Box (Blue Box No.5)
3) Press Dice.(example: 6)
4) Move Black Box 6 spaces into Blue Box (Blue Box No.11)

Do you understand what I am trying to explain?

Right now im just dragging the Black Box according to the dice number.

Thanks,
Jean
Was This Post Helpful? 0

#15 MentalFloss  Icon User is offline

  • Not really an expert anymore...
  • member icon

Reputation: 433
  • View blog
  • Posts: 1,157
  • Joined: 02-September 09

Re: C# Board game

Posted 04 May 2010 - 12:17 PM

This is a requirement:

Quote

This is due to the fact that i dont want the panel to change the colour.. as each picturebox(example the blue boxes) will have its own name written on it...


You have to provide all of these little nuances and such. Otherwise, the solution is going to deviate from your needs because you left stuff out. So, edit your post with full requirements.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2