open System open System.IO // _____ _ _ _____ _____ _____ ______ _ _ _____ _____ _ //| __ \ | | | ___/ ___/ ___| | ___|| || |_| _ || _ | | //| | \/ | | | |__ \ `--.\ `--. | |_ |_ __ _| | | || | | | | //| | __| | | | __| `--. \`--. \ | _| _| || |_| | | || | | | | //| |_\ \ |_| | |___/\__/ /\__/ / | | |_ __ _\ \_/ /\ \_/ / |____ // \____/\___/\____/\____/\____/ \_| |_||_| \___/ \___/\_____/ // // let game() = let mutable notFound = true let fivetimestable = seq { for i in 5 .. 5 .. 100 do yield i } let random = new Random(System.DateTime.Now.Millisecond) let next = random.Next(10) let ans = (Seq.nth next fivetimestable) Console.WriteLine("What's your name?") let name = Console.ReadLine() Console.WriteLine("Guess!") let mutable goes = 1 let stopWatch = new System.Diagnostics.Stopwatch() stopWatch.Start() |> ignore while notFound do let guess = System.Int32.Parse(System.Console.ReadLine()) if ans.Equals(guess) then notFound <- false stopWatch.Stop() |> ignore else goes <- goes + 1 Console.BackgroundColor <- ConsoleColor.Blue let time = (stopWatch.ElapsedMilliseconds / 1000L) Console.WriteLine("You did it {0} it took you {1} goes in {2} seconds", name, goes, time) name, goes, time let highscore(result) = let name, goes, time = result let fileName = Environment.CurrentDirectory + "/highscores.txt" let scores = File.ReadAllLines(fileName) let newScore = [| String.Format("{0}, {1}, {2}", name.ToString(), goes.ToString(), time.ToString()) |] let newHighScores = Seq.append scores newScore File.WriteAllLines(fileName, newHighScores) newHighScores |> Seq.iter (fun l -> Console.WriteLine(l)) () [] let main argv = // Should be broken down into loads of lovely little funcs but..... // _ _______ _ _____ //\ \ / / _ | | | _ | // \ V /| | | | | | | | | // \ / | | | | | | | | | // | | \ \_/ / |___\ \_/ / // \_/ \___/\_____/\___/ // let result = game() highscore(result) |> ignore Console.ReadKey() |> ignore 0 // return an integer exit code // this needs to be in a file called highscores.txt // .__ _____ .__ //| | ____ _____ ____ __ __ ____ _____/ ____\ __ _ _|__| ____ //| | _/ __ \\__ \ / ___\| | \_/ __ \ / _ \ __\ \ \/ \/ / |/ \ //| |_\ ___/ / __ \_/ /_/ > | /\ ___/ ( <_> ) | \ /| | | \ //|____/\___ >____ /\___ /|____/ \___ > \____/|__| \/\_/ |__|___| / // \/ \//_____/ \/ \/ // //Name, Goes, Time