C# Making a Football Game Console Application -
C# Making a Football Game Console Application -
i have c# console application write using code have tried couple of things , seem run block. trying create timer on game @ top way me print console , sort of maintain eliminating console.clear code. there way can maintain countdown timer @ top while console.clear active timer not in console window?
additionally, know how convert number format timeclock so: 00:05:00?
using system; using system.timers; namespace timerexample { class programme { static timer timer = new timer(1000); static int = 10; static void main(string[] args) { timer.elapsed+=timer_elapsed; timer.start(); console.read(); } private static void timer_elapsed(object sender, elapsedeventargs e) { i--; console.clear();//here disable , prints out timer in widow // if leave console window wipes out print? console.writeline("================================================="); console.writeline(" first quarter"); console.writeline(""); console.writeline(" time remaining: " + i.tostring()); console.writeline(""); console.writeline("================================================="); if (i == 0) { console.clear(); console.writeline(""); console.writeline("=============================================="); console.writeline(" huddle ! ! ! !"); console.writeline(""); console.writeline(" timeout"); console.writeline("=============================================="); timer.close(); timer.dispose(); } gc.collect(); } } }
okay here extension of code having issues trying maintain game on bottom of window , trying code countdown timer active game starts keeping game selection print user suggestions help
{}....
++++++++++++++++++++++
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.timers; namespace timerexample { class programme { static timer timer = new timer(1000); static int = 300; private void run() { header(); story(); timer.elapsed += timer_elapsed; timer.start(); // console.readline(); bool apprunning = true; bool playerexists = false; //bool drinkexists = false; int userinput = 0; //loop while (apprunning) { console.writeline("\n\n....................\n"); console.writeline("what do?\n"); console.writeline("1.)choose role 2.)show credits 3.)exit application"); console.writeline(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); console.writeline("chose player: "); //take user input , ocnvert string int info type userinput = int16.parse(console.readline()); //switch statement o flip through menu options switch (userinput) { case 1: //intelligence monitor create 1 sandwich per client if (playerexists == false) { console.writeline("does sandwich exist? reply is" + playerexists); console.writeline("lets create snadwich, shall we??\n"); //set default sandwich variable values string quarterback = "quarterback"; string runningback = "runningback"; string receiver = "receiver"; //get type of breadstuff user console.clear(); console.writeline("what type of play like?"); console.writeline("short, run, pass long"); quarterback = console.readline(); //get type of alternative user console.clear(); console.writeline("what type of play like?"); console.writeline("left, right, or staight"); runningback = console.readline(); //get type of jelly user console.clear(); console.writeline("what type of play like?"); console.writeline("long, short, or mid"); receiver = console.readline(); //create instance of sandwichclass player myplayer = new player(quarterback, runningback, receiver); myplayer.aboutplayer(); playerexists = true; } { console.writeline("you've made role choice!"); } break; case 2: showcredits(); break; case 3: apprunning = false; break; default: console.writeline("you have not chosen valid option."); console.writeline("please chose menu...."); break; }//end switch }//end of while }//end of private void run private static void timer_elapsed(object sender, elapsedeventargs e) { i--; // console.clear(); console.writeline("================================================="); console.writeline(" first quarter"); console.writeline(""); console.writeline(" time remaining: " + i.tostring()); console.writeline(""); console.writeline("================================================="); if (i == 0) { console.clear(); console.writeline(""); console.writeline("=============================================="); console.writeline(" time out ! ! ! !"); console.writeline(""); console.writeline(" huddle"); console.writeline("=============================================="); timer.close(); timer.dispose(); } gc.collect(); }//end ofprivatestaticvoidtimer class player { //set default vaulues our sandwich type private string quarterback = ""; private string runningback = ""; private string receiver = ""; //build constructor sandwich class public player(string quarterback, string runningback, string receiver) { this.quarterback = quarterback; this.runningback = runningback; this.receiver = receiver; } public void aboutplayer() { console.writeline("you have made selection!"); console.writeline("as"); console.writeline("press come in coninue..."); console.readline(); } } static void main(string[] args) { console.readkey(); programme myprogram = new program(); myprogram.run(); console.readline(); }//endofmain private void showcredits() { console.clear(); console.writeline("an in-class assigment intro programming"); console.writeline("cesar mojarro"); } private void header() { console.writeline("++++++++++++++++++++++++++++++++++++++++++++++++++++++"); console.writeline("+++++++1967 tackle football game championships v.1.0 ++++++"); console.writeline("++++++++++++++studded diamond cup ++++++++++++++++++++"); console.writeline("++++++++++++++++++++++by iam!+++++++++++++++++++++++++"); console.writeline("++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); console.readkey(); } private void story() { console.writeline("it's year 1967 , in first quarter steve miller running quarterback packs."); console.writeline("young styler running quarterback texan ranchers."); console.writeline("your frontline hung on party lastly nite, ouch! "); console.writeline("the team owner ready collect on pay day studded diamond cup"); console.writeline("don't allow him replace rookie!"); console.writeline(""); console.writeline(""); console.readkey(); console.writeline("the coin toss take place,\nyou nervous , take chance @ tackle unit."); console.writeline("rules simple maintain ball running yards,\nstay head strong , maintain eye on defense!"); console.writeline("don't allow them tackle downwards and\nreturn way goal line allowing apponent score"); console.writeline(""); console.writeline(""); console.writeline(""); console.readkey(); } }//endofprogram }
use console.cursorleft
, console.cursortop
move cursor line time, can overwrite line new value.
private void updatetime(int i) { //move first column. console.cursorleft = 0; //move 4th row console.cursortop = 3; //write text. spaces overwrite old numbers console.write(" time remaining: " + i.tostring() + " "); }
you can more efficient figuring out column i
written , overwrite that.
private string _timeremainingstring = " time remaining: "; private void updatetime(int i) { //move first column have had numbers. console.cursorleft = _timeremainingstring.length; //move 4th row console.cursortop = 3; //overwrite number portion. console.write(i.tostring() + " "); }
additionally, know how convert number format timeclock so: 00:05:00
if i
represents number of seconds left in game easiest solultion convert in timespan
can utilize time span's formatting format want.
private void updatetime(int i) { console.cursorleft = _timeremainingstring.length; console.cursortop = 3; var time = timespan.fromseconds(i); //the `.tostring("c")` on timespan give time in format "00:00:00" //you don't need spaces anymore because time 8 digits long. console.write(time.tostring("c")); }
c#
Comments
Post a Comment