|
You could use a Dictionary<string,string>
and do this:
Dictionary<string,string> myFields = new Dictionary<string,string>();
myFields.Add("x1", "Hello");
myFields.Add("x27", "Hi");
myFields.Add("x99", "Hey"); and then access them like this:
MessageBox.Show(myFields["x1"]);
or even:
string x1 = "x1";
string x27 = "x27";
string x99 = "x99";
MessageBox.Show(myFields[x1]);
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 25-Apr-19 15:40pm.
|
|
|
|
|
Or even:
string x1 = nameof(x1);
string x27 = nameof(x27);
string x99 = nameof(x99);
Dictionary<string,string> myFields = new Dictionary<string,string>();
myFields.Add(x1, "Hello");
myFields.Add(x27, "Hi");
myFields.Add(x99, "Hey");
MessageBox.Show(myFields[x1]);
Because "magic strings" are evil.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I forgot about nameof . I like that option.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I'm working on an adventure game and looking for some tips about coding the use of doors in rooms. I've got objects in rooms working fine, but trying to work out how to code for doors. Would you code for the door being an object in a room, but then the object is effectively in two rooms?
|
|
|
|
|
I'm assuming that this is more like a text adventure with pictures or a point and click type game.
Seems like you would just want treat the Room as an object with child objects. So the door that leads to Room B from From Room A would really only exist in Room A and the door in Room B that leads to Room A would be a different object. After all you are loading a new room when you leave one and go to the other.
If this is a 3D or 2D Iso type game then the labryinth would be one big room with smaller rooms inside and you just have to deal with the door allowing/blocking line of sight or fog of war.
Anyway, my thoughts, take it all with a grain of salt.
Jack of all trades, master of none, though often times better than master of one.
|
|
|
|
|
Hi It's a text adventure.
Thank You for your thoughts. As you mentioned, I too thought about creating a pair of objects for each door, and then putting them in their appropriate locations.I'll have a go with that method. Just wanted to see if this was a good way forward. Enjoying the codeproject site, lots of good programming ideas. Thanks for your reply - much appreciated.
|
|
|
|
|
No, I'd make "doors" a different class of "location attribute" - a "Direction" in which the player can move. That way, walking through a door is just the same as walking along a corridor - it moves you from "room 12: kitchen" to "room 24: dining room" just as walking north along a corridor takes you from "corridor 1: south end" to "corridor 2: north end". The opposite direction in the "new" room take you back to the previous (normally but adventure games have exceptions to that sometimes).
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi - Thanks for the reply. I've got a location and an exit attribute, but was struggling with how a door attribute might work.
|
|
|
|
|
I assume that you can interact with objects in the room?
In that case I would probably move into the direction of: door is an object, interacting with it "hides it" or "shows it" (open/close). If you remove it you can move into the direction of the "open door" resulting in a location outside the room's boundaries, in which case you know you need to load another room. In case of the closed door, the object blocks your way.
Even better would be to add properties to objects for example: can walk over, or can walk through. A "barrel" is something you can't walk over, but a piece of paper you can. Other objects you can pickup, push, look at, use, ...
makes sense?
|
|
|
|
|
Hi - Yes, I've been using these ideas, and it works very will. For example get the object, only works if its getable property is true. Openable = True etc.
But Doors I'm thinking are a bit different as they are effectively in two locations. When you open the door in one location, the door in the adjacent location also opens.
|
|
|
|
|
I can't find the article now but a few days ago this was posted from CP, I think. It is a github site where they published the source for all the old infocom games written in ZIL. The other link to Learning ZIL takes you to the book. On the right hand side you can get the book in a PDF form. The key takeaway is that chapter three explains the ZIL code for a room. You might find the logic behind the code interesting.
historicalsource[^]
Learning_ZIL_Steven_Eric_Meretzky_1995[^]
Jack of all trades, master of none, though often times better than master of one.
|
|
|
|
|
|
I would define "doors" as a Class with state
open, closed, locked, unlocked, visible, invisible
with access permissions:
can close, can open ... set by functions in the main game engine that evaluate current game/player state
In the context of the Room Class, you could have any number of doors.
I would keep a data structure that maps doors to the room they connect to.
There's a lot to think about: should there be a collection of all Doors; should Doors have references to both rooms they connect ?
Have fun !
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Hi - Thanks - Definitely lots to think about. Given me some ideas to start planning.
|
|
|
|
|
Member 14122184 wrote: Given me some ideas to start planning. The key idea is that you start by making an outline of the structure/flow of the game, and a list of requirements.
You have to decide if the game is single-player, multi-player, player against player, etc. Does the game embody objects/players in 3d space, or 2d ? Will the game require a complex engine, like Unity ?
Experiment by writing out different scenarios for how the game begins, progresses, is scored, ends. Try sketching out tree-diagrams for the game structure, and state-machine diagrams for flow-of-control.
If you are a relative newcomer to C# and .NET, I suggest you read this: [^]
You need to create an overview of the game ... then you can ask specific technical questions, and ask for more specific advice.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Hello, I have the feeling this question can become a discussions because there is a lot of parameters that can be change and I don't know what to do.
I'm trying to setup a azure pipeline. I already did this in the past but with template and not for a .NET Core web application. It was easy because I could use a template. For some reason, here, I could not chose any template. The Azure Pipeline tool directly ask me to edit a yml file. Maybe because my repository is a local DevOps repository? I have no idea.
I followed this tutorial: https://docs.microsoft.com/en-us/azure/devops/pipelines/languages/dotnet-core?view=azure-devops and created this yml file:
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
variables:
buildConfiguration: 'Release'
steps:
# - script: dotnet build --configuration $(buildConfiguration)
# displayName: 'dotnet build $(buildConfiguration)'
\- task: DotNetCoreInstaller@0
inputs:
version: '2.2.202' # replace this value with the version that you need for your project
\- script: dotnet restore
\- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration Release' # Update this to match your need
# do this after you've built your app, near the end of your pipeline in most cases
# for example, you do this before you deploy to an Azure web app on Windows
\- task: DotNetCoreCLI@2
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
# - task: PublishBuildArtifacts@1
# inputs:
# ArtifactName: 'drop'
Here is my result: All is success except
<h1>##[section]Starting: DotNetCoreCLI</h1>
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
Version : 2.150.1
Author : Microsoft Corporation
<h1>Help : <a href="https://go.microsoft.com/fwlink/?linkid=832194">More Information</a></h1>
##[error]No web project was found in the repository. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory.
##[error]Project file(s) matching the specified pattern were not found.
##[section]Finishing: DotNetCoreCLI</pre>
[error]No web project was found in the repository. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory. Also with .NET Core? Till now I can run my project locally with my Visual Studio whithout this config file. I don't get it.
PS: Can also someone tell me why the markdown is still active between my code tags? Impossible to display a correct verison of my yml file. # are transformed as title and - as list.
-- modified 23-Apr-19 0:24am.
|
|
|
|
|
Never met an asp.net project that didn't have a web.config file ... somewhere.
Quote: The web.config file configures the ASP.NET Core Module.
Host ASP.NET Core on Windows with IIS | Microsoft Docs
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
So why the publish tell me the config file is missing when I want to publish on my azure web app? Publish I can do manually with no error. Arrrgggg Microsoft please help. You example are wrong.
|
|
|
|
|
Bastien Vandamme wrote: Microsoft please help. You example are wrong Have you told them?
|
|
|
|
|
I HOPE this is the correct forum for this, apologize if it isn't i only joined 2 days ago so getting used to using this website.
So i'm learning C# myself by trying to make a small game, it won't be released but I will probably in the end use it as a class project next year. I'm starting now so I got plenty of time to learn basics and skills to prepare for next classes. So, I have a couple of questions I need to ask to clear things up and possibly maybe some links you can point me to, ideas OR even some demos I could use to teach myself, so I can learn what exactly i'm looking for, thanks.
Each game screen will be in the style of a form (no bigger than 10 forms) where I will add graphics etc, the player will be able to click certain objects to pick them up and in some cases pick more than one up. Think kinda like an hidden object type game where the player uses the mouse pointer to search around the screen for items and progress through the game.
1. I will make one form the item bag (called ItemsBag) so, how will I be able to pick up items on one form and have them display in the ItemsBag form?
2. Some items will be used for quests so stock pilling items will be a must, I'm also thinking a label to display amounts in stock with each time you click an item on one form it updates the amount on the ItemsBag form. Is there a tutorial for this type of stuff?
3. Talking to people (will only be a couple of people), I gather the use of a TextBox would be the best way to go with this and have the TextBox display different chat. I have the chat working so far where I click on a character and I get the first lot of talking sorted BUT how can I change text at different times? and also from a different form?
So say one person sends me to go pick something up in another form and I have it in my bag, it will change the text in that NPCs form. Is there some type of tutorial on how to do this? I'm thinking maybe in the NPCs TextBox code maybe something like having it check if I have the item(s) collected in the ItemsBag Form using IF statements, and check if amount is correct.. is that a correct way OR easiest way to go about this?
well i'm sure I will have plenty of more questions in the coming months as I learn, hopefully I haven't asked to much, I look forward to your replies, suggestions and help, thanks.
|
|
|
|
|
|
Thanks for your reply.
I'll take a look but I think it will be no good for me as I have to code completely in C# on its own and that's for Unity engine also i'll keep that link book marked though as I'd like to look into unity at a later date.
|
|
|
|
|
Not too many tutorials / games that do not incorporate a game engine. Mind you, the original Adventure source code is now available; so, no "engine".
Eric S. Raymond / open-adventure · GitLab
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I can't think of a worse way to learn a language than to skip systematic study and go straight to trying to program some kind of game, with the idea (I assume) that you'll develop broad spectrum knowledge as you figure out what works ... for the game.
Now, if you have depth experience with other languages, with algorithms, with UI widget programming ... different story.
It's not a case of "hard work with no fun," either: there are very good books that will give you an overview, and many interesting programming challenges tailored for new students. Hands on experimentation while implementing these challenges will also give you ideas for your future game. Try: [^], or books by Jesse Liberty, and Chris Sells, or the Deitel textbook [^]. Search for the free book by Petzold.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
|