Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,124 members, 7,957,219 topics. Date: Tuesday, 24 September 2024 at 09:21 AM |
Nairaland Forum / Science/Technology / Programming / C# Question........help??? (1341 Views)
Question Question Question! Help In Need. / Please Help Me Solve This C++ Question / C++ Question (2) (3) (4)
C# Question........help??? by kaimeraone: 5:45pm On May 29, 2012 |
Hi folks, please can you guys help me solve this question, need to submit it asap. not really a programming person but am taking a course that needs it. Cheers PS: Question TASK 1: Structural programming (Keywords: variables, logical operators, statements, loops) Write a program “Pokémon”, which includes the following variables: hunger, happiness, fight, energy. Each round the player should enter an action e.g. p = play. The values for happiness should be increased then by 5, energy should be decreased by 10 and hunger increased by 4. Another action could be s = sleep, where energy is increased by 30 and hunger increased by 5. Implement at least two other actions of your own choice. Rules: hunger, happiness, fight, energy have a range of values between 0 and 100. Choose the right data type. If energy is smaller than 15, the happiness decreases by 1 each round. If hunger is greater than 90, happiness decreases by 3 each round. End: The Pokémon dies if a value is not between the range of 0 and 100. Better implement a warning for the player in time. If the game ends display the number of rounds on the console.
|
Re: C# Question........help??? by lordZOUGA(m): 5:57pm On May 29, 2012 |
doing this in C++ will be kool tho |
Re: C# Question........help??? by dolipop(f): 1:51am On May 30, 2012 |
will get the code across to u.. later today. do u want it in console or windows forms |
Re: C# Question........help??? by kaimeraone: 7:55am On May 30, 2012 |
dolipop: will get the code across to u.. later today. do u want it in console or windows forms thnx dolipop, console would be fine. both would be great though [kaimeraone@gmail.com] |
Re: C# Question........help??? by Kobojunkie: 11:48am On May 30, 2012 |
You are taking a programming course and you are not really a programming person? Why are you here to waste our time then? |
Re: C# Question........help??? by mkwayisi: 12:28pm On May 30, 2012 |
Kobojunkie: You are taking a programming course and you are not really a programming person? Why are you here to waste our time then?I don't think the OP asked Kobojunkie anything. Rather, he asked anyone who wouldn't mind wasting his/her time to provide a solution. So if someone is wasting *your* time, well, it's you yourself ;-) |
Re: C# Question........help??? by Kobojunkie: 12:40pm On May 30, 2012 |
Kobojunkie: You are taking a programming course and you are not really a programming person? Why are you here to waste our time then? |
Re: C# Question........help??? by kaimeraone: 7:25pm On Jun 01, 2012 |
Hey guys, anyone with a solution yet? have a blessed weekend. cheers |
Re: C# Question........help??? by solomon201(m): 3:15pm On Jun 03, 2012 |
Check this one. It starts with random values for ur attributes This is the Pokemon.cs file: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Pokemon { class Pokemon { public int hunger { get; set; } public int Happiness { get; set; } public int Fight {get; set;} public int Energy { get; set; } public Pokemon() { Random gen = new Random(DateTime.Now.Second); hunger = gen.Next(40, 60); Happiness = gen.Next(50, 70); Fight = gen.Next(25, 60); Energy = gen.Next(30, 70); } public void Play() { Happiness += 5; Energy -= 10; hunger += 4; CheckRules(); } private void CheckRules() { if (Energy < 15) Happiness -= 1; if (hunger > 90) Happiness -= 3; } public void Sleep() { Energy += 30; hunger -= 5; CheckRules(); } public void Eat() { hunger -= 10; Happiness += 3; CheckRules(); } public void Work() { hunger += 15; Energy -= 10; } public bool IsGameStillValid() { if (Happiness < 0 || Happiness > 100) return false; if (hunger < 0 || hunger > 100) return false; if (Fight < 0 || Fight > 100) return false; if (Energy < 0 || Energy > 100) return false; return true; } public void DisplayStats() { Console.WriteLine("Value of your Attributes are:" Console.WriteLine("Happiness: {0}",Happiness); Console.WriteLine("Hunger: {0}", hunger); Console.WriteLine("Fight: {0}", Fight); Console.WriteLine("Energy: {0}", Energy); } } } And this is the Program.cs file using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Pokemon { class Program { static void Main(string[] args) { Console.WriteLine("\t\t\tWelcome to Pokemon!!!" Console.Write("\t\t" for(int x=0;x<35;x++) Console.Write("*" Console.WriteLine(); bool IsValid; int rounds=0; string choice=null; Pokemon you= new Pokemon(); IsValid=you.IsGameStillValid(); Console.WriteLine(); you.DisplayStats(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Warning!!!!\nIf any of your attributes is below 0 or above 100 the game ends" Console.WriteLine(); Console.WriteLine("Game on Press any key to begin..." Console.ReadLine(); Console.Clear(); DisplayMenu(); while(IsValid) { rounds+=1; choice=Console.ReadLine(); choice=choice.ToUpper(); switch(choice) { case "S": you.Sleep(); break; case "P": you.Play(); break; case "E": you.Eat(); break; case "W": you.Work(); break; default: { Console.WriteLine("Invalid Choice Made " Console.ReadLine(); Console.WriteLine(); return; } } IsValid=you.IsGameStillValid(); Console.Clear(); Console.WriteLine("Game Still On!" Console.WriteLine(); you.DisplayStats(); Console.WriteLine(); DisplayMenu(); } Console.WriteLine(); Console.WriteLine("You Played {0} rounds of Pokemon and finished with the following Stats",rounds); Console.WriteLine(); you.DisplayStats(); Console.ReadLine(); } private static void DisplayMenu() { Console.WriteLine("Select Action\n" Console.WriteLine("P=Play" Console.WriteLine("S=Sleep" Console.WriteLine("E=Eat" Console.WriteLine("W=Work" } } } Hope it close to what u need if not modify 1 Like |
(1) (Reply)
Did You Guys Do These At School? / Help A Newbie Php Programmer / Let's Code
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 22 |