The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
Race Track Simulation
06-03-2018, 03:40 PM (This post was last modified: 06-03-2018 03:41 PM by Eddie W. Shore.)
Post: #1
Race Track Simulation
Link to post: https://edspi31415.blogspot.com/2018/06/...races.html

? (Trumpet Sounds) ?

The program GAME_RACE simulates a race between seven racers:

Apple ѽ (Decimal Unicode: 1149, Hexadecimal Unicode: 47D)
Knight ♞ (Decimal Unicode: 9822, Hexadecimal Unicode: 265E)
Spade ♠ (Decimal Unicode: 9824, Hexadecimal Unicode: 2660)
Club ♣ (Decimal Unicode: 9827, Hexadecimal Unicode: 2663)
Heart ♥ (Decimal Unicode: 9289, Hexadecimal Unicode: 2665)
Diamond ♦ (Decimal Unicode: 9830, Hexadecimal Unicode: 2666)
Spike ✥ (Decimal Unicode: 10021, Hexadecimal Unicode: 2725)

To watch a race in action, all you have to do is to run GAME_RACE. Betting not included.

? HP Prime Program GAME_RACE ?

Code:
EXPORT GAME_RACE()
BEGIN
// 2018-04-15 EWS

// initialize racers
// apple
LOCAL l1:={1149,#FF0000h,300,30};
// knight
LOCAL l2:={9822,#C0C0C0h,300,45};
// spade
LOCAL l3:={9824,#400080h,300,60};
// club
LOCAL l4:={9827,#000080h,300,75};
// heart
LOCAL l5:={9829,#FF0000h,300,90};
// diamond
LOCAL l6:={9830,#F0E090h,300,105};
// spike
LOCAL l7:={10021,#808080h,300,120};

// the race
LOCAL h,k,j,q;

FOR h FROM 1 TO 3 DO
RECT(#00FF00h);
TEXTOUT_P(CHAR(1149)+CHAR(9822)+
CHAR(9824)+CHAR(9827)+CHAR(9829)+
CHAR(9830)+CHAR(10021),125,100,5);
TEXTOUT_P(STRING(3-h+1),125,120,5);
WAIT(1);
END;
TEXTOUT_P(" ",125,120,5,0,25,#00FF00h);
TEXTOUT_P("And they're off!",125,
120,5);
WAIT(0.5);

REPEAT 

// background
RECT();

// background
FILLPOLY_P({(20,0),(20,150),
(330,150),(330,0)},#00FF00h);
FILLPOLY_P({(0,0),(0,150),
(20,150),(20,0)},#E0E0E0h);
LINE_P(0,25,330,25);
// crowd
FOR h FROM 20 TO 300 STEP 10 DO
TEXTOUT_P(CHAR(9823),h,0,5);
END;
TEXTOUT_P(CHAR(9818),140,0,5,#000080h);
TEXTOUT_P(CHAR(9819),150,0,5,#FF0000h);
// racers
FOR h FROM 1 TO 7 DO
TEXTOUT_P(CHAR(1149),l1(3),l1(4),5,l1(2));
TEXTOUT_P(CHAR(9822),l2(3),l2(4),5,l2(2));
TEXTOUT_P(CHAR(9824),l3(3),l3(4),5,l3(2));
TEXTOUT_P(CHAR(9827),l4(3),l4(4),5,l4(2));
TEXTOUT_P(CHAR(9829),l5(3),l5(4),5,l5(2));
TEXTOUT_P(CHAR(9830),l6(3),l6(4),5,l6(2));
TEXTOUT_P(CHAR(10021),l7(3),l7(4),5,l7(2));
END;

WAIT(0.5);
// move the racers
l1(3):=l1(3)-RANDINT(1,3)*5;
l2(3):=l2(3)-RANDINT(1,3)*5;
l3(3):=l3(3)-RANDINT(1,3)*5;
l4(3):=l4(3)-RANDINT(1,3)*5;
l5(3):=l5(3)-RANDINT(1,3)*5;
l6(3):=l6(3)-RANDINT(1,3)*5;
l7(3):=l7(3)-RANDINT(1,3)*5;


q:={l1(3),l2(3),l3(3),
l4(3),l5(3),l6(3),l7(3)};
q:=q<5;
q:=ΣLIST(q);
UNTIL q>0;

TEXTOUT_P("The race is over!",
0,160,5,#008000h);

WAIT(0);
END;

[img][Image: 28664934658_c6a9442818_c.jpg]sample symbol race by Edward Shore, on Flickr[/img]
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Race Track Simulation - Eddie W. Shore - 06-03-2018 03:40 PM



User(s) browsing this thread: 1 Guest(s)