示例#1
0
        /* ski accepts the data node, run, and rise to calculate how many times the skiier hits a tree */
        public static hitMiss ski(DataNode dnode, int over, int down)
        {
            int hits        = 0;
            var miss        = 0;
            int colPosition = 0;
            var numRows     = dnode.getNumberRows();
            var numCols     = dnode.getNumberColumns();

            char[,] data = dnode.getDataArray();
            var hitMissCounts = new hitMiss(0, 0); // to count our number of hits and misses

            for (int rowPosition = 0; rowPosition < numRows; rowPosition += down, colPosition += over)
            {
                //did we hit a tree?
                if (data[rowPosition, (colPosition % numCols)] == '#')
                {
                    hitMissCounts.updateHits(1);
                }
                else
                {
                    hitMissCounts.updateMiss(1);
                }
            }

            return(hitMissCounts);
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            //Read from file into our dataMap array
            var dataMap = readIntoArray(@"C:\Users\hojay\Downloads\SkiWorking\Skiing\Skiing_Amongst_Trees\TreeMap.txt");


            int run  = 3;
            int rise = 2;

            // call the ski function passing in the slope (over (run) 3 down (rise) 1 and the DataMap
            hitMiss hmcount = ski(dataMap, run, rise);

            //output the resutls to the viewer
            Console.WriteLine("With a slope of over " + run + " down " + rise + ", we hit " + hmcount.getHits() + " trees and missed the other " + hmcount.getMiss() + " trees.");
        }