Click here to Skip to main content
15,896,118 members
Home / Discussions / C#
   

C#

 
AnswerRe: I don't understand your q very well, but.. Pin
Masaaki Onishi19-Nov-02 19:20
Masaaki Onishi19-Nov-02 19:20 
GeneralSplit string by string Pin
dezoe19-Nov-02 6:43
dezoe19-Nov-02 6:43 
GeneralRe: Split string by string Pin
leppie19-Nov-02 11:12
leppie19-Nov-02 11:12 
GeneralRe: Split string by string Pin
Eric Gunnerson (msft)19-Nov-02 11:25
Eric Gunnerson (msft)19-Nov-02 11:25 
GeneralRe: Split string by string Pin
dezoe19-Nov-02 12:41
dezoe19-Nov-02 12:41 
QuestionEnabled ForeColor? Pin
Delegate19-Nov-02 6:41
Delegate19-Nov-02 6:41 
GeneralSqlReader.GetValues() problem Pin
leppie19-Nov-02 6:32
leppie19-Nov-02 6:32 
GeneralRemoving EnhancedMetafile from clipboard fails Pin
gharrison19-Nov-02 5:27
gharrison19-Nov-02 5:27 
GeneralCOM+ Windows API Pin
thematt19-Nov-02 2:52
thematt19-Nov-02 2:52 
GeneralRe: COM+ Windows API Pin
leppie19-Nov-02 11:07
leppie19-Nov-02 11:07 
GeneralRe: COM+ Windows API Pin
thematt20-Nov-02 2:21
thematt20-Nov-02 2:21 
GeneralBinding Collection to Datagrid Pin
thematt19-Nov-02 2:41
thematt19-Nov-02 2:41 
GeneralRe: Binding Collection to Datagrid Pin
leppie19-Nov-02 10:59
leppie19-Nov-02 10:59 
GeneralRe: Binding Collection to Datagrid Pin
thematt20-Nov-02 2:19
thematt20-Nov-02 2:19 
Questionhow to display the image formats (. gif) in crystal reports Pin
crodling18-Nov-02 20:24
crodling18-Nov-02 20:24 
Generalwhere to find basic discuss or tutorial about... Pin
zhoujun18-Nov-02 19:15
zhoujun18-Nov-02 19:15 
GeneralRe: where to find basic discuss or tutorial about... Pin
leppie19-Nov-02 0:08
leppie19-Nov-02 0:08 
GeneralRe: where to find basic discuss or tutorial about... Pin
zhoujun19-Nov-02 13:19
zhoujun19-Nov-02 13:19 
GeneralRandom Numbers Pin
Member 1810818-Nov-02 18:37
Member 1810818-Nov-02 18:37 
GeneralRe: Random Numbers Pin
David Stone18-Nov-02 19:08
sitebuilderDavid Stone18-Nov-02 19:08 
GeneralRe: Random Numbers Pin
Senkwe Chanda18-Nov-02 20:58
Senkwe Chanda18-Nov-02 20:58 
GeneralRe: Random Numbers Pin
Member 1810818-Nov-02 21:49
Member 1810818-Nov-02 21:49 
here's the code for the problem in question

<br />
Class BlockClass<br />
{<br />
  private enum BlockColor<br />
  {<br />
    BLUE,<br />
    GREEN,<br />
    RED<br />
  }<br />
  <br />
  // some more members here<br />
<br />
  private BlockColor ItsColor;<br />
<br />
  public void AssignColor()<br />
  {<br />
    Random rnd = new Random();<br />
    switch (rnd.Next(4))<br />
    {<br />
      case 1 :<br />
        this.ItsColor = BlockColor.BLUE;<br />
        break;<br />
      case 2 :<br />
        this.ItsColor = BlockColor.GREEN;<br />
        break;<br />
      case 1 :<br />
        this.ItsColor = BlockColor.RED;<br />
        break;<br />
  }<br />
<br />
  public BlockClass(Graphics InGraphics, <br />
                         int inSpeed,<br />
                       Point inLocation,<br />
                        bool inTopRow)<br />
  {<br />
    // some other constructor code<br />
    this.AssignColor();<br />
    // some other constructor code<br />
  }<br />
}<br />


basically AssignColor() is only used as part of the object's construction it is called once per BlockClass that is created. I choose to use an enumeration so it would be easy for me to do redraw using another switch statement to either draw the block using basic graphics routines like DrawRectangle() or load a specific image from an imagelist containing the 3 color blocks plus a blank white block for redrawing purposes

to give you an idea how this class is used:

<br />
class BlocksClass<br />
{<br />
  ArrayList TheBlocks = new ArrayList(20);<br />
<br />
  public void LayoutBlocks()<br />
  {<br />
    for(int x = 0;x < 20;x++)<br />
    {<br />
      ArrayList YArray = new ArrayList(20);<br />
      for(int y = 0;y < 20;y++)<br />
      {<br />
        BlockClass Block = new BlockClass(this.Gfx,<br />
                                          this.speed,<br />
                                          new Point((x * 7) + 3,(y * 7) + 3)),<br />
                                          (y == 0))<br />
        YArray.Add(Block);<br />
      }<br />
      this.TheBlocks.Add(YArray)<br />
    }<br />
  }   <br />
}<br />


so basically the program calculates a 20x20 playing board with 7x7 pixel boxes
by filling in the Y rows of a specific X column and then moving on to the next X column and repeating (i did this cause part of the program needs to be able to delete a square and cause those above it to drop down to replace it (figured i set up the array like this it would be easier to parse for this event)

ok now i'm done typing like... working at 3am does that to me i can't shut up i mean look at me...Sleepy | :zzz:
GeneralRe: Random Numbers Pin
James T. Johnson19-Nov-02 14:46
James T. Johnson19-Nov-02 14:46 
GeneralRe: Random Numbers Pin
Member 1810819-Nov-02 20:54
Member 1810819-Nov-02 20:54 
GeneralRe: Random Numbers Pin
LongRange.Shooter19-Nov-02 11:03
LongRange.Shooter19-Nov-02 11:03 

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.