Click here to Skip to main content
15,897,704 members
Home / Discussions / C#
   

C#

 
GeneralRe: Navigate the web Pin
Little_Dice29-May-07 9:26
Little_Dice29-May-07 9:26 
QuestionOffice 11 and Interop. Pin
swjam20-May-07 16:23
swjam20-May-07 16:23 
QuestionCreate and print PDF file in web application using iTextSharp assembly Pin
There is always the way to do it, but I don't know20-May-07 13:44
There is always the way to do it, but I don't know20-May-07 13:44 
AnswerRe: Create and print PDF file in web application using iTextSharp assembly Pin
blackjack215020-May-07 20:20
blackjack215020-May-07 20:20 
GeneralRe: Create and print PDF file in web application using iTextSharp assembly Pin
There is always the way to do it, but I don't know21-May-07 11:00
There is always the way to do it, but I don't know21-May-07 11:00 
GeneralRe: Create and print PDF file in web application using iTextSharp assembly Pin
There is always the way to do it, but I don't know22-May-07 7:57
There is always the way to do it, but I don't know22-May-07 7:57 
QuestionHow to set the caret position in ComboBox? Pin
GaryShen20-May-07 12:54
GaryShen20-May-07 12:54 
QuestionHelp! I'm going insane!!!! Pin
mfkr20-May-07 12:48
mfkr20-May-07 12:48 
So I've decided to start diving into minor game programming and getting a better understanding of how it's done by making a few games this summer. The first is this clone of the Zombie Simulator that you might of seen by Kevan Davis. I'm not trying to be original mind you just to learn. I figured i'd be a pretty easy start but I've come to a dead stop.

I've managed to randomly create "buildings" but I'm having issues with my "Being" class being able to manipulate the outsider world. In the main program class "Zombie" I have my bitmap image set to protected which SHOULD allow for the Being class to manipulate it since it is a derived class from Zombie. So maybe someone can help me. What the hell am I doing wrong? BTW I know not all the methods are completely...but I must first be able to display the object before I continue onward. Below is all the code I've done. I hope it isn't to long.

using System; <br />
using System.Drawing; <br />
using System.Drawing.Drawing2D; <br />
using System.Collections; <br />
using System.ComponentModel; <br />
using System.Windows.Forms; <br />
using System.Data; <br />
  <br />
namespace ZombiesSim<br />
{<br />
	/// <summary> <br />
	/// Summary description for Form1. <br />
	/// </summary> <br />
	public class Zombie : System.Windows.Forms.Form <br />
	{<br />
	    private System.ComponentModel.IContainer components;<br />
		<br />
	    private bool _doBuffer = true;<br />
		private int freeze, x, y, bwidth, bheight;<br />
		private Color human, panichuman, zombie, wall;<br />
		private int num = 1000;<br />
		private int speed = 1;<br />
		private Graphics g;<br />
		private bool gxstart;<br />
		private Being bee;<br />
		//private Being[] beings;<br />
		public Bitmap world;<br />
		protected int width, height;<br />
		private Random rand = new Random();<br />
<br />
	  <br />
	    public Zombie() <br />
	    { <br />
			// <br />
			// Required for Windows Form Designer support <br />
			// <br />
			InitializeComponent(); <br />
			<br />
			human = Color.Purple;<br />
			panichuman = Color.Pink;<br />
			zombie = Color.Lime;<br />
			wall = Color.DimGray;<br />
			<br />
			width = this.ClientSize.Width;<br />
			height = this.ClientSize.Height;<br />
			<br />
			world = new Bitmap( width, height );<br />
			g = Graphics.FromImage( world );<br />
			gxstart = true;<br />
			<br />
			freeze = 0;<br />
	    }<br />
	  <br />
	    /// <summary> <br />
	    /// Clean up any resources being used. <br />
	    /// </summary> <br />
	    protected override void Dispose( bool disposing ) <br />
	    { <br />
			if( disposing ) <br />
			{ <br />
				if (components != null) <br />
				{ <br />
					components.Dispose(); <br />
				} <br />
			} <br />
			base.Dispose( disposing ); <br />
	    } <br />
	  <br />
	    #region Windows Form Designer generated code <br />
	    /// <summary> <br />
	    /// Required method for Designer support - do not modify <br />
	    /// the contents of this method with the code editor. <br />
	    /// </summary> <br />
	    private void InitializeComponent() <br />
	    { <br />
			this.components = new System.ComponentModel.Container(); <br />
			this.SuspendLayout(); <br />
			// <br />
			// Zombie<br />
			// <br />
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); <br />
			this.ClientSize = new System.Drawing.Size(666, 666); <br />
			this.Name = "Zombie Simulation"; <br />
			this.Text = "Zombie Simulation"; <br />
			this.ResumeLayout(false);<br />
			this.MaximizeBox = false;<br />
			this.FormBorderStyle = FormBorderStyle.FixedDialog;<br />
			this.Shown += new System.EventHandler(this.Zombie_Shown);<br />
	    }<br />
	    #endregion<br />
		<br />
	    /// <summary><br />
	    /// The main entry point for the application.<br />
	    /// </summary><br />
	    [STAThread]<br />
	    static void Main()<br />
	    {<br />
			Application.Run(new Zombie());<br />
	    }<br />
		<br />
		private void Zombie_Shown(object sender, EventArgs e)<br />
        {<br />
        }<br />
		<br />
	    protected override void OnPaint(PaintEventArgs e)<br />
	    {<br />
			if( world != null && gxstart == true )<br />
			{<br />
				<br />
				g.Clear(Color.Black);<br />
				<br />
				for( int i = 0; i < 100; i++)<br />
				{<br />
					x = rand.Next( this.ClientSize.Width );<br />
					y = rand.Next( this.ClientSize.Height );<br />
					bwidth = rand.Next( 30, 90 );<br />
					bheight = rand.Next( 30, 90 );<br />
					g.FillRectangle( new SolidBrush( wall ), x, y, bwidth, bheight );<br />
				}<br />
				<br />
				for( int i = 0; i < 30; i++)<br />
				{<br />
					x = rand.Next( this.ClientSize.Width );<br />
					y = rand.Next( this.ClientSize.Height );<br />
					bwidth = rand.Next( 40, 60 );<br />
					bheight = rand.Next( 40, 60 );<br />
					g.FillRectangle( new SolidBrush( wall ), x, y, bwidth, bheight );<br />
				}<br />
				<br />
				gxstart = false;<br />
				<br />
			}<br />
			<br />
			setup();<br />
			<br />
			if(_doBuffer)<br />
			{<br />
				//g.Dispose();<br />
				//Copy the back buffer to the screen<br />
				e.Graphics.DrawImageUnscaled( world ,0,0);<br />
			}<br />
			//base.OnPaint (e); //optional but not recommended<br />
	    }<br />
		<br />
		public void setup()<br />
		{<br />
			bee = new Being();<br />
			/*<br />
			for( int i = 0; i < 100; i++)<br />
			{<br />
				world.SetPixel( rand.Next( 1, width - 1 ), rand.Next( 1, height - 1 ), human );<br />
			}<br />
			*/<br />
		}<br />
		<br />
	    protected override void OnPaintBackground(PaintEventArgs pevent) <br />
	    { <br />
			//Don't allow the background to paint <br />
	    } <br />
	  <br />
	    protected override void OnSizeChanged(EventArgs e)<br />
	    {<br />
			/*<br />
			if( world != null )<br />
			{<br />
				world.Dispose();<br />
				world = null;<br />
			}<br />
			base.OnSizeChanged (e);<br />
			*/<br />
	    }<br />
	}<br />
	<br />
	public class Being : Zombie<br />
	{<br />
		private int xpos, ypos, dir;<br />
		private int type;<br />
		private int active;<br />
		private Random rand = new Random();<br />
		private Color hue;<br />
		<br />
		public Being()<br />
		{<br />
			dir = rand.Next( 1, 4 );<br />
			type = 1;<br />
			active = 0;<br />
			hue = Color.Purple;<br />
			position();<br />
			world.SetPixel( 5, 5, Color.Purple );<br />
		}<br />
		<br />
		public int[] getposition()<br />
		{<br />
			int[] pos = { xpos, ypos };<br />
			return pos;<br />
		}<br />
		<br />
		public void position()<br />
		{<br />
			for( int j = 0; j < 100; j++ )<br />
			{<br />
				xpos = rand.Next( 1, width - 1);<br />
				ypos = rand.Next( 1, height - 1);<br />
				if( world.GetPixel( xpos, ypos ) == Color.Black )<br />
					j = 100;<br />
			}<br />
		}<br />
		<br />
		/*<br />
		public Color getpixel( int x, int y )<br />
		{<br />
			return world.GetPixel( x, y );<br />
		}<br />
		<br />
		public void setpixel( int x, int y, Color color )<br />
		{<br />
			world.SetPixel( x, y, color );<br />
		}<br />
		*/<br />
		<br />
		public void infect( int x, int y )<br />
		{<br />
			if( x == xpos && y == ypos )<br />
				type = 2;<br />
		}<br />
		<br />
		public void infect()<br />
		{<br />
			hue = Color.Lime;<br />
			type = 2;<br />
		}<br />
		<br />
		public void uninfect()<br />
		{<br />
			hue = Color.Purple;<br />
			type = 1;<br />
		}<br />
		<br />
		public void look( int x, int y )<br />
		{<br />
			dir = rand.Next( 1, 4 );<br />
			<br />
			if( dir == 1 )<br />
				y++;<br />
			if( dir == 2 )<br />
				x++;<br />
			if( dir == 3 )<br />
				y--;<br />
			if( dir == 4 )<br />
				x--;<br />
		}<br />
		<br />
		public void move()<br />
		{<br />
			<br />
		}<br />
	}<br />
}

AnswerRe: Help! I'm going insane!!!! Pin
Christian Graus20-May-07 12:52
protectorChristian Graus20-May-07 12:52 
GeneralRe: Help! I'm going insane!!!! Pin
mfkr20-May-07 13:16
mfkr20-May-07 13:16 
GeneralRe: Help! I'm going insane!!!! Pin
Christian Graus20-May-07 13:19
protectorChristian Graus20-May-07 13:19 
GeneralRe: Help! I'm going insane!!!! Pin
mfkr20-May-07 16:28
mfkr20-May-07 16:28 
GeneralRe: Help! I'm going insane!!!! Pin
Christian Graus20-May-07 16:38
protectorChristian Graus20-May-07 16:38 
GeneralRe: Help! I'm going insane!!!! Pin
mfkr20-May-07 16:45
mfkr20-May-07 16:45 
GeneralRe: Help! I'm going insane!!!! Pin
Christian Graus20-May-07 17:20
protectorChristian Graus20-May-07 17:20 
GeneralRe: Help! I'm going insane!!!! Pin
mfkr20-May-07 17:49
mfkr20-May-07 17:49 
GeneralRe: Help! I'm going insane!!!! Pin
Christian Graus20-May-07 18:21
protectorChristian Graus20-May-07 18:21 
QuestionGraphics.DrawString(What's wrong??); Pin
Muammar©20-May-07 12:47
Muammar©20-May-07 12:47 
AnswerRe: Graphics.DrawString(What's wrong??); Pin
Christian Graus20-May-07 12:51
protectorChristian Graus20-May-07 12:51 
GeneralRe: Graphics.DrawString(What's wrong??); Pin
Muammar©20-May-07 23:37
Muammar©20-May-07 23:37 
AnswerRe: Graphics.DrawString(What's wrong??); Pin
Stefan Mellberg25-May-07 13:49
Stefan Mellberg25-May-07 13:49 
Questionglobal variables in c#- the 'extern' alternative Pin
brian5520-May-07 12:45
brian5520-May-07 12:45 
AnswerRe: global variables in c#- the 'extern' alternative Pin
Christian Graus20-May-07 12:49
protectorChristian Graus20-May-07 12:49 
GeneralRe: global variables in c#- the 'extern' alternative Pin
brian5520-May-07 16:18
brian5520-May-07 16:18 
GeneralRe: global variables in c#- the 'extern' alternative Pin
Christian Graus20-May-07 16:39
protectorChristian Graus20-May-07 16:39 

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.