• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
cavendert

Stuck in C#......

10 posts in this topic

Hey guys. I'm sure that this is beyond simple, but I can't figure this out. As you will see in the code below, I'm trying to simulate a Pokemon battle (stupid easy). I'm trying to create a structure for 6 pokemon, and associate a string name, and an int for health. 
 
I've figured out how to make that in the "Class" section. So, my question is, how do I then input the pokemon into the structure, so the health is associated with a pokemon? I know how to write it, and call it in C++, but I'm at a complete loss here. So, code below (please be gentle), and let me know what I'm missing please. 
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Practice_Battle
{
    class Program
    {
        struct chadList
        {
            string name;
            int health;
        };
        static void Main(string[] args)
        {
 
            chadList chadPokemon;
            {
                
 
            }
 
 
            //Chad's List of Pokemon
            //string[] chadPokemon = new string[6] { "Charizard", "Garchomp", "Metagross", "Aegislash", "Quagsire", "Gardevoir" };
 
            //Random Pokemon Generator
            Random ran = new Random();
            string randomChoice = chadPokemon[ran.Next(0, chadPokemon.Length)];
 
 
 
            Console.WriteLine("Gamer Chad wants to battle!");
            Console.WriteLine("Do you accept? (yes or no)");
            string acceptInput = Console.ReadLine();
 
            string message = "";
 
            if (acceptInput == "yes")
                message = "It's time to put your game face on!";
            else
                message = "Too bad. It's time to battle!";
 
            //Random Pokemon is Chosen, I choose a Pokemon
            Console.WriteLine(message);
            Console.WriteLine("I choose you, " + randomChoice);
            Console.WriteLine("Please choose your Pokemon:");
            Console.WriteLine("Blastoise, Blazekin, Meganium");
            string myChoice = Console.ReadLine();
 
            if (myChoice == "Blastoise")
                message = "A water Pokemon, with lots of health. Good Choice!";
            else if (myChoice == "Blazekin")
                message = "A fire Pokemon, with lots of Power. Let's do this!";
            else
                message = "A plant Pokemon, with lots of health. Best of luck!";
 
            Console.WriteLine(myChoice + ", " + message);
            Console.ReadLine();
 
        }
    }
}

Thank you for any advice that you can give!

0

Share this post


Link to post
Share on other sites


I know how to write it, and call it in C++, but I'm at a complete loss here.

 

I am not sure what you mean here.

1

Share this post


Link to post
Share on other sites

In C++ you would probably use something like a vector with 6 elements.  Then just fill your vector with instances of the Pokemon object.

In C# you would do the same thing but I believe the proper container is the ArrayList.

2

Share this post


Link to post
Share on other sites
//Chad's List of Pokemon
chadList[] chadPokemon = 
{ 
	{ "Charizard", 100 },
	{ "Garchomp", 100 }
};
 
//Random Pokemon Generator
Random ran = new Random();
chadList randomChoice = chadPokemon[ran.Next(0, chadPokemon.Length)];

I have no idea of what you want to do... this it?

 

 

This might be to good use, Collections.

Edited by ChillyFlashER
1

Share this post


Link to post
Share on other sites

I'm really sorry for the poor description, but Brian, that's exactly what I was looking for. If I could ask a question about it. When you write List<Pokemon>, Pokemon is the name of the list?

 

And later, after the random selection (since I won't know what was chosen), could I attach that randomPokemon.name to a string, (chadChoice=randomPokemon.name), and when I call that string, it would still associate the correct Health stat, with the Name that was chosen?

0

Share this post


Link to post
Share on other sites

Ok. The list worked just fine, so thank you all for that. I have one more question pertaining to the list now. I have successfully had my Opponent randomly select from his list, and display no problem. Now, I want to reference my selection. I have given myself a choice of 3 pokemon, and call them by choosing 1,2 or 3. 

 

How do I call that up? With something along the lines of Console.WriteLine(myChoice.length -1); ?

 

Here is the code to try and make more sense of it. 

 

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


namespace Practice_Battle
{
    class Pokemon
    {
        public string Name;
        public int Health;
        public int Attack;
    }


    class Program
    {
        static List<Pokemon> chadPokemon = new List<Pokemon>() {
            new Pokemon {
                Name = "Charizard",
                Health = 200,
                Attack = 50
            },
            new Pokemon {
                Name = "Garchomp",
                Health = 180,
                Attack = 50
            },
            new Pokemon {
                Name= "Metagross", 
                Health = 200,
                Attack = 50
            },
            new Pokemon {
                Name = "Aegislash",
                Health = 200,
                Attack = 50
            },
            new Pokemon {
                Name = "Quagsire",
                Health = 200, 
                Attack = 50
            },
            new Pokemon {
                Name = "Gardevoir",
                Health = 200,
                Attack = 50
            }
        };


        static List<Pokemon> myPokemon = new List<Pokemon>() {
            new Pokemon {
                Name = "Blastoise",
                Health = 200,
                Attack = 50
            },
            new Pokemon {
                Name = "Blazekin",
                Health = 200, 
                Attack = 50
            },
            new Pokemon {
                Name = "Meganium", 
                Health= 200, 
                Attack = 50
            }
        };
        
        static void Main(string[] args)
        {
                       
            //Chad's List of Pokemon
            //string[] chadPokemon = new string[6] { "Charizard", "Garchomp", "Metagross", "Aegislash", "Quagsire", "Gardevoir" };


            //Random Pokemon Generator
            var rnd = new Random();
            var randomChoice = chadPokemon[rnd.Next(chadPokemon.Count)];






            Console.WriteLine("Gamer Chad wants to battle!");
            Console.WriteLine("Do you accept? (yes or no)");
            string acceptInput = Console.ReadLine();


            string message = "";


            if (acceptInput == "yes")
                message = "It's time to put your game face on!";
            else
                message = "Too bad. It's time to battle!";


            //Random Pokemon is Chosen, I choose a Pokemon
            Console.WriteLine(message);
            Console.WriteLine("I choose you, " + randomChoice.Name);
            Console.WriteLine("Please choose your Pokemon: (1,2,3)");
            Console.WriteLine("1. Blastoise, 2. Blazekin, 3. Meganium");
            string myChoice = Console.ReadLine();


            if (myChoice == "1")
                message = "Blastoise, a water Pokemon, with lots of health. Good Choice!";
            else if (myChoice == "2")
                message = "Blazekin, a fire Pokemon, with lots of Power. Let's do this!";
            else
                message = "Meganium, a plant Pokemon, with lots of health. Best of luck!";


            Console.WriteLine(message);
            Console.ReadLine();


            Console.WriteLine("Type yes to Attack.");
            acceptInput = Console.ReadLine();
                       
        }
    }
}
0

Share this post


Link to post
Share on other sites

When the user enters something, you get a piece of text back.  What you need to do is to find out if they actually wrote a number, and then determine what number that is, so you can use it to retrieve an element from your list of pokemons. Luckily, the built-in number types have methods for parsing text.  To convert text to an integer, you might use Convert.ToInt32() or Int32.Parse() or Int32.TryParse().

 

You also want to do some sort of error handling; if the user didn't enter a number, or they wrote a larger number than you have pokemons, then you should ask them again until they enter something valid.

 

Here's a simple loop to do that.

Pokemon SelectedPokemon = null;
do {
	Console.WriteLine("Please choose your Pokemon: (1,2,3)");
	Console.WriteLine("1. Blastoise, 2. Blazekin, 3. Meganium");
	string myChoice = Console.ReadLine();

	if (myChoice == "1")
		message = "Blastoise, a water Pokemon, with lots of health. Good Choice!";
	else if (myChoice == "2")
		message = "Blazekin, a fire Pokemon, with lots of Power. Let's do this!";
	else
		message = "Meganium, a plant Pokemon, with lots of health. Best of luck!";

	Console.WriteLine(message);
	Console.ReadLine();

	int SelectedPokemonNo = 0;
	if( !Int32.TryParse( myChoice, out SelectedPokemonNo ) )
	{
		// uh oh, myChoice wasnt a number
		Console.WriteLine( "That's not a pokemon! Try again" );
		continue;
	}
	SelectedPokemonNo--; // make it a 0-based index
	if( SelectedPokemonNo < 0 || SelectedPokemonNo >= myPokemon.Count )
	{
		// uh oh, myChoice out of range
		Console.WriteLine( "That's not a pokemon! Try again" );
		continue;
	}

	SelectedPokemon = myPokemon[SelectedPokemonNo];
	Console.WriteLine( "You selected {0} with {1} health.", SelectedPokemon.Name, SelectedPokemon.Health );

}
while( null == SelectedPokemon );

Something else you might think about is how you have built the pokemon names and descriptions directly into the code that asks to choose between them.  A better design would be to put the descriptions ("a water Pokemon, with lots of health") into another field in the Pokemon class, and have the menu retrieve it from there.

 

I think it would be good for you to read some tutorials on C#; they would have taught you about converting texts to numbers, and using lists, and countless more details.  I just googled up this one; there are 23 pages and it looks decent - if you go through all those those, you'll be much better prepared.  Enjoy smile.png  http://www.csharp-station.com/Tutorial/CSharp/Lesson01

Edited by Brian Sandberg
1

Share this post


Link to post
Share on other sites

I'm currently going through the Microsoft Virtual Academy for the tutorial, but I will definitely read up on that. I don't mind having to read things. I totally forgot about the "parse", and found it in my notes right before I got back on this forum. 

 

So, I'm having a slightly different issue, but I've put that in a different thread while I try to figure that one out. Thank you guys for all of the help on this topic!!!!

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0