Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Would This Work?


  • Please log in to reply
15 replies to this topic

#1 Wolfy87

Wolfy87

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:48 AM

Posted 01 October 2008 - 10:08 AM

int[] mapstatic;
int[] value;

private void GenerateMap_click (object sender,EventArgs e)
{
  form2 form2 = new form2();
  form2.Show();
  form2 form2 =(form2)Application.OpenForms();
  mapstatic = new int[25];
  Random mapgenerator = new Random();
  value = new int[1]
  value[0] = 0;
  1:
  value[0] = (value[0] + 1);
  mapstatic[value] = mapgenerator.Next(1, 5);
  if (value[0] == 25)
	  goto 2;
  goto 1
  2:
  timer1.Value = 1000;
  timer1.Start();
}

private void timer1_tick (object sender,EventArgs e)
{
  int[] loc;
  loc = new int[1]
  loc[0] = 0;
  int[] number;
  number = new int[1];
  number[0] = 1;
  1:
  form2.loc(loc[0]).Image = ("ground" + mapstatic[number].ToString + ".png");
  if (number == 3)
  number[0] = (number[0] + 1);
  loc[0] = (loc[0] + 1)
  if (loc == 26)
	   goto 2
  goto 1
  2:
}

PlyPencil has helped me with this at school and i have based it on the engin for his tile generator in his game, but i would like to know wether it would work or not (Proboly not) and i would also like to know wether the goto function is being used correctly? I could do it another way but this saves alot of writing and memory...ok not to much memory.

Many thanks =],
Wolfy87.

BC AdBot (Login to Remove)

 


m

#2 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:48 AM

Posted 01 October 2008 - 10:36 AM

Ok, refined it a bit to a pice of code that runs...
namespace MapTest
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}
		int[] mapstatic;
		int[] value;

		private void button1_Click(object sender, EventArgs e)
		{
			mapstatic = new int[25];
			value = new int[1];
			value[0] = 0;
			Random mapgenerator = new Random();
		 bookmark1:
			value[0] = (value[0] +1);
			mapstatic[value[0]] = mapgenerator.Next(1, 5);
			if (value[0] == 26)
				goto bookmark2;
			goto bookmark1;
		bookmark2:
			int[] loc;
			loc = new int[1];
		}
	}
}

Ive only got that bit so far though but still dosent work properly

#3 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:48 AM

Posted 01 October 2008 - 10:48 AM

What do you expect it to do? At any point have you written any code that does anything when you click on a button?

#4 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:48 AM

Posted 01 October 2008 - 10:57 AM

Yes im sorry if i havent made it clear...it was a bit of a stupid post...
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 MapTest
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}
		int[] mapstatic;
		int[] value;

		private void button1_Click(object sender, EventArgs e)
		{
			mapstatic = new int[25];
			value = new int[1];			
			Random mapgenerator = new Random();
		 mylabel1:
			mapstatic[(value[0])] = mapgenerator.Next(1, 5);
			value[0] = (value[0] + 1);
			if (value[0] == 25)
				goto mylabel2;
			goto mylabel1;			
		mylabel2:
			int[] loc;
			loc = new int[1];
			loc[0] = 0;
			int[] number;
			number = new int[1];
			number[0] = 1;
		mylabel3:
			loc(loc[0]).Image = ("ground" + mapstatic[(number[0])] + ".png");  <<<< this is the only non working part...
			number[0] = (number[0] + 1);
			loc[0] = (loc[0] + 1);
			if (loc[0] == 26)
				goto mylabel3;
			goto mylabel4;
		mylabel4:
			this.Refresh();
		}
	}
}

In the first part i generate 25 random numbers between 1, 5. in the second part according to the numbers it loads the corrosponding image into the corrosponding picture box but the <<<< part above is the only part that wont work now...

It just sort of generates a different looking map each time..not much point in it its just a test.

#5 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:48 AM

Posted 01 October 2008 - 10:59 AM

I have 25 image boxes called "loc1" and "loc2" etc etc all the way up to "loc25"

Slightly more refined -.-...

namespace MapTest
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}
		int[] mapstatic;
		int[] value;

		private void button1_Click(object sender, EventArgs e)
		{
			mapstatic = new int[25];
			value = new int[1];			
			Random mapgenerator = new Random();
		 mylabel1:
			mapstatic[(value[0])] = mapgenerator.Next(1, 5);
			value[0] = (value[0] + 1);
			if (value[0] == 25)
				goto mylabel2;
			goto mylabel1;			
		mylabel2:
			int[] location;
			location = new int[1];
			location[0] = 0;
			int[] number;
			number = new int[1];
			number[0] = 1;
		mylabel3:
			(loc + (location[0])).Image = ("ground" + mapstatic[(number[0])] + ".png");   <<<<< this still dose not work...
			number[0] = (number[0] + 1);
			location[0] = (location[0] + 1);
			if (location[0] == 26)
				goto mylabel3;
			goto mylabel4;
		mylabel4:
			this.Refresh();			
		}
	}
}

Edited by Wolfy87, 01 October 2008 - 11:02 AM.


#6 PlyPencil

PlyPencil

  • Members
  • 51 posts
  • OFFLINE
  •  
  • Local time:11:48 AM

Posted 01 October 2008 - 12:23 PM

Logically its sound, its just checking that goto function exists :thumbsup:

#7 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:48 AM

Posted 01 October 2008 - 12:26 PM

Yep it dose :thumbsup: i tryed it and the goto works fine its just the bit with the <<<<< thats not working and its because it cant find loc1 because its not saying loc1 its saying loc + the value of location[0]. the only way around this is if i write them all seperately.

#8 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:48 AM

Posted 01 October 2008 - 12:42 PM

loc1 its saying loc + the value of location[0].

Of course it is, because that is what you are telling it to do; take the value stored in loc and add it to the value location[0]. Presumably you really want loc to be a string, and you want to concatenate it with whatever value is contained in location[0] (as a string also). If you were paying attention to your compiler, it would tell you that loc has not been initialized.

So actually, the logic is not sound. :thumbsup:

#9 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:48 AM

Posted 01 October 2008 - 01:03 PM

No i don not want it to ba a string, i am refering to the image box 'loc1' the the '1' will be added on by one to then assign the image to 'loc2' (the image box one in from the bottem left) and so on. This is why it wont work so i will have to just write them seperately.

#10 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:04:48 AM

Posted 01 October 2008 - 01:20 PM

Have it your way. You still have not initialized a variable called loc, and therefore the code will not work as is.

What do I know. I just do this for a living. :thumbsup:

#11 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:48 AM

Posted 01 October 2008 - 01:29 PM

loc is not ment to be a vairiable :thumbsup:
it is the start of an image boxes name that is then added to the number in location[0] to give the full name of it i.e. the coordinate. but it will not work because it is recognising this first part of it as a string / variable which i dont want it to, i want it to see it as one word/command not two

#12 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,301 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:03:48 AM

Posted 01 October 2008 - 01:35 PM

While the GoTo is usable in C#, it should be avoided. More info on why here:
http://en.wikipedia.org/wiki/Goto#Criticism_of_goto_usage

Yep it dose i tryed it and the goto works fine its just the bit with the <<<<< thats not working and its because it cant find loc1 because its not saying loc1 its saying loc + the value of location[0]. the only way around this is if i write them all seperately.

Yes, you have to write them all seperately. If you want to loop through them all you have to push them into an array and loop through that; you can not loop identifers in CSharp.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#13 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:48 AM

Posted 01 October 2008 - 01:45 PM

Ok thought so, thanks Billy.

#14 Wolfy87

Wolfy87
  • Topic Starter

  • Members
  • 414 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:England
  • Local time:10:48 AM

Posted 01 October 2008 - 02:21 PM

So far so good i have got it to generate 8 tiles so far :thumbsup:. Because i am using many many if statements now is there a better way? i have vaigly herd of 'case' from PlyPencil at school and things but dont realy understand it.

Many thanks,
Wolfy87.

#15 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,301 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:03:48 AM

Posted 01 October 2008 - 07:22 PM

You can use a switch to do that... I personally prefer the if elseif else ladder but it's up to you.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users