-
-
Save SlamJammington/1ae049234b88a51af27f940040b6c1d8 to your computer and use it in GitHub Desktop.
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; | |
using System.IO; | |
using System.Collections.Generic; | |
using System.Text; | |
/* | |
* WinLossRecorder | |
* Records, retrieves, and writes wins and losses for a given username | |
*/ | |
namespace WinLossRecorder | |
{ | |
public class WinLossRecorderCL | |
{ | |
public WinLossRecorderCL() | |
{ | |
if (File.Exists("WinRecord.txt")) | |
{ | |
return; | |
} | |
else | |
{ | |
File.CreateText("WinRecord.txt"); | |
File.CreateText("WinRecord.txt").Close(); | |
} | |
} | |
// displays record for given user | |
public void displayWinLossRecord(string user) | |
{ | |
int userWins = 0; | |
int userLosses = 0; | |
string winText = user + " win"; | |
string lossText = user + " loss"; | |
var winFile = File.ReadAllLines("WinRecord.txt"); | |
foreach (string entry in winFile) | |
{ | |
if (winText == user) | |
{ | |
userWins = userWins + 1; | |
} | |
else if (lossText == user) | |
{ | |
userLosses = userLosses + 1; | |
} | |
} | |
if(userLosses == 0 && userWins == 0) | |
{ | |
Console.WriteLine("No log for " + user + " found!"); | |
return; | |
} | |
decimal winLossRatio = userWins / userLosses; | |
Console.WriteLine(user + "'s stats \n ━━━━━━━━━━━━━━━━━━━━━━━━━━━━"); | |
Console.WriteLine("Wins : " + userWins.ToString() + "\nLosses : " + userLosses.ToString() + "\nW/L Ratio : " + winLossRatio.ToString()); | |
} | |
/* adds a win/loss record for given user | |
* user : username | |
* status : win or loss, valid params : "win","loss" | |
*/ | |
public void addWinLossRecord(string user, string status) | |
{ | |
// don't need to validate "status" = as it's not user input | |
status = status.ToLower(); | |
File.AppendAllText("WinRecord.txt", user + " " + status); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment