Created
September 19, 2018 04:10
-
-
Save janellbaxter/5bc103f4954ef94278d76c2bf8d0bd5a to your computer and use it in GitHub Desktop.
Experimental example for Introduction to Programming showing classes, objects, if/else and other programming conepts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace PenguinSuperHero | |
{ | |
class Penguin | |
{ | |
string Name = "Anonymous Penguin"; | |
string Location = "Nowhere"; | |
bool Superhero = false; | |
double Points = 0; | |
//constructor - doesn't have a return type | |
public Penguin(string passedInName, string passedInLocation, bool passedInSuperhero) | |
{ | |
Name = passedInName; | |
Location = passedInLocation; | |
Points = 0; | |
Superhero = passedInSuperhero; | |
Console.WriteLine("Penguin name: " + Name); | |
Console.WriteLine("Location: " + Location); | |
Console.WriteLine("Points: " + Points); | |
if (Superhero == true) | |
{ | |
Console.WriteLine(Name + " is a superhero!"); | |
} | |
else | |
{ | |
Console.WriteLine(Name + " is penguin of the \"people\"."); | |
} | |
Console.WriteLine("\n"); | |
} | |
void Talk() | |
{ | |
} | |
void Eat() | |
{ } | |
void Act() { } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace PenguinSuperHero | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
string playerName = "Anonymous"; | |
string penguinLocation = ""; | |
string location = "Chicago"; | |
Console.Title = "Superhero Penguins!"; | |
Console.WriteLine("Welcome to Penguin World\nHere are the penguins currently in game:\n\n"); | |
Penguin billy = new Penguin("Billy", "Chicago", true); | |
Penguin bob = new Penguin("Bob", "Paris", false); | |
Console.WriteLine("Welcome Player One, what is your penguin's name?"); | |
playerName = Console.ReadLine(); | |
Console.WriteLine("Is your penguin starting in a) Amsterdam, b) Beijing, or c) Chicago"); | |
penguinLocation = Console.ReadLine(); | |
penguinLocation = penguinLocation.ToLower(); | |
if (penguinLocation == "a") | |
{ | |
location = "Amsterdam"; | |
} | |
else if (penguinLocation == "b") | |
{ | |
location = "Beijing"; | |
} | |
else | |
{ | |
location = "Chicago"; | |
} | |
Penguin playerOne = new Penguin(playerName, location, false); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment