473,803 Members | 3,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need to create Items for a game.

mb
what is the best way to do this:

In a game I want to a class called "Items". This class will have the game
items

public class Items
{
public int Chair
public int Table
. . .and so on . . .
}

Then I want each item in the Items class to have properties like X and Y for
location.

The reason I want it like this is so I can instantiate a Items type,
randomly pick one of it's items then place it on the board (or get its name,
color, or material etc.).

I thought C# would give me some advantages over VB6 when I just used a
multi-demensional array MyItems(20,20), where the first number is the
item, and the second number was its list of properties. I would make
constants like CHAIR, and NAME:

Example
MyItems(CHAIR, NAME) = "Red Chair"

When I saw C# and its ability to make objects, I though this would eliminate
this need. However, it seems that I am going to have to make a
multidemensiona l array again. Isn't there an easier way with C#?
Nov 16 '05 #1
4 2094

"mb" <mm@hotmail.com > wrote in message
news:ON******** ******@TK2MSFTN GP10.phx.gbl...
what is the best way to do this:

In a game I want to a class called "Items". This class will have the game
items

public class Items
{
public int Chair
public int Table
. . .and so on . . .
}

Then I want each item in the Items class to have properties like X and Y
for
location.

The reason I want it like this is so I can instantiate a Items type,
randomly pick one of it's items then place it on the board (or get its
name,
color, or material etc.).

I thought C# would give me some advantages over VB6 when I just used a
multi-demensional array MyItems(20,20), where the first number is the
item, and the second number was its list of properties. I would make
constants like CHAIR, and NAME:

Example
MyItems(CHAIR, NAME) = "Red Chair"

Whats wrong with defining, say,

public class Item
{
public string Name;
public string Location;
]

public class Items
{
public static readonly Item[] Items;
}

and then
Items.Items[0].Name = "Red Chair";

?
That is certainly the approach I would take, instead of using an array.
Nov 16 '05 #2
Hmmm... Don't be too upset if I'm way off here, but sounds sort of like you
want to create a gameboard with an Item object in each square?

How about a two-dimensional array of Items?

Items [] gameboard = new Items [20, 20];

Does that make sense for what you're doing? Then you populate each square
with a particular Item that you've instantiated and assigned values to
(i.e., Items item1 = new Items; item1.itemtype = chair; item1.color = red;
gameboard [10, 10] = item1; etc.)

Your itemtypes would be an enumeration in this instance. Or you could work
it by creating subclasses of the Items, which would make sense if they each
have varying properties.

Just a thought - the array of Items might be a little easier to program than
storing the X and Y in each item, especially since it's a small array...

Thanks,
Michael C., MCDBA
"mb" <mm@hotmail.com > wrote in message
news:ON******** ******@TK2MSFTN GP10.phx.gbl...
what is the best way to do this:

In a game I want to a class called "Items". This class will have the game
items

public class Items
{
public int Chair
public int Table
. . .and so on . . .
}

Then I want each item in the Items class to have properties like X and Y for location.

The reason I want it like this is so I can instantiate a Items type,
randomly pick one of it's items then place it on the board (or get its name, color, or material etc.).

I thought C# would give me some advantages over VB6 when I just used a
multi-demensional array MyItems(20,20), where the first number is the
item, and the second number was its list of properties. I would make
constants like CHAIR, and NAME:

Example
MyItems(CHAIR, NAME) = "Red Chair"

When I saw C# and its ability to make objects, I though this would eliminate this need. However, it seems that I am going to have to make a
multidemensiona l array again. Isn't there an easier way with C#?

Nov 16 '05 #3
mb

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .

"mb" <mm@hotmail.com > wrote in message
news:ON******** ******@TK2MSFTN GP10.phx.gbl...
what is the best way to do this:

In a game I want to a class called "Items". This class will have the game items

public class Items
{
public int Chair
public int Table
. . .and so on . . .
}

Then I want each item in the Items class to have properties like X and Y
for
location.

The reason I want it like this is so I can instantiate a Items type,
randomly pick one of it's items then place it on the board (or get its
name,
color, or material etc.).

I thought C# would give me some advantages over VB6 when I just used a
multi-demensional array MyItems(20,20), where the first number is the
item, and the second number was its list of properties. I would make
constants like CHAIR, and NAME:

Example
MyItems(CHAIR, NAME) = "Red Chair"

Whats wrong with defining, say,

public class Item
{
public string Name;
public string Location;
]

public class Items
{
public static readonly Item[] Items;
}

and then
Items.Items[0].Name = "Red Chair";

?
That is certainly the approach I would take, instead of using an array.


I can't get this to work. It says I can't use the "Items" twice in:

public class Items
{
public static readonly Item[] Items;
}

1) Also, how and where do I instantiate this?

2) What I am trying to do is create a self contained .cs file that has the
definitions for the 24 items I will use (hopefully setup so I could easily
use this class file in another game).
Where would I define the items if I wanted it to be a self contained file
for portability?

3) One last question. Why does "public static readonly Item[] Items;" work?
Is this an example of a indexer? I am trying to understand indexers, and
haven't quite got a grasp on them.

THANKS!
Nov 16 '05 #4

I can't get this to work. It says I can't use the "Items" twice in:

public class Items
{
public static readonly Item[] Items;
}

Oops, I wasn't thinking. A class cannot have a member with the same name.

maybe add the static items field to the Item class.

1) Also, how and where do I instantiate this? Since its readonly, you will need to instantiate it either directly
public static Item[] Items = new Item[20];

or in a static constructor.


2) What I am trying to do is create a self contained .cs file that has the
definitions for the 24 items I will use (hopefully setup so I could easily
use this class file in another game).
Where would I define the items if I wanted it to be a self contained file
for portability?
Personally, I would use a non-code file of some sort which your code loads
and generates items instead of writing them directly into source, but it
depends on what you want to do.
3) One last question. Why does "public static readonly Item[] Items;"
work?
Is this an example of a indexer? I am trying to understand indexers, and
haven't quite got a grasp on them.

Its an example of a readonly static field. You cannot have a static indexer,
but the Array class *does* have an indexer. So by writing Items[a] you are
accesing the indexer of the return value of the Items field.

Hope that makies sense, -_- THANKS!

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1512
by: LRW | last post by:
This is mySQL 101. I know it's supposed to be super simple, but I'm an idiot. I can't get my join to work (1st time I've tried doing joins.) I've read http://www.mysql.com/doc/en/JOIN.html, but I'm just not groking it. When I try to do the same thing, I can't "convert" one field into the data from another. Here's what I have. To test this concept I made two tables on a database called db_join:
8
13087
by: Charlotte Henkle | last post by:
Hello; I'm pondering how to count the number of times an item appears in total in a nested list. For example: myList=,,] I'd like to know that a appeared three times, and b appeared twice, and the rest appeard only once.
0
381
by: LRW | last post by:
This has to do with mySQL 101. I know it's supposed to be super simple, but I'm an idiot. I can't get my join to work (1st time I've tried doing joins.) I've read http://www.mysql.com/doc/en/JOIN.html, but I'm just not groking it. When I try to do the same thing, I can't "convert" one field into the data from another. Here's what I have. To test this concept I made two tables on a
1
1568
by: Claude Vernier | last post by:
Hello, I'm a C# programmer. I have two projects. First, write an action scrolling game in C#, (portable to Windows Mobile eventually...), This game will look like The Adventure of Link from Nintendo, or Super Mario Bros... I didn't planned to use DirectX since all tutorials I have seen for DirectX are for 3D.
7
2860
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I found a bug that I can't figure out (believe me; I've tried everything and asked for help several times on the IRC-channel). The updateMsg() and iMsg() takes a list of message-lines as argument (or process a string to a list), and it'll output...
0
1719
by: raypjr | last post by:
Hi everyone. I need a little help with some parts of a word guessing game I'm working on. I have some parts done but unsure about others and could use a little advice. Any help is very much appreciated.Here is the code to give more detail: Dim GameOver As Boolean Dim NumWords As Integer, ThreeWordList(1000) As String, ThreeWordMeaning(1000) As String Dim R As Integer, WordsLeft(1000) As Integer Dim SecretWord As String,...
28
1807
by: G8tors | last post by:
I have a fantasy football league that I am keeping stats for in an Access Database. I need help coming up with a way to calclulate the winning % for each team for their entire career. What I have is a table with the following fields: Fantasy Team Season Week W/L Own Score Vs Opponent Opponent Score Game type
1
2107
by: javabeginner123 | last post by:
i have a java prob, and i have to solve it fast, but i'm just getting to know it, so plz help me solve it with full code completed, thanks so much. the prob is to create a monter fight and there is the description: The monsters are of a very strange kind, called "Bigmon". They have some basic characteristics, like attack and defense power, life points, a name, and a bonus factor that is used in special occasions. In this initial phase of the...
2
1727
by: shinerankin | last post by:
Hi Guys & Gals: I have a project with using flash that is updated with an xml file. The developer went belly up and is no longer assisting with anything. I need to write a simple html or php form to update and possibly edit current items in the xml file. Here is my current xml file: <?xml version="1.0" encoding="UTF-8"?><sports> <sport id="6" game="Softball" gameStatus="F" home="Tift County" away="Warner Robins" homeScore="0"...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10542
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4274
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.