Bulles Eye game C# - Help, can't make it work

i need help to remove the errors and make the game :P

Page 1 of 1

11 Replies - 1393 Views - Last Post: 25 June 2009 - 04:50 AM Rate Topic: -----

#1 source144   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 06-June 09

Bulles Eye game C# - Help, can't make it work

Posted 23 June 2009 - 11:58 PM

this is my code for now:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
	class Program
	{
		begin:

		new public static Bull_object CurrentMyclass = new Bull_object();
		public static string ch1, ch2, ch3, ch4;
		public static int NO_1, NO_2, NO_3, NO_4, NO1, NO2, NO3, NO4;
		int sign = 0;
		public static string sep = " ";
		public static string _LastCommand = " ";
		static void Main(string[] args)
		{
			while (_LastCommand.ToUpper() != "Q" && _LastCommand.ToUpper() != "N")
			{
				Console.Clear();
				Console.ForegroundColor = ConsoleColor.Blue;
				Console.Write("Console Bulles Eye Version 1.0");
				Console.ForegroundColor = ConsoleColor.Gray;
				Console.WriteLine(", Enter Q = Quit");
				Console.WriteLine("-----------------------------------------------");
				Console.WriteLine("Bull >> " + NO_1 + sep + NO_2 + sep + NO_3 + sep + NO_4);
				Console.WriteLine("Bull >>  |{0}|{1}|{2}|{3}|", ch1, ch2, ch3, ch4);
				Random RandomNumber = new Random();
				NO1 = RandomNumber.Next(9);
				NO2 = RandomNumber.Next(9);
				NO3 = RandomNumber.Next(9);
				NO4 = RandomNumber.Next(9);
				//run dinamic object
				CurrentMyclass.NO_1 = Convert.ToInt32(Console.ReadLine());
				CurrentMyclass.NO_2 = Convert.ToInt32(Console.ReadLine());
				CurrentMyclass.NO_3 = Convert.ToInt32(Console.ReadLine());
				CurrentMyclass.NO_4 = Convert.ToInt32(Console.ReadLine());
				CurrentMyclass.sign = Console.ReadLine();
				Console.ForegroundColor = ConsoleColor.Green;
				Console.WriteLine("Bull >> There are {0} {1}", CurrentMyclass.Bull_numbers.turnleft, CurrentMyclass.Bullnumbers.turnlefts);
				//Console.ForegroundColor = ConsoleColor.;
				//CurrentMyclass.do_it();
				//Console.WriteLine("combine: " + CurrentMyclass.combine_numbers("||"));
				CurrentMyclass = null;
				if (_LastCommand.ToUpper() != "Q")
				{
					_LastCommand = Console.ReadLine();
				}
			}
			//run static object
			//myClass2.do_it_static();
			//Console.Read();

		}
	}
	class Bull_object
	{
		public static int turnleft = 10;
		public static string turnlefts = " ";
		public int NO_1 { get; set; }
		public int NO_2 { get; set; }
		public int NO_3 { get; set; }
		public int NO_4 { get; set; }
		public string sign { get; set; }
		public void do_it()
		{
			Console.WriteLine("nike");
		}
		public int Bull_numbers()
		{
			turnleft--;
			turnlefts = "Turns left until the game ends..";
			string ch1 = " ";
			string ch2 = " ";
			string ch3 = " ";
			string ch4 = " ";
			int toreturn = 0;
			switch (ConsoleApplication2.Program._LastCommand.ToUpper())
			{
				case "Q":
					break;

				case "C":
					turnleft = 10;
					turnlefts = " ";
					int sign = 0;
					string sep = " ";
					string _LastCommand = " ";
					Console.Clear();
					Console.ForegroundColor = ConsoleColor.Blue;
					Console.Write("Console Bulles Eye Version 1.0");
					Console.ForegroundColor = ConsoleColor.Gray;
					Console.WriteLine(", Enter Q = Quit");
					Console.WriteLine("-----------------------------------------------");
					Console.WriteLine("Bull >> " + NO_1 + sep + NO_2 + sep + NO_3 + sep + NO_4);
					Console.WriteLine("Bull >>  |{0}|{1}|{2}|{3}|", ch1, ch2, ch3, ch4);
					Console.ForegroundColor = ConsoleColor.Magenta;
					Console.WriteLine("Bull >> Command 'n' Was loaded and a new Bulles Eye Game has started!");
					Console.ForegroundColor = ConsoleColor.Gray;
					Random RandomNumber = new Random();
					int NO1 = RandomNumber.Next(9);
					int NO2 = RandomNumber.Next(9);
					int NO3 = RandomNumber.Next(9);
					int NO4 = RandomNumber.Next(9);
			}
			switch (NO_1)
			{
				case Program.NO1:
					ch1 = "V";
					break;

				case "NO2":
					ch1 = "*";
					break;

				case "NO3":
					ch1 = "*";
					break;

				case "NO4":
					ch1 = "*";
					break;

				default:
					ch1 = "X";
					break;
			}
			switch (NO_2)
			{
				case "NO1":
					ch2 = "*";
					break;

				case "NO2":
					ch2 = "V";
					break;

				case "NO3":
					ch2 = "*";
					break;

				case "NO4":
					ch2 = "*";
					break;

				default:
					ch2 = "X";
					break;
			}
			switch (NO_3)
			{
				case "NO1":
					ch3 = "*";
					break;

				case "NO2":
					ch3 = "*";
					break;

				case "NO3":
					ch3 = "V";
					break;

				case "NO4":
					ch3 = "*";
					break;

				default:
					ch3 = "X";
					break;
			}
			switch (NO_4)
			{
				case "NO1":
					ch4 = "*";
					break;

				case "NO2":
					ch4 = "*";
					break;

				case "NO3":
					ch4 = "*";
					break;

				case "NO4":
					ch4 = "V";
					break;

				default:
					ch4 = "X";
					break;
			}
			return ch1;
			return ch2;
			return ch3;
			return ch4;
		}
		//public string combine_numbers(string seperator)
		//{
		//return NO_1.ToString() + seperator + NO_2.ToString();
		//}
	}
	class myClass2
	{
		public static void do_it_static()
		{
			Console.WriteLine("static nike");
		}
	}
}


so please someone help me solve it..
thanks..

Is This A Good Question/Topic? 0
  • +

Replies To: Bulles Eye game C# - Help, can't make it work

#2 source144   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 06-June 09

Re: Bulles Eye game C# - Help, can't make it work

Posted 24 June 2009 - 04:38 AM

this is a console app, PLEASE HELP!
Was This Post Helpful? 0
  • +
  • -

#3 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,617
  • Joined: 25-December 08

Re: Bulles Eye game C# - Help, can't make it work

Posted 24 June 2009 - 05:06 AM

What is the issue?

Edit: Do you have a compiler and/or IDE? because I threw your code into visual studio, and I got about 23 errors. Most are easy to fix, but did you try and fix any yourself first?

This post has been edited by SwiftStriker00: 24 June 2009 - 05:11 AM

Was This Post Helpful? 0
  • +
  • -

#4 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,617
  • Joined: 25-December 08

Re: Bulles Eye game C# - Help, can't make it work

Posted 24 June 2009 - 05:29 AM

View PostSwiftStriker00, on 24 Jun, 2009 - 06:06 AM, said:

What is the issue?

Edit: Do you have a compiler and/or IDE? because I threw your code into visual studio, and I got about 23 errors. Most are easy to fix, but did you try and fix any yourself first?



Ok dude, how much experience have you had with c# because it seams you in over your head. Lets start at the beginning and walk through with what you want:
 begin:
 new public static Bull_object CurrentMyclass = new Bull_object();
 public static string ch1, ch2, ch3, ch4;
 public static int NO_1, NO_2, NO_3, NO_4, NO1, NO2, NO3, NO4;
 int sign = 0;
 public static string sep = " ";
 public static string _LastCommand = " ";


You should look into using more descriptive variable names to help you remember how your using them. For example instead of NO_1, you can call it toss_1_points , if each of the num's were number of points scored in a game

also go ahead and remove begin: , the program will begin in Main

speaking of which:
static void Main(string[] args)  {
			Console.ForegroundColor = ConsoleColor.Blue;
			Console.Write("Console Bullseye Version 1.0");
			while (_LastCommand.ToUpper() != "Q" && _LastCommand.ToUpper() != "N") {
				Console.Clear();
				Console.ForegroundColor = ConsoleColor.Gray; 
				Console.WriteLine(", Enter Q = Quit");
				Console.WriteLine("-----------------------------------------------");


First (and not really big deal) it is bullseye not 'bulles eye' unless that is on purpose, and by all means change it back.
Second you while is a good start, but I moved the Title to outside the loop, you only need to tell people once what your program is.

Lastly:
Console.WriteLine("Bull >> " + NO_1 + sep + NO_2 + sep + NO_3 + sep + NO_4);
Console.WriteLine("Bull >>  |{0}|{1}|{2}|{3}|", ch1, ch2, ch3, ch4);
Random RandomNumber = new Random(); 
NO1 = RandomNumber.Next(9); 
NO2 = RandomNumber.Next(9); 
NO3 = RandomNumber.Next(9); 
NO4 = RandomNumber.Next(9);


Your code is going to break every NO_ and ch1, the first time you run through this, because you never give them initial values

This post has been edited by SwiftStriker00: 24 June 2009 - 05:46 AM

Was This Post Helpful? 0
  • +
  • -

#5 source144   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 06-June 09

Re: Bulles Eye game C# - Help, can't make it work

Posted 24 June 2009 - 06:56 AM

i already fixed ~20 errors, there were 46 errors..
the reason for that is because i was doing the project on visual C# by accident on another program or something and it didn't read all these bugs
please can someone clear these bugs~!!!! im stuck ~2 day's with it..
Was This Post Helpful? 0
  • +
  • -

#6 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,617
  • Joined: 25-December 08

Re: Bulles Eye game C# - Help, can't make it work

Posted 24 June 2009 - 07:14 AM

View Postsource144, on 24 Jun, 2009 - 07:56 AM, said:

i already fixed ~20 errors, there were 46 errors..
the reason for that is because i was doing the project on visual C# by accident on another program or something and it didn't read all these bugs
please can someone clear these bugs~!!!! im stuck ~2 day's with it..


ok, well repost your code that is less buggy. Also what is your problem? is it that it is just buggy? its not functioning properly? Unexpected errors?

I dont mind helping you debug your program, but at least show me some courtesy of explaining the best you can the problem in stead of "Halp, I'm stuck...Hurry"
Was This Post Helpful? 0
  • +
  • -

#7 source144   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 06-June 09

Re: Bulles Eye game C# - Help, can't make it work

Posted 24 June 2009 - 07:27 AM

i just dont know how to get rid of the errors if some one will do it il see and learn how to do it my self.. thanks..
i opened the Visual C#.. and i didnt show any error then i tryed to debug and it ill debug my last program.. so then i opened a new Visual C#.. and it showed me 46 errors i fixed about 26 that i know how to fix.. the others i dont know how to fix them so that is what i need help in... thank you.
Was This Post Helpful? 0
  • +
  • -

#8 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,617
  • Joined: 25-December 08

Re: Bulles Eye game C# - Help, can't make it work

Posted 24 June 2009 - 08:30 AM

ok well post the errors so I can explain what they mean. but heres two things i noticed:

in public int Bull_numbers() you have 4 return statements, which will not work a method can only return 1 thing, the other 3 will never be reached. Are you trying to return them, or save their values.

second your missing the point on switch statement, how it works and how to create it. What is your goal with it?
Was This Post Helpful? 0
  • +
  • -

#9 source144   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 06-June 09

Re: Bulles Eye game C# - Help, can't make it work

Posted 24 June 2009 - 09:39 AM

save thier value
Was This Post Helpful? 0
  • +
  • -

#10 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,617
  • Joined: 25-December 08

Re: Bulles Eye game C# - Help, can't make it work

Posted 24 June 2009 - 10:04 AM

View Postsource144, on 24 Jun, 2009 - 10:39 AM, said:

save thier value

Then you dont need a return value, you want something like this:

public class Test{
	public string c1, c2, c3, c4;

	public Test(){
		c1 = "";
		c2 = "";
		c3 = "";
		c4 = "";
	}

	public void setValues( int input ){
		switch( input ){
			case 1:
				c1 = "a";
				c2 = "b";
				c3 = "c";
				c4 = "d";
				break;
			case 2:
				c1 = "aa";
				c2 = "bb";
				c3 = "cc";
				c4 = "dd";
				break;
			default:
				c1 = "q";
				c2 = "w";
				c3 = "e";
				c4 = "t";
				break;
				}
	  }

	  public override string ToString(){
			return "Values are: " + c1 + "  " + c2 + " " + c3 + " " + c4;
	  }

	  public static void Main( string[] args){
			Test t = new Test();
			t.setValues( 1 );
			Console.WriteLine( t.ToString() );
			t.setValues( 2);
			Console.WriteLine( t.ToString() );
			t.setValues( 3);
			Console.WriteLine( t.ToString() );
	  }

}		 


This post has been edited by SwiftStriker00: 24 June 2009 - 10:06 AM

Was This Post Helpful? 0
  • +
  • -

#11 source144   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 06-June 09

Re: Bulles Eye game C# - Help, can't make it work

Posted 24 June 2009 - 10:34 PM

this is what i've done now:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
	public static class Bull_object
	{
		public static int turnleft { get; set; }
		public static string turnlefts { get; set; }
		public static int NO_1 { get; set; }
		public static int NO_2 { get; set; }
		public static int NO_3 { get; set; }
		public static int NO_4 { get; set; }
		public static int NO1 { get; set; }
		public static int NO2 { get; set; }
		public static int NO3 { get; set; }
		public static int NO4 { get; set; }
		public static string ch1 { get; set; }
		public static string ch2 { get; set; }
		public static string ch3 { get; set; }
		public static string ch4 { get; set; }
		public static string _LastCommand { get; set; }
	}
	class Program
	{
		public static bool firststrun = true;
		public static string sep = " ";
		static void Main(string[] args)
		{
			if (Program.firststrun == true)
			{
				Bull_object.NO1 = 0;
				Bull_object.NO2 = 0;
				Bull_object.NO3 = 0;
				Bull_object.NO4 = 0;
			}
			while (Bull_object._LastCommand.ToUpper() != "Q" && Bull_object._LastCommand.ToUpper() != "N")
			{
				Console.Clear();
				Console.ForegroundColor = ConsoleColor.Blue;
				Console.Write("Console Bulles Eye Version 1.0");
				Console.ForegroundColor = ConsoleColor.Gray;
				Console.WriteLine(", Enter Q = Quit");
				Console.WriteLine("-----------------------------------------------");
				Console.WriteLine("Bull >> " + Bull_object.NO_1 + sep + Bull_object.NO_2 + sep + Bull_object.NO_3 + sep + Bull_object.NO_4);
				Console.WriteLine("Bull >>  |{0}|{1}|{2}|{3}|", Bull_object.ch1, Bull_object.ch2, Bull_object.ch3, Bull_object.ch4);
				Random RandomNumber = new Random();
				Bull_object.NO1 = RandomNumber.Next(9);
				Bull_object.NO2 = RandomNumber.Next(9);
				Bull_object.NO3 = RandomNumber.Next(9);
				Bull_object.NO4 = RandomNumber.Next(9);
				//run dinamic object
				Bull_object.NO_1 = Convert.ToInt32(Console.ReadLine());
				Bull_object.NO_2 = Convert.ToInt32(Console.ReadLine());
				Bull_object.NO_3 = Convert.ToInt32(Console.ReadLine());
				Bull_object.NO_4 = Convert.ToInt32(Console.ReadLine());
				//sign = Console.ReadLine();
				Console.ForegroundColor = ConsoleColor.Green;
				//  Console.WriteLine("Bull >> There are {0} {1}", Bull_numbers.turnleft, Bull_Numbers());
				//Console.ForegroundColor = ConsoleColor.;
				//CurrentMyclass.do_it();
				//Console.WriteLine("combine: " + CurrentMyclass.combine_numbers("||"));
				if (Bull_object._LastCommand.ToUpper() != "Q")
				{
					Bull_object._LastCommand = Console.ReadLine();
				}
			}
			//run static object
			//myClass2.do_it_static();
			//Console.Read();

		}
	}
		public static class Bull_numbers
		{
			int toreturn = 0;
			public static string Bull_numbers()
			{
				switch (Bull_object._LastCommand.ToUpper())
				{
					case "N":
						Bull_object.turnleft = 10;
						Bull_object.turnlefts = " ";
						string sep = " ";
						Bull_object._LastCommand = " ";
						Console.Clear();
						Console.ForegroundColor = ConsoleColor.Blue;
						Console.Write("Console Bulles Eye Version 1.0");
						Console.ForegroundColor = ConsoleColor.Gray;
						Console.WriteLine(", Enter Q = Quit");
						Console.WriteLine("-----------------------------------------------");
						Console.WriteLine("Bull >> " + Bull_object.NO_1 + sep + Bull_object.NO_2 + sep + Bull_object.NO_3 + sep + Bull_object.NO_4);
						Console.WriteLine("Bull >>  |{0}|{1}|{2}|{3}|", Bull_object.ch1, Bull_object.ch2, Bull_object.ch3, Bull_object.ch4);
						Console.ForegroundColor = ConsoleColor.Magenta;
						Console.WriteLine("Bull >> Command 'n' Was loaded and a new Bulles Eye Game has started!");
						Console.ForegroundColor = ConsoleColor.Gray;
						Random RandomNumber = new Random();
						Bull_object.NO1 = RandomNumber.Next(9);
						Bull_object.NO2 = RandomNumber.Next(9);
						Bull_object.NO3 = RandomNumber.Next(9);
						Bull_object.NO4 = RandomNumber.Next(9);
						break;

					case "Q":
						break;
				}
				return Bull_object._LastCommand;
			}
		}
		public static class Bull_num
		{
			public static int Bull_Num()
			{
				switch (Bull_object.NO_1)
				{
					case Bull_object.NO1:
						Bull_object.ch1 = "V";
						break;

					case Bull_object.NO2:
						Bull_object.ch1 = "*";
						break;

					case Bull_object.NO3:
						Bull_object.ch1 = "*";
						break;

					case Bull_object.NO4:
						Bull_object.ch1 = "*";
						break;

					default:
						Bull_object.ch1 = "X";
						break;
				}
				switch (Bull_object.NO_2)
				{
					case Bull_object.NO1:
						Bull_object.ch2 = "*";
						break;

					case Bull_object.NO2:
						Bull_object.ch2 = "V";
						break;

					case Bull_object.NO3:
						Bull_object.ch2 = "*";
						break;

					case Bull_object.NO4:
						Bull_object.ch2 = "*";
						break;

					default:
						Bull_object.ch2 = "X";
						break;
				}
				switch (Bull_object.NO_3)
				{
					case Bull_object.NO1:
						Bull_object.ch3 = "*";
						break;

					case Bull_object.NO2:
						Bull_object.ch3 = "*";
						break;

					case Bull_object.NO3:
						Bull_object.ch3 = "V";
						break;

					case Bull_object.NO4:
						Bull_object.ch3 = "*";
						break;

					default:
						Bull_object.ch3 = "X";
						break;
				}
				switch (Bull_object.NO_4)
				{
					case Bull_object.NO1:
						Bull_object.ch4 = "*";
						break;

					case Bull_object.NO2:
						Bull_object.ch4 = "*";
						break;

					case Bull_object.NO3:
						Bull_object.ch4 = "*";
						break;

					case Bull_object.NO4:
						Bull_object.ch4 = "V";
						break;

					default:
						Bull_object.ch4 = "X";
						break;
				}
			}
		}
		//public string combine_numbers(string seperator)
		//{
		//return NO_1.ToString() + seperator + NO_2.ToString();
		//}
	}


at the swich in the end all the
"case Bull_object.NO#:"
it will say Error: A constant Value is expected


what does it mean and how do i fix it?
Was This Post Helpful? 0
  • +
  • -

#12 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,617
  • Joined: 25-December 08

Re: Bulles Eye game C# - Help, can't make it work

Posted 25 June 2009 - 04:50 AM

View Postsource144, on 24 Jun, 2009 - 11:34 PM, said:

at the swich in the end all the
"case Bull_object.NO#:"
it will say Error: A constant Value is expected


what does it mean and how do i fix it?


This is because Bull_object.NO# is a variable that its value can change. in your switch statement, is your telling the computer to evaluate an expression, and then see what code path to take based off its result. So if you have a variable path, the compiler cannot ever garentee if you will enter that code block. You want to use either hard code static values, an Enum, or declared Bull_object.NO# as final. (the last one wont work for your program atm)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1