Click here to Skip to main content
15,887,341 members
Home / Discussions / C#
   

C#

 
AnswerRe: Fill a datagridview using two data sources Pin
Eddy Vluggen16-May-13 3:03
professionalEddy Vluggen16-May-13 3:03 
GeneralRe: Fill a datagridview using two data sources Pin
geralson16-May-13 3:52
geralson16-May-13 3:52 
AnswerRe: Fill a datagridview using two data sources Pin
Eddy Vluggen16-May-13 4:12
professionalEddy Vluggen16-May-13 4:12 
GeneralRe: Fill a datagridview using two data sources Pin
Pete O'Hanlon17-May-13 3:11
mvePete O'Hanlon17-May-13 3:11 
QuestionC# AND DATABASE Pin
DatabaseShah15-May-13 19:59
DatabaseShah15-May-13 19:59 
AnswerRe: C# AND DATABASE PinPopular
Pete O'Hanlon15-May-13 20:36
mvePete O'Hanlon15-May-13 20:36 
AnswerRe: C# AND DATABASE Pin
Abhinav S16-May-13 8:24
Abhinav S16-May-13 8:24 
Questionhow to move picture box depending on a random dice number Pin
salhamaideh15-May-13 14:08
salhamaideh15-May-13 14:08 
hey guys i'm making a ladder and snake game using C# and i'm stuck at the point where i need to move my players forward .. which means that the players move correctly only in round 1 but after that they start going backwards .
for example for player one the first turn the dice showed number 4 so it moved to square 4 , in second round the dice showed number 2 the player goes back to number two and not to number 6 as it's suppose to .. so can you help me with that i would really appreciate it
this is my code so far :

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 ladder__snake
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//variables to hold the players locations

int blueposition = 1;
int redposition = 1;
int round = 0;
bool drawbg = false;


Point[] squares = new Point[26];


public void main()
{
//array for the squares
squares[0] = new Point(50, 450);
squares[1] = new Point(150, 450);
squares[2] = new Point(250, 450);
squares[3] = new Point(350, 450);
squares[4] = new Point(450, 450);
squares[5] = new Point(450, 350);
squares[6] = new Point(350, 350);
squares[7] = new Point(250, 350);
squares[8] = new Point(150, 350);
squares[9] = new Point(50, 350);
squares[10] = new Point(50, 250);
squares[11] = new Point(150, 250);
squares[12] = new Point(350, 250);
squares[13] = new Point(350, 250);
squares[14] = new Point(450, 250);
squares[15] = new Point(450, 150);
squares[16] = new Point(350, 150);
squares[17] = new Point(250, 150);
squares[18] = new Point(150, 150);
squares[19] = new Point(50, 150);
squares[20] = new Point(50, 50);
squares[21] = new Point(150, 50);
squares[22] = new Point(250, 50);
squares[23] = new Point(350, 50);
squares[24] = new Point(450, 50);
}
private void button1_Click(object sender, EventArgs e)
{
round++;
label3.Text = round.ToString();

//for the blue player dice
Random rnd;
int guess;
rnd = new Random();

guess = rnd.Next(1, 7);

pictureBox1.Image = Image.FromFile(guess.ToString() + ".png");


// Get the Blue player moving


switch (guess)
{
case 1:
bluePlayer.Location = new Point(50, 450);
break;

case 2:
bluePlayer.Location = new Point(150, 450);
break;
case 3:
bluePlayer.Location = new Point(250, 450);
break;
case 4:

bluePlayer.Location = new Point(250, 350);
MessageBox.Show("It's a ladder move to square 8");
break;
case 5:
bluePlayer.Location = new Point(450, 450);
break;
case 6:
bluePlayer.Location = new Point(450, 350);
break;

}




//bluePlayer.Location = squares[blueposition+guess];


//BluePlayer += guess;

//currentPosition1 += guess;
// bluePlayer.Location = squares[BluePlayer+guess];
//guess = 0;
label4.Visible = false;
label5.Visible = true;
label5.Text = "Red Player's turn";
button2.Enabled = true;
button1.Enabled = false;
pictureBox2.Image = Image.FromFile("dice.png");

//blueposition += guess;
//bluePlayer.Location = squares[guess];

}

private void button2_Click(object sender, EventArgs e)
{

//for the red player dice
Random rnd;
int guess;
rnd = new Random();

guess = rnd.Next(1, 7);

pictureBox2.Image = Image.FromFile(guess.ToString() + ".png");
//redposition += guess;






switch (guess)
{
case 1:
redPlayer.Location = new Point(50, 445);
break;

case 2:
redPlayer.Location = new Point(150, 445);
break;
case 3:
redPlayer.Location = new Point(250, 445);
break;
case 4:

redPlayer.Location = new Point(250, 350);
MessageBox.Show("It's a ladder move to square 8");
break;
case 5:
redPlayer.Location = new Point(450, 445);
break;
case 6:
redPlayer.Location = new Point(450, 345);
break;
}
label5.Visible = false;
label4.Visible = true;
label4.Text = "Blue Player's turn";

button2.Enabled = false;
button1.Enabled = true;
pictureBox1.Image = Image.FromFile("dice.png");

}

private void groupBox2_Enter(object sender, EventArgs e)
{
if (!drawbg)
{ groupBox2.Visible = true; }
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void Form1_Load_1(object sender, EventArgs e)
{
pictureBox1.Image = pictureBox2.Image = Image.FromFile("dice.png");
}












}
}
AnswerRe: how to move picture box depending on a random dice number Pin
dusty_dex15-May-13 15:21
dusty_dex15-May-13 15:21 
Generalplase help me to correct some codes Pin
Member 1005503115-May-13 9:26
Member 1005503115-May-13 9:26 
GeneralRe: plase help me to correct some codes Pin
dusty_dex15-May-13 9:49
dusty_dex15-May-13 9:49 
GeneralRe: plase help me to correct some codes Pin
Emmanuel Medina15-May-13 10:03
professionalEmmanuel Medina15-May-13 10:03 
GeneralRe: plase help me to correct some codes Pin
Jegan Thiyagesan16-May-13 1:46
Jegan Thiyagesan16-May-13 1:46 
QuestionInheritance WinForms Pin
Cynizm15-May-13 6:12
Cynizm15-May-13 6:12 
AnswerRe: Inheritance WinForms Pin
Pete O'Hanlon15-May-13 6:24
mvePete O'Hanlon15-May-13 6:24 
GeneralRe: Inheritance WinForms Pin
Cynizm15-May-13 6:59
Cynizm15-May-13 6:59 
GeneralRe: Inheritance WinForms Pin
Pete O'Hanlon15-May-13 7:15
mvePete O'Hanlon15-May-13 7:15 
GeneralRe: Inheritance WinForms Pin
Cynizm15-May-13 7:25
Cynizm15-May-13 7:25 
GeneralRe: Inheritance WinForms Pin
lukeer15-May-13 21:20
lukeer15-May-13 21:20 
AnswerRe: Inheritance WinForms Pin
Dave Kreskowiak15-May-13 6:53
mveDave Kreskowiak15-May-13 6:53 
GeneralRe: Inheritance WinForms Pin
Cynizm15-May-13 7:04
Cynizm15-May-13 7:04 
GeneralRe: Inheritance WinForms Pin
Dave Kreskowiak15-May-13 12:42
mveDave Kreskowiak15-May-13 12:42 
AnswerRe: Inheritance WinForms Pin
Abhinav S15-May-13 7:56
Abhinav S15-May-13 7:56 
QuestionConsuming REST service from C# code Pin
Subin Mavunkal15-May-13 4:21
Subin Mavunkal15-May-13 4:21 
AnswerRe: Consuming REST service from C# code Pin
Abhinav S15-May-13 7:52
Abhinav S15-May-13 7:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.