Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions C#/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# MS Visual Studio
*.suo
*.csproj.user
*.user
.vs/
obj/
bin/
packages/
.paket/
52 changes: 52 additions & 0 deletions C#/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/Trivia/TriviaDotNetCore/bin/Debug/netcoreapp1.0/TriviaDotNetCore.dll",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"externalConsole": false
},
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceRoot}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command.pickProcess}"
}
]
}
17 changes: 17 additions & 0 deletions C#/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [ "Trivia/TriviaDotNetCore/" ],
"isBuildCommand": true,
"showOutput": "silent",
"problemMatcher": "$msCompile"
}
]
}
22 changes: 22 additions & 0 deletions C#/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Trivia kata - C# version
========================

It can be used with Visual Studio or Visual Code (including on Linux/MacOS).

Visual Studio
-------------

"Ideal" setup would include :
- [Resharper](https://www.jetbrains.com/resharper/) (for academic/students/training, you can request a free licence)
- [NCrunch](http://www.ncrunch.net/)

I you don't have DotNetCore, remove the corresponding project to avoid compilation errors.

Visual Code
-----------

Need to install DotNetCore (1.0 at least).

Add the C# extensions in VSCode.

Open the Trivia.sln file with "omnisharp" VSCode command.
56 changes: 36 additions & 20 deletions C#/Trivia/Trivia.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trivia", "Trivia\Trivia.csproj", "{6DF4340A-A044-4593-BC79-8F7961BB91E7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6DF4340A-A044-4593-BC79-8F7961BB91E7}.Debug|x86.ActiveCfg = Debug|x86
{6DF4340A-A044-4593-BC79-8F7961BB91E7}.Debug|x86.Build.0 = Debug|x86
{6DF4340A-A044-4593-BC79-8F7961BB91E7}.Release|x86.ActiveCfg = Release|x86
{6DF4340A-A044-4593-BC79-8F7961BB91E7}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Trivia", "Trivia\Trivia.csproj", "{6DF4340A-A044-4593-BC79-8F7961BB91E7}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TriviaDotNetCore", "TriviaDotNetCore\TriviaDotNetCore.xproj", "{B3F603C7-3911-4259-9B81-0FBC5FBB2AA1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6DF4340A-A044-4593-BC79-8F7961BB91E7}.Debug|Any CPU.ActiveCfg = Debug|x86
{6DF4340A-A044-4593-BC79-8F7961BB91E7}.Debug|x86.ActiveCfg = Debug|x86
{6DF4340A-A044-4593-BC79-8F7961BB91E7}.Debug|x86.Build.0 = Debug|x86
{6DF4340A-A044-4593-BC79-8F7961BB91E7}.Release|Any CPU.ActiveCfg = Release|x86
{6DF4340A-A044-4593-BC79-8F7961BB91E7}.Release|x86.ActiveCfg = Release|x86
{6DF4340A-A044-4593-BC79-8F7961BB91E7}.Release|x86.Build.0 = Release|x86
{B3F603C7-3911-4259-9B81-0FBC5FBB2AA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3F603C7-3911-4259-9B81-0FBC5FBB2AA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3F603C7-3911-4259-9B81-0FBC5FBB2AA1}.Debug|x86.ActiveCfg = Debug|Any CPU
{B3F603C7-3911-4259-9B81-0FBC5FBB2AA1}.Debug|x86.Build.0 = Debug|Any CPU
{B3F603C7-3911-4259-9B81-0FBC5FBB2AA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3F603C7-3911-4259-9B81-0FBC5FBB2AA1}.Release|Any CPU.Build.0 = Release|Any CPU
{B3F603C7-3911-4259-9B81-0FBC5FBB2AA1}.Release|x86.ActiveCfg = Release|Any CPU
{B3F603C7-3911-4259-9B81-0FBC5FBB2AA1}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
2 changes: 0 additions & 2 deletions C#/Trivia/Trivia/.gitignore

This file was deleted.

214 changes: 214 additions & 0 deletions C#/Trivia/TriviaDotNetCore/Game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UglyTrivia
{
public class Game
{


List<string> players = new List<string>();

int[] places = new int[6];
int[] purses = new int[6];

bool[] inPenaltyBox = new bool[6];

LinkedList<string> popQuestions = new LinkedList<string>();
LinkedList<string> scienceQuestions = new LinkedList<string>();
LinkedList<string> sportsQuestions = new LinkedList<string>();
LinkedList<string> rockQuestions = new LinkedList<string>();

int currentPlayer = 0;
bool isGettingOutOfPenaltyBox;

public Game()
{
for (int i = 0; i < 50; i++)
{
popQuestions.AddLast("Pop Question " + i);
scienceQuestions.AddLast(("Science Question " + i));
sportsQuestions.AddLast(("Sports Question " + i));
rockQuestions.AddLast(createRockQuestion(i));
}
}

public String createRockQuestion(int index)
{
return "Rock Question " + index;
}

public bool isPlayable()
{
return (howManyPlayers() >= 2);
}

public bool add(String playerName)
{


players.Add(playerName);
places[howManyPlayers()] = 0;
purses[howManyPlayers()] = 0;
inPenaltyBox[howManyPlayers()] = false;

Console.WriteLine(playerName + " was added");
Console.WriteLine("They are player number " + players.Count);
return true;
}

public int howManyPlayers()
{
return players.Count;
}

public void roll(int roll)
{
Console.WriteLine(players[currentPlayer] + " is the current player");
Console.WriteLine("They have rolled a " + roll);

if (inPenaltyBox[currentPlayer])
{
if (roll % 2 != 0)
{
isGettingOutOfPenaltyBox = true;

Console.WriteLine(players[currentPlayer] + " is getting out of the penalty box");
places[currentPlayer] = places[currentPlayer] + roll;
if (places[currentPlayer] > 11) places[currentPlayer] = places[currentPlayer] - 12;

Console.WriteLine(players[currentPlayer]
+ "'s new location is "
+ places[currentPlayer]);
Console.WriteLine("The category is " + currentCategory());
askQuestion();
}
else
{
Console.WriteLine(players[currentPlayer] + " is not getting out of the penalty box");
isGettingOutOfPenaltyBox = false;
}

}
else
{

places[currentPlayer] = places[currentPlayer] + roll;
if (places[currentPlayer] > 11) places[currentPlayer] = places[currentPlayer] - 12;

Console.WriteLine(players[currentPlayer]
+ "'s new location is "
+ places[currentPlayer]);
Console.WriteLine("The category is " + currentCategory());
askQuestion();
}

}

private void askQuestion()
{
if (currentCategory() == "Pop")
{
Console.WriteLine(popQuestions.First());
popQuestions.RemoveFirst();
}
if (currentCategory() == "Science")
{
Console.WriteLine(scienceQuestions.First());
scienceQuestions.RemoveFirst();
}
if (currentCategory() == "Sports")
{
Console.WriteLine(sportsQuestions.First());
sportsQuestions.RemoveFirst();
}
if (currentCategory() == "Rock")
{
Console.WriteLine(rockQuestions.First());
rockQuestions.RemoveFirst();
}
}


private String currentCategory()
{
if (places[currentPlayer] == 0) return "Pop";
if (places[currentPlayer] == 4) return "Pop";
if (places[currentPlayer] == 8) return "Pop";
if (places[currentPlayer] == 1) return "Science";
if (places[currentPlayer] == 5) return "Science";
if (places[currentPlayer] == 9) return "Science";
if (places[currentPlayer] == 2) return "Sports";
if (places[currentPlayer] == 6) return "Sports";
if (places[currentPlayer] == 10) return "Sports";
return "Rock";
}

public bool wasCorrectlyAnswered()
{
if (inPenaltyBox[currentPlayer])
{
if (isGettingOutOfPenaltyBox)
{
Console.WriteLine("Answer was correct!!!!");
purses[currentPlayer]++;
Console.WriteLine(players[currentPlayer]
+ " now has "
+ purses[currentPlayer]
+ " Gold Coins.");

bool winner = didPlayerWin();
currentPlayer++;
if (currentPlayer == players.Count) currentPlayer = 0;

return winner;
}
else
{
currentPlayer++;
if (currentPlayer == players.Count) currentPlayer = 0;
return true;
}



}
else
{

Console.WriteLine("Answer was corrent!!!!");
purses[currentPlayer]++;
Console.WriteLine(players[currentPlayer]
+ " now has "
+ purses[currentPlayer]
+ " Gold Coins.");

bool winner = didPlayerWin();
currentPlayer++;
if (currentPlayer == players.Count) currentPlayer = 0;

return winner;
}
}

public bool wrongAnswer()
{
Console.WriteLine("Question was incorrectly answered");
Console.WriteLine(players[currentPlayer] + " was sent to the penalty box");
inPenaltyBox[currentPlayer] = true;

currentPlayer++;
if (currentPlayer == players.Count) currentPlayer = 0;
return true;
}


private bool didPlayerWin()
{
return !(purses[currentPlayer] == 6);
}
}

}
Loading