• Create Account

# Deprecated

Member Since 21 Nov 2009
Offline Last Active Jul 10 2012 04:31 PM

### #4900628Another Go at Programming - Advice appreciated

Posted by on 08 January 2012 - 07:40 AM

The first problems at http://projecteuler.net/problems are pretty easy to solve, although they should provide some challenge if you're not familiar with conditional statements, loops and/or functions.

Write a simple text-based game where the computer picks a random number and you have to guess that number. Make the computer tell you whether your guess was greater than, or smaller than the actual number.

Create a deck of cards, write functions to shuffle the deck, sort the deck, display the deck, pick a card from the deck and anything else that you would normally do with a deck of cards.

Write a simple text-based blackjack game where you play against the computer using the deck you designed earlier.

Try to solve the first 20 problems at http://projecteuler.net/problems, and make sure to read the papers you get for completing each challenge.

### #4900578Simple Class Problem

Posted by on 08 January 2012 - 02:22 AM

Even though there is a great difference between a hero and his/hers nemesis in real life, if you look at your code there is (almost) no difference at all. I'd suggest that you create a class Creature/Human/Entity instead and create two separate instances instead.

```class Entity {
private int health, strength, weaponStrength, defence;
private bool isAlive, isEvil;
private string identity;
public void Entity(int health, int strength, int weaponStrength, int defence, bool isAlive, bool isEvil, string identity) {
this.health = health;
this.strength = strength;
this.weaponStrength = weaponStrength;
this.defence = defence;
this.isAlive = isAlive;
this.isEvil = isEvil;
this.identity = identity;
}

public int getStrength() {
return this.strength;
}

public Calculate(Entity enemy) {
return this.strength - enemy.getStrength();
}
}

.....
Entity hero = Entity(100, ..., "Good Guy");
Entity nemesis = Entity(100, ..., "Nemesis");
```

Heads up, I've never written a single line of code in C# so the syntax may be a little off.. Took a guess from the code you provided. Although the concept should be correct.

P.S You should be using getters and setters instead of public variables, gives you more control over you code; google "getters and setters C#" and it should be one of the first results. D.S

Edit: Added a getter for strength.

PARTNERS