This code tracks life in games like Yu-Gi-Oh and Magic. It can handle 2-4 players, and the menu will adapt to whatever the amount of players needed is. The Menu( command can be replaced with anything else, as long as it is still user friendly. I am going for the lowest size, because speed is not an issue.


Code:

ClrHome
Input "Starting Life: ",X
Repeat 2≤P and P≤4
   Input "Players: ",P
End
{X,X,X(P≥3),X(P=4)}→L₁
Lbl M
ClrHome
If P=2
Menu("Life Tracker","P1: "+eval(L₁(1)),1,"P2: "+eval(L₁(2)),2,"Quit",Q
If P=3
Menu("Life Tracker","P1: "+eval(L₁(1)),1,"P2: "+eval(L₁(2)),2,"P3: "+eval(L₁(3)),3,"Quit",Q
If P=4
Menu("Lifer Tracker","P1: "+eval(L₁(1)),1,"P2: "+eval(L₁(2)),2,"P3: "+eval(L₁(3)),3,"P4: "+eval(L₁(4)),4,"Quit",Q
Lbl 1
Input eval(L₁(1)),Str1
expr(toString(L₁(1))+Str1)→L₁(1)
Goto M
Lbl 2
Input eval(L₁(2)),Str1
expr(toString(L₁(2))+Str1)→L₁(2)
Goto M
Lbl 3
Input eval(L₁(3)),Str1
expr(toString(L₁(3))+Str1)→L₁(3)
Goto M
Lbl 4
Input eval(L₁(4)),Str1
expr(toString(L₁(4))+Str1)→L₁(4)
Goto M
Lbl Q
Stop
This should work, but I haven't tested it. I tested it now. I just optimized what I saw. I changed all the menus to one custom menu and replaced all your repetitive values/code with variables. This is in sourcecoder format btw I hope you don't mind

Code:
ClrHome
Input "Starting Life: ",X
Repeat sum(P={2,3,4
Input "Players: ",P
End
{X,X,X(P>=3),X(P=4->L1
Lbl M
ClrHome
Output(1,1,"Life Tracker
For(I,2,P+1
Output(I,2,"P"+toString(I-1)+": "+eval(L1(I-1
End
Output(P+2,2,"Quit
2->A
Repeat sum(K={45,105
Output(A,1,">
Repeat Ans:getKey:End
Ans->K
Output(A,1,"
A+(Ans=34)(A<P+2)-(Ans=25)(A>2->A
End
ClrHome
If K=45 or A=P+2:Return
A-1
Input eval(L1(Ans)),Str1
expr(toString(L1(Ans))+Str1->L1(Ans
Goto M
After some minor corrections, it works great! thanks!
KosmicCyclone wrote:
After some minor corrections, it works great! thanks!

Oops, yeah it looks like I made a mistake or two. I just fixed the code and edited my last post for you, but you probably came up with the same thing too. You're welcome btw Smile
I made the scores be displayed in color, and added a cool display that uses the Center of Mass equation to kind of represent who is strongest. This could probably use some more optimizations now.

Code:

{11,15,14,18,10,17,13}->|LC
Degree
Menu("Life Tracker","New Game",N,"Load Game",L
Lbl N
Repeat sum(P={2,3,4,5,6,7
   Input "Players: ",P
End
P->dim(|LLIFE
Input "Starting Life: ",X
Fill(X,|LLIFE
Lbl L
dim(|LLIFE)->P:P->dim(|LX:P->dim(|LY
StoreGDB 1
AxesOff:GridOff
0->Xmin:32->Xmax
0->Ymin:20->Ymax
BackgroundOn DarkGray
Lbl M
ClrHome:ClrDraw
TextColor(Black
Text(0,0,"Life Tracker
Text(12(P+1),10,"Quit
For(Q,1,P
   TextColor(|LC(Q
   Text(12Q,10,"P",toString(Q),": ",eval((|LLIFE(Q
End
0->L
For(theta,0,359,360/P
   L+1->L
   21+P>Rx(8,theta->|LX(L
   10+P>Ry(8,theta->|LY(L
End
(Sigma(|LX(L)|LLIFE(L),L,1,dim(|LX)))n/d(sum(|LLIFE->A
(Sigma(|LY(L)|LLIFE(L),L,1,dim(|LY)))n/d(sum(|LLIFE->B
For(L,1,P
   Pt-On(|LX(L),|LY(L),|LC(L
   Pt-On(|LX(L),|LY(L),2,|LC(L
   Line(|LX(L),|LY(L),A,B,|LC(L),1
End
Pt-On(A,B,|LC(1+sum(not(cumSum(|LLIFE=max(|LLIFE
Pt-On(A,B,2,White
1->A
Repeat K=105
   TextColor(Black
   Text(12A,0,">
Repeat Ans:getKey:End
   Ans->K
   Text(12A,0,"     
   A+(Ans=34)(A<P+1)-(Ans=25)(A>1->A
End
If A=P+1:Goto Q
ClrHome
A
Input eval(|LLIFE(Ans)),Str1
max(0,expr(toString(|LLIFE(Ans))+Str1->|LLIFE(Ans
Goto M
Lbl Q
RecallGDB 1:BackgroundOff
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement