TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Prime b
NA
810
345.9k
How to add random with an int
Oct 18 2012 4:11 PM
I am doing this lab from Head First C# book
there's 4 dogs and 3 dudes who can bet on those dogs.
dogs will move at random so i have to use random generator.
My question is how do I update the form through the Run() method?
======================Book==========================
class Greyhound {
public int StartingPosition; // Where my PictureBox starts
public int RacetrackLength; // How long the racetrack is
public PictureBox MyPictureBox = null; // My PictureBox object
public int Location = 0; // My Location on the racetrack
public Random Randomizer; // An instance of Random
public bool Run() {
// Move forward either 1, 2, 3 or 4 spaces at random
// Update the position of my PictureBox on the form
// Return true if I won the race
}
public void TakeStartingPosition() {
// Reset my location to the start line
============My Work=========================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TheRace
{
class Greyhound
{
public int StartingPosition;
public int RacetrackLength;
public PictureBox MyPictureBox = null;
public int Location = 0;
public Random Randomizer = new Random();
public bool Run()
{
Location = StartingPosition + Randomizer.Next(1,4);
}
public void TakeStartingPoisition()
{
}
}
Reply
Answers (
1
)
What is a "Friendless Class" in C#? I heard someone refer to it but I googled it online and found nothing.
Connection must be valid and open