Compare your project to our solution code and share your project below! Your solution might not look exactly like ours, and that’s okay! The most important thing right now is to get your code working as it should (you can always refactor more later). There are multiple ways to complete these projects and you should exercise your creative abilities in doing so.
This is a safe space for you to ask questions about any sample solution code and share your work with others! Simply reply to this thread to get the conversation started. Feedback is a vital component in getting better with coding and all ability levels are welcome here, so don’t be shy!
About community guidelines: This is a supportive and kind community of people learning and developing their skills. All comments here are expected to keep to our community guidelines
How do I share my own solutions?
If you completed the project off-platform, you can upload your project to your own GitHub and share the public link on the relevant project topic.
If you completed the project in the Codecademy learning environment, use the share code link at the bottom of your code editor to create a gist, and then share that link here.
Do I really need to get set up on GitHub?
Yes! Both of these sharing methods require you to get set up on GitHub, and trust us, it’s worth your time. Here’s why:
Once you have your project in GitHub, you’ll be able to share proof of your work with potential employers, and link out to it on your CV.
It’s a great opportunity to get your feet wet using a development tool that tech workers use on the job, every day.
Not sure how to get started? We’ve got you covered - read this article for the easiest way to get set up on GitHub.
Best practices for asking questions about the sample solution
Be specific! Reference exact line numbers and syntax so others are able to identify the area of the code you have questions about.
Hey! It seems pretty weird, I cannot find out what the issue is with my code.
I was pretty close to the solution and I fixed everything (mostly private setters and fixed the if else statements on the ask() method, but fixed that).
Here is my code! (code on the bottom aswell) https://gist.github.com/3b317603b85623d89eb7b8181a572716
I’m mostly getting errors on the codewords array line (for my project, line 16) saying that it can’t convert string to int. I don’t know where it is going that requires it to be an int.
Line 26 I get an error on the int i.
I’m I bit distressed by this, any help please?
Also, if anyone got some spare time, I still can’t grasp on why do we need to use private setters for the properties that have a setter. I guess I still don’t get getters, setters and privacy.
using System;
namespace Spaceman
{
class Game
{
public string CodeWord
{ get; private set; }
public string CurrentWord
{ get; private set; }
public int MaxGuesses
{ get; }
public int NumGuesses
{ get; private set; }
private string cwArray = new string[“aperture”, “limit”, “stars”, “light”, “rigid”];
Ufo ufo = new Ufo();
public Game()
{
Random gen = new Random();
CodeWord = cwArray[gen.Next(0, 5)];
MaxGuesses = 5;
NumGuesses = 0;
for (int i; i < CodeWord.Length; i++)
{
CurrentWord += "_";
}
}
public void Display()
{
Console.WriteLine(ufo.Stringify());
Console.WriteLine("The Current Word is: " + CurrentWord);
Console.WriteLine($"You have {NumGuesses} attempts");
}
public void Ask()
{
Console.WriteLine("Hey human! Try to guess a letter or I'll take this other human!");
string answer = Console.ReadLine();
Console.WriteLine();
if (answer.Trim().Length != 1)
{
Console.WriteLine("Please, one letter at a time.");
return;
}
char charCode = answer.Trim().ToCharArray()[0];
if (CodeWord.Contains(charCode))
{
Console.WriteLine("You've got it right!");
for (int i = 0; i < CurrentWord.Length; i++)
{
if (CodeWord[i] == charCode)
{
CurrentWord = CurrentWord.Remove(i, 1).Insert(i, charCode.ToString());
}
}
}
else
{
NumGuesses++;
ufo.AddPart();
}
}
public bool DidWin()
{
if (CodeWord.Equals(CurrentWord))
{ return true; }
else { return false; }
}
public bool DidLose()
{
if (NumGuesses >= MaxGuesses)
{ return true; }
else { return false; }
}
public void Greet()
{
Console.WriteLine("Hello there Player!");
}
}
I’m assuming you got this sorted out by now, but just for reference, the first issue is happening because it’s treating your strings as indexes, not values - just a simple syntax error. Here’s the corrected syntax:
I was discouraged that I had to cheat and consult the solution in order to overcome a few errors, but I ended up learning that certain things can’t work at least. This was a good, difficult exercise.
Hi all, here is my project Spaceman finally finished.
But I don’t understand why the words of more than 7 letters don’t play well, I try to understand but I can’t find or give me an Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.String.get_Chars(Int32 index)
at Spaceman.Game.Ask() in /home/ccuser/workspace/csharp-spaceman/Game.cs:line 69
at Spaceman.Program.Main(String args) in /home/ccuser/workspace/csharp-spaceman/Program.cs:line 17
in sharedFiles i put a copy of spaceman3… the most up to date so far but still working on editing the images and adding words… for one thing it has an extra wrong guess because 5 total was brutal…
/* Invaders from outer space have arrived and are abducting
* humans using tractor beams. Players must crack the codeword
* to stop the abduction. On the 6th accumulated miss the game
* ends with a loss and the choice is given to start a new game.
*
* Also the player can exit any time via pressing Control+C.
* The text colors are selected to work best with the display
* having its colors ionverted via system settings. Flags have
* been set up to make sure colors revert to original settings when
* a player enters Control+C. */