|
I'm making a solitaire game and figured out that the shuffle code doesn't show the Image1(0) card when the cards are shuffled in the design view. So that is one problem. I also am trying to drag and drop images from image1(0) to 12 from the left hand side of the design view to the right hand side where hearts(0) cards are. One thing, the hearts cards already have other bitmaps on them; they are blank boxes to show up for the person playing to automatically drop the image1 card in that slot. Here's what my newbie experience is so far...Oh, I also made tags in the design view to think they might help out.
Public Sub Main()
Start_Game.Show
End Sub
Private Sub Exit_Click()
MsgBox ("Thank you for playing. Good Bye.")
End
End Sub
Private Sub Start_Click()
Dim arrDeck(52)
Randomize
Dim Cardcount As Integer
Dim Counter As Integer
Dim Card1 As Integer
Dim Card2 As Integer
' Fill deck with cards in order 1 to 52
Do While Cardcount <= 52
arrDeck(Cardcount) = Cardcount
Cardcount = Cardcount + 1
Loop
' Shuffle the deck - end value (100)
Dim Temp As Image
Dim Index As Integer
For Index = 0 To 51
For Counter = 0 To 100
Card1 = Int(51 * Rnd)
Card2 = Int(51 * Rnd)
If (Card1 <> Card2) Then
Temp(Index).Picture = Image1(Card1).Picture
Image1(Card1).Picture = Image1(Card2).Picture
Image1(Card2).Picture = Temp(Index).Picture
End If
Next Index
Next Counter
' Now output images in order
For Counter = 0 To 51
Image1(Counter).Visible = True
Next Counter
End Sub
Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
Private Sub Image1_Click(Index As Integer)
If Image1(Index).Tag = Hearts(Index).Tag Then
Image1(Index).Picture = Hearts(Index).Picture
Hearts(Index).Picture = Source.Picture
Image1(Index).Visible = False
End If
Next
End Sub
End Sub
|
|
|
|
|
|
Here is one problem:
Card1 = Int(51 * Rnd)
This will give you a random number with 51 possible values, i.e. from 0 to 50. That means that you are never touching the last card in the deck.
You are doing 100 times as much work as you need to in order to shuffle the deck. You don't have to make more than 51 swaps to completely shuffle the deck, you just have to make sure that each card has an equal chance to be swapped into each position in the deck:
For card1 = 0 To 50
card2 = card1 + Int((52 - card1) * Rnd)
If card1 <> card2 Then
Temp = Image1(card1).Picture
Image1(card1).Picture = Image1(card2).Picture
Image1(card2).Picture = Temp
End If
Next Index
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thank you for your comment, however, I did try 0 to 50 and 52 *RND first; It still has the same effect. I lose the Image1(0) card; the King of Hearts. If I use Temp as an Image for tghe shuffle it does not work. Says it is not a proper variable or is not set as one ; I try set command and that doesn't work. I try Image1(0).Picture in place of temp and I lose the King of Hearts card too of course; hence Image1(0). How do I shuffle the images with using a third variable for the shuffle correctly and not lose any cards at run time at display of images? Much appreciation in advance.
|
|
|
|
|
maybe you'll have to use a clone ?
Jarno Burger
Video Jockey
|
|
|
|
|
You know, maybe that's the key; I'll try that and let y'all know. Thanks.
|
|
|
|
|
Well, that was it! Thank you for the suggestion. I made a clone, made it invisible and used it in the swap, like this:
f (posn1 z<> posn2) Then
KingH(0).Picture = Image1
posn1).Picture
Image1(posn1).Picture = Image1(posn2).Picture
Image1(posn2).Picture = KingH(0).Picture
|
|
|
|
|
yeah ! cool !
whahoo ! we solved it !
Jarno Burger
Video Jockey
|
|
|
|
|
Yep we did; thanks!
I have another question. Trying to move the image1(12) card (drag and drop) to the hearts(12) card. Testing to see if the tags are equal first, which they are set in design view, then setting the same image bitmap of image1(12) card over (dropped on) the blank image of hearts(12) card. What happens at run time is ALL the cards 0 - 12 of image1 can only be dropped in hearts(12) spot. None of the other cards in the image1 stack (up to 52, remember, I'm just doing a sample first) can be dropped over the hearts cards, but no "shirley" error message pops up either. Any suggestions?
Pardon the format; just testing now
'Private Sub Image1_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
'Image1(Index).Picture = Source.Picture
'End Sub
Private Sub Hearts_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
'Dim ImageIndex As Integer
Dim HeartsPic0 As Image
HeartsPic0.Picture = Source.Picture
Source.Picture = LoadPicture("C:\Program1\013h.gif")
If Image1(12).Tag = Hearts(12).Tag Then
Hearts(12).Picture = HeartsPic0.Picture
Else
MsgBox ("You're wrong Shirley")
Exit Sub
End If
End Sub
|
|
|
|
|
.tag is normally object. comparing object with object sometimes work. but to be sure , do a ctype(image(x).tag , string/integer/double/your class type ) first. Your watch window in visual studio does some neat tricks to show you what is in the tags. But the bad thing is , that your code doesn't know, only that watch-window does (thats called reflection).
You have to "convert the object back to your type of class"->ctype(thingie , class-type) . Just to make sure your tag is ok.
And maybe Debug.WriteLine all the tag info constantly to your debugger window. Maybe something goes wrong somewhere else , working with tags , (that could behave like any object) , can be tedious.
In your case , are your tags your game-data , or are there other array's of stuff with game-data ? Try to make a mental split-up of game-data and interface. Build a 'huge' game-data class .
You'll add / remove / update /load / save / (de)serialize your gamedata. In that way , maybe in the future you only have to type in the intermediatewindow or debugwatcher :'gamedata.show' , to show all the gamedata in one list in the debugwindow or debugwatcher.
Later in the future you can remember multiple "states" of gamedata , to have a undo/replay function.
Jarno Burger
Video Jockey
|
|
|
|
|
Hi.
I have a textbox that is constantly updated line by line from a process.startinfo... thingy. The text pasted in the textbox is actully console application output.
What i need is a string variable that always holds the last line from the textbox when its updating (new lines are added).
Does anyone know how i can do that?
http://www.themightyatom.nl
|
|
|
|
|
Hi,
assuming your other process is outputting lines of text (lines separated by NewLine) then it isn't very wise to (1) concatenate all of them since that is what a TextBox needs, and (2) then try to find the last line again.
For starters, remember the most recent line where it comes in (maybe in a Process.OutputDataReceived handler?) i.e. before it gets concatenated; and then maybe drop the Textbox, i.e. if you are not relying on the wrapping capabilities of a textbox, then use a ListBox instead. It is both easier and faster.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Well, the process that im running is a compilation process with its output redirected to a textbox, and i'd like to use regular expressions later to colorize error and warning messages.
I already have a sub that is fired when a new line is added to the textbox, i just need a string variable to hold the last pasted line. I need to compare something. Its hard to explain, unless you know what level design for the game Half-Life is all about...
Ill experiment with a listbox.
http://www.themightyatom.nl
|
|
|
|
|
Hi,
if your ListBox output needs some formatting, then you have to paint the content yourself: switch its DrawMode to one of the "OwnerDrawn" values and provide a DrawItem handler, wich can be as simple as
public void lb_DrawItem(object sender, DrawItemEventArgs e) {
ListBox lb=sender as ListBox;
int index=e.Index;
if (index<0 || index>=lb.Items.Count) return;
string s=(string)lb.Items[index];
e.DrawBackground();
g.DrawString(s, font, brush, e.Bounds);
}
assuming each line uses a single format (you need to provide some font and brush; if you create them inside the DrawItem handler, don't forget to dispose them too).
BTW: one nice characteristic of the ListBox is it only calls DrawItem for the lines that are actually visible, so when thousands of lines are present, but only 25 or so are visible at any given time, only those 25 will fire the DrawItem colorization and painting.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
what did for my debugger , put every given string in a array with a fixed length.
when there was a new string , i fisrt moved every string one position in the array , meaning that the first one would be dumped.
FIFO.
a array with strings was a lot easier to edit/view.
you could also use a queue , but i love to build stuff myself , loving hobby code
Jarno Burger
Video Jockey
|
|
|
|
|
Hmmm... this is tough.
I tried a listbox to display the output, and it works fine, even better than a textbox.
But what really annoys me is that a listbox does not allow you to colorize specific items (fore and backcolor). It also flickers like crazy. So was thinking, are there custom listbox controls out there with the exact same functionalities is the stock listbox, only with the added ability to colorize the backcolor and/or forecolor of specific listbox items?
I google like crazy today but found squat.
http://www.themightyatom.nl
modified on Thursday, May 28, 2009 12:51 PM
|
|
|
|
|
I don't think there are such list boxes. I would stay with the textbox or use Scintilla.NET http://www.codeplex.com/ScintillaNET[^] it has syntax colloring built in.
To get the last line, search backwards to the first cr/lf and you got your line.
Good luck: Didi
|
|
|
|
|
Yeah i think so, i already found a custom listbox control that supports item colors, but it flickers like crazy when items are added in a short timespan.
Ill try that ScintillaNET thingy. If i understand correctly, this is a pack with new/updated controls with new features?
http://www.themightyatom.nl
|
|
|
|
|
You could use BeginUpdate and EndUpdate on your control before and after the adding of items (that works on most controls). Yes Scintilla.NET is a pack with controls in it...
Regards: Didi
|
|
|
|
|
I tried the beginupdate and endupdate, but i want the user to actually see the process.
As for Scintilla.NET, it only adds four unkown controls to the toolbox. I don't know how i could use that with my textbox. Plus, it makes my Visual Studio crash. :/
http://www.themightyatom.nl
|
|
|
|
|
you don't use it with your textbox, but instead of. Find documentation on Scintilla Documentation[^] Scintilla.Net is a wraper of Scintilla, a c++ rich text control with sintax highliting etc.
What exactly do you do, just before your VS crashes?
|
|
|
|
|
Nevermind, im not going to use it, too complicated for me.
Ill just stick to a richtextbox.
If i just could find a way to get the last line of that constantly updating textbox, i may just get it to work.
Syntax highlighting using regex isn't the problem, i know how to do it.
http://www.themightyatom.nl
|
|
|
|
|
To get the last line, search backwards to the first cr/lf and you got your line. Find info here[^]
Good luck: Didi
|
|
|
|
|
Hi,
This is Alokesh,I am unable to insert any kind of image in menubar control in VB.net. Please tell how can I do it? Your quick response will be earnestly solicited.
With Thanks and regards,
Alokesh
DBS, Chennai
|
|
|
|
|
Hi, This is E.T.
Use the image property and select the file you want to use in the import box. Make sure the image you are trying to use is a supported format (which are listed int he Files of type combo).
Cheers!
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|