static void printOut(Player[] array, int playerAmount, errorCount err) { int total = 0; int frameS = 0; for (int i = 0; i < playerAmount; i++) { total = 0; for (int j = 0; j < MAXFRAME; j++) { Console.WriteLine("Player: " + i + " FRAME: " + array[i].getFrame(j)); frameS = array[i].getFrameScore(j); Console.WriteLine("BALL ONE: " + array[i].getBallOne(j)); Console.WriteLine("BALL TWO: " + array[i].getBallTwo(j)); Console.WriteLine("Frame Score: " + frameS); total += frameS; } Console.WriteLine("------------------------------------"); Console.WriteLine("Player: " + i + " Total Score: " + total + " Total Errors: " + err.count ); Console.WriteLine("------------------------------------"); } }
static void valueHandler(int frame, int value, int player, int ball, Player[] array) { //Console.WriteLine("Frame: " + frame + " Player: " + player + " Ball: " + ball + " Value: " + value); array[player].addToArray(frame, value, ball); }
static void Main(string[] args) { //vars //string fileName = ""; int curBall = 0; //read in file FROM INSTRUCTIONS data will be either on ONE line or split on lines so split on space and new line //Console.WriteLine("Enter bowling text file please:"); //fileName = Console.ReadLine(); try { // List<string> list = new List<string>(); List<int> list = new List<int>(); string line; do { line = Console.ReadLine(); if (line != "END") { bool check = int.TryParse(line, out curBall); if (check == true) { list.Add(curBall); //Console.WriteLine(curBall); } } } while (line != "END"); //handle the values Console.WriteLine("------------------------------------"); // Console.WriteLine(list[0] + " is the Number of players"); //get number of players for game(one for now //int numPlayers = list[0]; int numPlayers = 1; //list.RemoveAt(0);//we don't need that number anymore, pop it //int count = 0; Player[] playerArray = new Player[numPlayers]; for (int i = 0; i < numPlayers; i++) { playerArray[i] = new Player(); playerArray[i].playerNum = i; } int curPlayer = 0; errorCount errCnt = new errorCount(); if (numPlayers > 0) { curPlayer = 0; int ballNum = 1; // bool ballFilled = false; //bool strike = false; int frame = 1; int tenOne = 0; int tenTwo = 0; int past = 0; bool isStrike = false; bool isStrike2 = false; bool isSpare = false; bool isNormal = false; bool skip = false; bool skip2 = false; //valueHandler(frame, item, curPlayer, ballNum, playerArray); foreach (int item in list) { //Console.WriteLine(item + " CURRENT ITEM"); if (curPlayer > numPlayers - 1 && skip2 == false) { curPlayer = 0; frame++; } if (frame == MAXFRAME) { break; } if (frame < TEN) { switch (ballNum) { case 1: if (frameOk(frame, item, 0, errCnt) == true) { //ballFilled = true; if (item != TEN) { ballNum = 2; } if (item == TEN) { valueHandler(frame, item, curPlayer, ballNum, playerArray); curPlayer++; } past = item; } //Console.WriteLine("ball 1 " + item); break; case 2: // if (ballFilled == false && strike == false) // { if (frameOk(frame, item, 0, errCnt) == true) { if(frameOk(frame, past, item, errCnt) == true && past != TEN) { if (past + item <= TEN) { valueHandler(frame, past, curPlayer, 1, playerArray); valueHandler(frame, item, curPlayer, ballNum, playerArray); curPlayer++; ballNum = 1; skip2 = false; } } else { ballNum = 1; skip2 = true; } //Console.WriteLine("ball 2 " + item); // } } break; } } //jumbled code for handling 10th frame and extra frame if (frame == MAXFRAME - 1 && frameOk(frame, item, 0, errCnt) == true) { if (isSpare == true) { ballNum = 1; //Console.WriteLine("TEST"); valueHandler(MAXFRAME, item, curPlayer, ballNum, playerArray); isSpare = false; curPlayer++; skip = true; } if (isStrike2 == true) { ballNum = 2; valueHandler(MAXFRAME, item, curPlayer, ballNum, playerArray); skip = true; isStrike2 = false; ballNum = 1; curPlayer++; } if (isStrike == true) { //Console.WriteLine("STRIKE1"); ballNum = 1; valueHandler(MAXFRAME, item, curPlayer, ballNum, playerArray); isStrike = false; isStrike2 = true; skip = true; } isNormal = false; if (frame == MAXFRAME - 1 && skip == false) { if (ballNum == 1) { //Console.WriteLine("BALLNUMFRAME10-----Ball1--------------" + item); valueHandler(frame, item, curPlayer, ballNum, playerArray); if (item != TEN) { tenOne = item; //ballNum = 2; //break; } if (item == TEN) { isStrike = true; valueHandler(frame, item, curPlayer, ballNum, playerArray); //curPlayer++; } skip2 = false; } if (ballNum == 2) { //Console.WriteLine("BALLNUMFRAME10-----Ball2--------------" + item); tenTwo = item; if (frameOk(frame, tenOne, tenTwo, errCnt) == true) { //valueHandler(frame, tenOne, curPlayer, 1, playerArray); valueHandler(frame, item, curPlayer, ballNum, playerArray); if (tenOne + tenTwo == TEN) { isSpare = true; //ballNum = 1; //break; } if (tenOne + tenTwo < TEN) { curPlayer++; isNormal = true; } skip2 = false; } else { skip2 = true; } ballNum = 1; } if (isNormal == false && skip2 == false) { ballNum = 2; } } } skip = false; } } printOut(playerArray, numPlayers, errCnt); Console.WriteLine("------------------------------------"); // Console.WriteLine(count); } catch (Exception e) { Console.WriteLine("error: '{0}'", e); } Console.WriteLine("Press Enter to exit"); Console.ReadLine(); }