![]() |
| ||
| noob question Hi guys, i downloaded visual c# 2008 about a month ago and have been trying stuff out for myself. I'm attempting to make a text based RPG, i made big progress but i'm stuck now. Basically i want to show the player's HP in green whenever he has 51 to 100% of the maximum HP for his level, yellow from 26 - 50HP and red when below 25%. My code shows the HP in green from 100% all the way down to 25%, going directly to red and bypassing yellow, how do i fix this? here's the code. if (ok.player > 51% ok.maxhp) a person in another forum gave me the following solution, but it didn't work, instead it showed the HP in green from 100 to 0% never changing color. decimal one_percent = (decimal)(ok.maxhp / 100); |
| ||
| Re: noob question I downloaded it about a year ago, still learning:cool: but I believe I can help. Your code : if (ok.player > 51% ok.maxhp) The % is not what you think a percentage, it is the modulo operator! So you are comparing something against 51 modulo ok.maxhp, which is not what you want. Other persons code : decimal one_percent = (decimal)(ok.maxhp / 100); ok.maxhp / 100 is an integer divide, if maxhp is never greater than 100, one_percent will always be zero! This is my code, hope it helps. You only have to restore the ok variable in it. double maxhp = 55; |
| ||
| Re: noob question Thank you very much for your reply. I have no doubt that code works, sadly yesterday night after posting the question i changed around some stuff in other code of the same program and now a lot of stuff doesn't work, i hate that i get no error messages, but the game still doesn't work as intended. Basically i had 2 classes, one full of getters and setters with info, and another called world, where everthing took place in the game. But i wanted to create a class called "fight" and take my fighting code over there to make it a bit more manageable since my "world" class had around 1000 lines of code already. But some info from the world and "items" class doesn't travel to my fight class, i heard that in c# you're only allowed to send info from 1 class to another and not more, if that's true, do i HAVE to make all my code in 1 class? I'm starting college in January and i want to at least know a little something before i get there, i think everyone that takes a computer science program already knows a thing or two. |
| ||
| Re: noob question >i heard that in c# you're only allowed to send info from 1 class to another and not more In C# you can't have multiple inheritance, if it is that what you mean. You can have many classes working together if you want to. |
| All times are GMT -4. The time now is 9:27 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC