REM'$Include:'YahtzeeTypes.BI' TYPE Upper_Card
'max score 125('base' shown),140('lite') Bonus
AS _BYTE ' 35 if all values added >= 63 Total
AS _UNSIGNED _BYTE 'base rules allow for only 125 max, but lite rules allow for 140
ThreeOfKind
AS _BYTE 'total all dice, max 28(3x6+2x5 not using full house/30 with yahtzee bonus) FourOfKind
AS _BYTE ' total all dice, max 29(4x6+1x5/30 with yahtzee bonus) Chance
AS _BYTE ' 29 max(30 if not using yahtzee\'base' rules or yahtzee+bonus taken) Yahtzee
AS _BYTE ' 50 points(+100 per bonus yahtzee) Bonus
AS _BYTE ' only 1 allowed in 'base' rules but multiple in 'lite' rules Total
AS INTEGER 'Max:'base' rules-332: 'lite' rules- 650+185 and + 600 for upper_card(1435)'Absolute MAXIMUM high score is 1575 using 'lite' rules which allow for up to 13 yahtzees
'first yahtzee being 50 points then 12 extra yahtzee at 100 points placing max numbers in
'all 12 non yahtzee boxes, this would be a 'GOD'game where player rolled nothing but 5 of
'a kind including 1 for each of the upper card scores and nothing but 6s for lower.
'Odds are astronomical, but not technically impossible!
Current_Roll
AS _BYTE 'each player gets up to 3 rolls for max score Upper_Filled
AS _BYTE 'flag if all upper stats are filled in Lower_Filled
AS _BYTE 'flag if all lower stats are filled in Rule_Set
AS _BYTE 'using base rules or lite rules GameOver
AS _BYTE 'when all 13 flags are set game is over FirstGame
AS _BYTE 'if there is no score file then this is first game MFIVerB
AS _BYTE 'does user have the B version MFI file?(extra BGM) MFIVerC
AS _BYTE 'does user have Full BGM list MFI file? BGMVol
AS _BYTE 'volume level of Background music SFXVol
AS _BYTE 'volume level of Sound effects Current_BGM
AS _BYTE 'which type of BGM is playing Loaded
AS _BYTE 'are online high scores already loaded?
CONST STANDARD
= 1, LITE
= 2, LOWER
= -1, UPPER
= -2 CONST ACES
= 1, DUCES
= 2, TRIPS
= 3, QUADS
= 4, QUINC
= 5, SEXTE
= 6 CONST THREEOFKIND
= 7, CHANCE
= 13, FULLHOUSE
= 9, FOUROFKIND
= 8, YAHTZEE
= 12, SMSTRAIGHT
= 10, LGSTRAIGHT
= 11
'Graphic stuff setup---------------------------------------
Layer
(1) = _NEWIMAGE(640, 480, 32) 'Mixing layerLayer
(4) = _NEWIMAGE(640, 480, 32) 'click boxesLayer
(10) = _NEWIMAGE(640, 480, 32) 'Temp LayerLayer
(11) = _NEWIMAGE(640, 480, 32) 'green mat layerLayer
(13) = _NEWIMAGE(297, 608, 32) 'final score temp layer'----------------Special Resource file check--------------------------
DATA 9,80,104,97,125,115,108,108,86,56,8,89,125,97,107,99,87,97,124 G.MFIVerC = TRUE
G.Current_BGM = 2
MFI_Loader "YahtzeeV1_2c.MFI" 'load graphics and fonts (and sounds) B version
G.MFIVerB = TRUE
G.Current_BGM = 2
MFI_Loader "YahtzeeV1_2b.MFI" 'load graphics and fonts (and sounds) B version
G.MFIVerB = FALSE
G.MFIVerC = FALSE
MFI_Loader "YahtzeeV1_2.MFI" 'load graphics and fonts (and sounds)
'-----------------------------------------------------------------------
'-------------Final GFX setup-----------------------------
_TITLE "Yahtzee64 by Unikorn Produckions @2019 Ver 1.0b Build 011" Draw_GameMat Layer(11)
_SOURCE Layer
(4) 'source for mouse click detection '----------------------------------------------------------
'---------Inital Sound level setup-----------------------
G.BGMVol = 10
G.SFXVol = 10
'----------------------------------------------------------
'---------Some inital setup values------------
Init_Scores 0
G.Rule_Set = STANDARD
Die_Shaker 'pre-shake dice
'---------------------------------------------
'--------intro screens-------
Intro
'-------------------------------------------------
Load_Local_HiScore
Menu
Create_ClickLayer 3
ClearLayer Layer(1)
Pick_Nick 0
Create_ClickLayer 0
Init_Scores 0
Main_Game_Loop
Create_ClickLayer 3
End_Score 0
Save_Local_Score
IF G.Connected
THEN Save_Online_Score: Sort_Online_Scores
G.GameOver = FALSE
G.SetValues = 0
CASE 3 'local high scores ClearLayer Layer(1)
ClearLayer Layer(10)
Load_Local_HiScore
Local_Scores
CASE 4 'online high scores ClearLayer Layer(1)
ClearLayer Layer(10)
Load_Online_HiScore
Sort_Online_Scores
G.Loaded = TRUE
Online_Scores
Sound_Controls
ExitFlag%% = TRUE
Create_ClickLayer 4
_PRINTSTRING (85, 160), "A B C D E F G H I J K L M", Layer
(1) _PRINTSTRING (85, 210), "N O P Q R S T U V W X Y Z", Layer
(1)
i%% = 0
j%%
= (Selection%%
MOD 14) - 1 i%% = 1
j%%
= (Selection%%
MOD 14) i%% = 2
j%%
= (Selection%%
MOD 13) - 1 IF Selection%%
<> 0 THEN 'hi-lite current letter mouse is over LINE (85 + 35 * j%%
+ j%%
, 158 + 50 * i%%
)-STEP(19, 25), _RGB32(224, 204, 16), B
'hi-lite current Character
_PUTIMAGE , Layer
(1), Layer
(0) 'move image to screen
Nick$
= Nick$
+ CHR$(64 + Selection%%
) Nick$
= Nick$
+ CHR$(48 + (Selection%%
- 27)) Nick$ = Nick$ + " "
Nick$ = Nick$ + "."
Exitflag%% = TRUE
Button_Down_Lock
ClearLayer Layer(1)
tim%% = tim%% + 1
IF tim%%
= 15 AND lit%%
= FALSE
THEN lit%%
= TRUE: tim%%
= 0 IF tim%%
= 15 AND lit%%
THEN lit%%
= FALSE: tim%%
= 0
Nick(Who~%%) = Nick$
Place_ShakerCup 500, 20
Display_Dice 50, 50
_PRINTSTRING (30, 409), "Click on Dice to keep then click shaker cup,", Layer
(1) _PRINTSTRING (30, 426), "to reroll remaining dice, or click on score ", Layer
(1) _PRINTSTRING (30, 409), "Out of Rolls, select score card to save ", Layer
(1) Display_UpperCard 400, 140, .33, 0
Display_LowerCard 400, 295, .33, 0
Top~%%
= _SHL(G.SetValues
, 2) Bot~%%
= _SHR(G.SetValues
, 6) LOCATE 1, 1:
PRINT Selection%%; G.Current_Roll; Die_Check; G.Upper_Filled; Top~%%; Bot~%%; G.SetValues
Die_Shaker
Shaking%% = TRUE
CASE 2, 3 'view score card View_Score_Card Selection%%, 0
IF DieArray
(Selection%%
- 3).Locked
THEN DieArray
(Selection%%
- 3).Locked
= FALSE
ELSE DieArray
(Selection%%
- 3).Locked
= TRUE
'player gets 3 rolls, count roll when mouse button released
Soundplaying%% = 1
Soundplaying%% = 2
Soundplaying%% = 3
Soundplaying%% = 4
Soundplaying%% = 0
SUB View_Score_Card
(UL%%
, Who~%%
) Result%% = Show_Upper_Card(Who~%%)
Result%% = Show_Lower_Card(Who~%%)
IF Result%%
= -1 THEN ExitFlag%%
= TRUE
IF Result%%
= -2 THEN G.Current_Roll
= 0: ExitFlag%%
= TRUE
UL%% = 0
Top~%%
= _SHL(G.SetValues
, 2) Bot~%%
= _SHR(G.SetValues
, 6) IF Top~%%
= 252 THEN G.Upper_Filled
= TRUE
IF Bot~%%
= 254 THEN G.Lower_Filled
= TRUE
IF Top~%%
= 252 AND Bot~%%
= 254 THEN G.GameOver
= TRUE
Button_Down_Lock
GET #1, , c~%%
'retrieve number of files FOffset&(I~%%) = FOffset&(I~%%) + 1
READ T%%: T%%
= T%%
XOR C%%: T$
(d%%
) = T$
(d%%
) + CHR$(T%%
) 'load the files where they go here----------
Layer(2) = LoadGFX(FOffset(1), Size(1)) '_LOADIMAGE("Upper_Card.png", 32) 'upper score card
Layer(3) = LoadGFX(FOffset(2), Size(2)) '_LOADIMAGE("Lower_Card.png", 32) 'Lower score card
Layer(5) = LoadGFX(FOffset(3), Size(3)) '_LOADIMAGE("UPsplash6x4.BMP", 32) 'flash Screen
Layer(6) = LoadGFX(FOffset(4), Size(4)) '_LOADIMAGE("Yahtzeeflash.BMP", 32)
Layer(7) = LoadGFX(FOffset(5), Size(5)) '_LOADIMAGE("Yahtzee-logo.BMP", 32)
Layer(8) = LoadGFX(FOffset(6), Size(6)) '_LOADIMAGE("SizedDiceRedDot.BMP", 32)
Layer(9) = LoadGFX(FOffset(7), Size(7)) '_LOADIMAGE("ShakerCup.BMP", 32)
FFX& = LoadFFX(FOffset(8), Size(8), 24) '_LOADFONT("OBGB.ttf", 24, "MONOSPACE")
FFX2& = LoadFFX(FOffset(8), Size(8), 24) '_LOADFONT("OBGB.ttf", 24, "MONOSPACE")
Layer(12) = LoadGFX(FOffset(15), Size(15)) '_LOADIMAGE("ShakerCup.BMP", 32)
BGM(1) = LoadSFX(FOffset(16), Size(16))
SFX(1) = LoadSFX(FOffset(9), Size(9)) 'die shake 4 or 5 dice
SFX(2) = LoadSFX(FOffset(10), Size(10)) 'die shake 3 dice
SFX(3) = LoadSFX(FOffset(11), Size(11)) 'die shake 2 dice
SFX(4) = LoadSFX(FOffset(12), Size(12)) 'single die shake
SFX(5) = LoadSFX(FOffset(13), Size(13)) 'rolling dice
IF G.MFIVerB
OR G.MFIVerC
THEN BGM
(2) = LoadSFX
(FOffset
(17), Size
(17)) IF G.MFIVerC
THEN BGM
(3) = LoadSFX
(FOffset
(18), Size
(18)) IF G.MFIVerC
THEN BGM
(4) = LoadSFX
(FOffset
(19), Size
(19)) IF G.MFIVerC
THEN BGM
(5) = LoadSFX
(FOffset
(20), Size
(20))
'-------------------------------------------
REM'$include:'Core_Funcitons.BAS' REM'$include:'GFX_Functions.BAS' REM'$include:'MFI_Functions.BAS' REM'$include:'ServerCode.BAS'
Result%% = 0
Result%% = R%%
Check_ClickBox = Result%%
Local(i%%).Who = ""
Local(i%%).Score = 0
Local(i%%).Rules = 0
Result%% = 0 'initalize value
IF DieArray
(i%%
).Value
= DV%%
THEN Result%%
= Result%%
+ DV%%
Count_Dice = Result%%
'Steves Dice Status checking routine
Count(DieArray(i%%).Value) = Count(DieArray(i%%).Value) + 1
Result%% = Result%% + Count(i%%)
IF Count
(i%%
) > 3 THEN Result%%
= Result%%
+ 2
'check for long straight------
IF Count
(i%%
) = 1 THEN LS%%
= LS%%
+ 1 IF Count
(i%%
+ 1) = 1 THEN LS2%%
= LS2%%
+ 1 '-----------------------------
'check for short straight------
IF Count
(i%%
+ x%%
) = 1 OR Count
(i%%
+ x%%
) = 2 THEN SS%%
= SS%%
+ 1 '------------------------------
IF LS%%
= 5 OR LS2%%
= 5 THEN Result%%
= 8 'comes after short straight cause a long trumps a short.
' IF Result = 3 THEN PRINT "Three of Kind"
' IF Result = 5 THEN PRINT "Full House"
' IF Result = 6 THEN PRINT "Four of Kind"
' IF Result = 7 THEN PRINT "Yahtzee"
' IF Result = 8 THEN PRINT "Large Straight"
' IF Result = 9 THEN PRINT "Short Straight"
Die_Check = Result%%
Result%% = 5
FOR i%%
= 1 TO 5 'check if any dice are locked, then they are not in the shaker cup. IF DieArray
(i%%
).Locked
THEN Result%%
= Result%%
- 1 Die_In_Cup = Result%%
Die_Roll
= INT(RND * 6) + 1 'very, very simple
IF G.Current_Roll
= 0 THEN DieArray
(i%%
).Locked
= FALSE
IF DieArray
(i%%
).Locked
= FALSE
THEN DieArray
(i%%
).Value
= Die_Roll
'set all values at -1 to show not filled in, as you can score 0
PCU(who~%%).Aces = -1
PCU(who~%%).Duces = -1
PCU(who~%%).Trips = -1
PCU(who~%%).Quads = -1
PCU(who~%%).Quinc = -1
PCU(who~%%).Sexte = -1
PCU(who~%%).Total = -1
PCL(who~%%).ThreeOfKind = -1
PCL(who~%%).FourOfKind = -1
PCL(who~%%).FullHouse = -1
PCL(who~%%).SmStraight = -1
PCL(who~%%).LgStraight = -1
PCL(who~%%).Chance = -1
PCL(who~%%).Yahtzee = -1
PCL(who~%%).Bonus = 0 'save for bonus Yahtzees which starts at 0
PCL(who~%%).Total = -1
'load high scores
G.FirstGame = TRUE
'use defult names
Local(1).Who = "COBALT": Local(1).Score = 390: Local(1).Rules = 0
Local(2).Who = "SMcNeill": Local(2).Score = 300: Local(2).Rules = 0
Local(3).Who = "Fellippe": Local(3).Score = 290: Local(3).Rules = 0
Local(4).Who = "Pete": Local(4).Score = 280: Local(4).Rules = 0
Local(5).Who = "STaXaTIC": Local(5).Score = 270: Local(5).Rules = 0
Local(6).Who = "Luke": Local(6).Score = 260: Local(6).Rules = 0
Local(7).Who = "[banned user]": Local(7).Score = 250: Local(7).Rules = 0
Local(8).Who = "Keybone": Local(8).Score = 240: Local(8).Rules = 0
Local(9).Who = "Catherine": Local(9).Score = 230: Local(9).Rules = 0
Local(10).Who = "Clippy": Local(10).Score = 220: Local(10).Rules = 0
Local(11).Who = "Narika": Local(11).Score = 210: Local(11).Rules = 0
Local(12).Who = "Galleon": Local(12).Score = 20: Local(12).Rules = 0
count = count + 1: C2 = T$(1)
Client
= _OPENCLIENT("TCP/IP:7993:172.93.60.23") 'attempt to join as client D1 = T$(0)
OK$ = Verify$
Detail$ = "[ERROR]Host not responding."
G.Connected = TRUE
PRINT "logging in to scores" N$ = D1: P$ = C2
Send Client, "[LOG IN]" + N$ + "," + P$ 'Register a new account
OK$ = Verify$
Detail$ = OK$
Send Client, "[GAME SET]Yahtzee" 'Let the server know what game we're playing.
OK$ = Verify$
ExitFlag%% = TRUE
DisplayError OK$
PRINT "Requesting score file"
Send Client, "[GAME GET]TestScores.txt" 'the command to get the data back from the server.
OK$ = Verify$
'All is good
DataWeGot$
= MID$(OK$
, 5) 'the data is attached after the [OK]. Like this, we got it. DisplayError OK$ 'pop up an error message telling us what went wrong.
END 'However we want to handle an error when trying to put data to the server.
Online(1).Who = "Not Connected"
IF PCL
(Who~%%
).ThreeOfKind
>= 0 THEN Result%
= PCL
(Who~%%
).ThreeOfKind
IF PCL
(Who~%%
).FourOfKind
>= 0 THEN Result%
= Result%
+ PCL
(Who~%%
).FourOfKind
IF PCL
(Who~%%
).FullHouse
>= 0 THEN Result%
= Result%
+ PCL
(Who~%%
).FullHouse
IF PCL
(Who~%%
).SmStraight
>= 0 THEN Result%
= Result%
+ PCL
(Who~%%
).SmStraight
IF PCL
(Who~%%
).LgStraight
>= 0 THEN Result%
= Result%
+ PCL
(Who~%%
).LgStraight
IF PCL
(Who~%%
).Chance
>= 0 THEN Result%
= Result%
+ PCL
(Who~%%
).Chance
IF PCL
(Who~%%
).Yahtzee
>= 0 THEN Result%
= Result%
+ PCL
(Who~%%
).Yahtzee
'go ahead and calculate grand total for lower as we go.-------------
PCL(Who~%%).Total = Result%
FOR i%%
= 1 TO PCL
(Who~%%
).Bonus
PCL(Who~%%).Total = PCL(Who~%%).Total + 100
Result% = Result% + 100
'-------------------------------------------------------------------
LowerTotal = Result%
SUB Reset_SelectedScore
(Selected%%
, Who~%%
, Rules%%
) PCU(Who~%%).Aces = -1
PCU(Who~%%).Duces = -1
PCU(Who~%%).Trips = -1
PCU(Who~%%).Quads = -1
PCU(Who~%%).Quinc = -1
PCU(Who~%%).Sexte = -1
PCL(Who~%%).ThreeOfKind = -1
PCL(Who~%%).FourOfKind = -1
PCL(Who~%%).FullHouse = -1
PCL(Who~%%).SmStraight = -1
PCL(Who~%%).LgStraight = -1
PCL(Who~%%).Yahtzee = -1
PCL(Who~%%).Chance = -1
i%% = i%% + 1
IF Local
(i%%
).Score
< Score%
THEN Found%%
= TRUE: Result%%
= i%%
Return_Local_Rank = Result%%
i~%% = i~%% + 1
IF Online
(i~%%
).Score
< Score%
THEN Found~%%
= TRUE: Result~%%
= i~%%
Return_Online_Rank = Result~%%
FUNCTION Set_SelectedScore%%
(Selected%%
, Who~%%
, Rules%%
) Result%% = FALSE
PCU(Who~%%).Aces = Count_Dice%%(ACES)
IF Die_Check
= 7 AND PCL
(Who~%%
).Yahtzee
> 0 THEN 'the bonus Yahtzee check IF G.Rule_Set
= STANDARD
AND PCL
(Who~%%
).Bonus
= 0 THEN PCL(Who~%%).Bonus = 1
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
IF PCU
(Who~%%
).Duces
= -1 THEN PCU(Who~%%).Duces = Count_Dice%%(DUCES)
IF Die_Check
= 7 AND PCL
(Who~%%
).Yahtzee
> 0 THEN 'the bonus Yahtzee check IF G.Rule_Set
= STANDARD
AND PCL
(Who~%%
).Bonus
= 0 THEN PCL(Who~%%).Bonus = 1
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
IF PCU
(Who~%%
).Trips
= -1 THEN PCU(Who~%%).Trips = Count_Dice%%(TRIPS)
IF Die_Check
= 7 AND PCL
(Who~%%
).Yahtzee
> 0 THEN 'the bonus Yahtzee check IF G.Rule_Set
= STANDARD
AND PCL
(Who~%%
).Bonus
= 0 THEN PCL(Who~%%).Bonus = 1
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
IF PCU
(Who~%%
).Quads
= -1 THEN PCU(Who~%%).Quads = Count_Dice%%(QUADS)
IF Die_Check
= 7 AND PCL
(Who~%%
).Yahtzee
> 0 THEN 'the bonus Yahtzee check IF G.Rule_Set
= STANDARD
AND PCL
(Who~%%
).Bonus
= 0 THEN PCL(Who~%%).Bonus = 1
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
IF PCU
(Who~%%
).Quinc
= -1 THEN PCU(Who~%%).Quinc = Count_Dice%%(QUINC)
IF Die_Check
= 7 AND PCL
(Who~%%
).Yahtzee
> 0 THEN 'the bonus Yahtzee check IF G.Rule_Set
= STANDARD
AND PCL
(Who~%%
).Bonus
= 0 THEN PCL(Who~%%).Bonus = 1
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
IF PCU
(Who~%%
).Sexte
= -1 THEN PCU(Who~%%).Sexte = Count_Dice%%(SEXTE)
IF Die_Check
= 7 AND PCL
(Who~%%
).Yahtzee
> 0 THEN 'the bonus Yahtzee check IF G.Rule_Set
= STANDARD
AND PCL
(Who~%%
).Bonus
= 0 THEN PCL(Who~%%).Bonus = 1
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
'condition is met 4 ways, 3 of kind, 4 of kind, full house and yahtzee
IF PCL
(Who~%%
).ThreeOfKind
= -1 THEN Result%% = TRUE
PCL(Who~%%).ThreeOfKind = 0
PCL(Who~%%).ThreeOfKind = PCL(Who~%%).ThreeOfKind + DieArray(i%%).Value
IF G.Rule_Set
= STANDARD
AND PCL
(Who~%%
).Bonus
= 0 THEN Result%% = TRUE
PCL(Who~%%).ThreeOfKind = 0
PCL(Who~%%).ThreeOfKind = PCL(Who~%%).ThreeOfKind + DieArray(i%%).Value
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
PCL(Who~%%).ThreeOfKind = 0
PCL(Who~%%).ThreeOfKind = PCL(Who~%%).ThreeOfKind + DieArray(i%%).Value
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
PCL(Who~%%).ThreeOfKind = 0
'condition is met with 4 of a kind or yahtzee
IF PCL
(Who~%%
).FourOfKind
= -1 THEN Result%% = TRUE
PCL(Who~%%).FourOfKind = 0
PCL(Who~%%).FourOfKind = PCL(Who~%%).FourOfKind + DieArray(i%%).Value
IF G.Rule_Set
= STANDARD
AND PCL
(Who~%%
).Bonus
= 0 THEN Result%% = TRUE
PCL(Who~%%).FourOfKind = 0
PCL(Who~%%).FourOfKind = PCL(Who~%%).FourOfKind + DieArray(i%%).Value
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
PCL(Who~%%).FourOfKind = 0
PCL(Who~%%).FourOfKind = PCL(Who~%%).FourOfKind + DieArray(i%%).Value
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
PCL(Who~%%).FourOfKind = 0
IF PCL
(Who~%%
).FullHouse
= -1 THEN Result%% = TRUE
PCL(Who~%%).FullHouse = 25
IF G.Rule_Set
= STANDARD
AND PCL
(Who~%%
).Bonus
= 0 THEN Result%% = TRUE
PCL(Who~%%).FullHouse = 25
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
PCL(Who~%%).FullHouse = 25
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
PCL(Who~%%).FullHouse = 0
IF PCL
(Who~%%
).SmStraight
= -1 THEN IF Die_Check
= 9 OR Die_Check
= 8 THEN 'check for long as well, if you have a long straight automatically have a short. Result%% = TRUE
PCL(Who~%%).SmStraight = 30
IF G.Rule_Set
= STANDARD
AND PCL
(Who~%%
).Bonus
= 0 THEN Result%% = TRUE
PCL(Who~%%).SmStraight = 30
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
PCL(Who~%%).SmStraight = 30
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
PCL(Who~%%).SmStraight = 0
IF PCL
(Who~%%
).LgStraight
THEN Result%% = TRUE
PCL(Who~%%).LgStraight = 40
IF G.Rule_Set
= STANDARD
AND PCL
(Who~%%
).Bonus
= 0 THEN Result%% = TRUE
PCL(Who~%%).LgStraight = 40
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
PCL(Who~%%).LgStraight = 40
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Result%% = TRUE
PCL(Who~%%).LgStraight = 0
IF PCL
(Who~%%
).Yahtzee
= -1 THEN Result%% = TRUE
PCL(Who~%%).Yahtzee = 50
Result%% = TRUE
PCL(Who~%%).Yahtzee = 0
IF PCL
(Who~%%
).Chance
= -1 THEN Result%% = TRUE
PCL(Who~%%).Chance = 0
PCL(Who~%%).Chance = PCL(Who~%%).Chance + Count_Dice%%(i%%)
IF Die_Check
= 7 AND PCL
(Who~%%
).Yahtzee
> 0 THEN IF G.Rule_Set
= STANDARD
AND PCL
(Who~%%
).Bonus
= 0 THEN PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
PCL(Who~%%).Bonus = PCL(Who~%%).Bonus + 1
Set_SelectedScore = Result%%
IF PCU
(Who~%%
).Aces
>= 0 THEN Result~%%
= PCU
(Who~%%
).Aces
IF PCU
(Who~%%
).Duces
>= 0 THEN Result~%%
= Result~%%
+ PCU
(Who~%%
).Duces
IF PCU
(Who~%%
).Trips
>= 0 THEN Result~%%
= Result~%%
+ PCU
(Who~%%
).Trips
IF PCU
(Who~%%
).Quads
>= 0 THEN Result~%%
= Result~%%
+ PCU
(Who~%%
).Quads
IF PCU
(Who~%%
).Quinc
>= 0 THEN Result~%%
= Result~%%
+ PCU
(Who~%%
).Quinc
IF PCU
(Who~%%
).Sexte
>= 0 THEN Result~%%
= Result~%%
+ PCU
(Who~%%
).Sexte
'go ahead and calculate grand total for upper as we go.-------------
PCU(Who~%%).Total = Result~%%
IF Result~%%
>= 63 THEN PCU
(Who~%%
).Total
= PCU
(Who~%%
).Total
+ 35 '-------------------------------------------------------------------
UpperTotal = Result~%%
Create_ClickLayer 1
Display_UpperCard 0, 0, 1, Who~%%
IF Set_SelectedScore
(ACES
, Who~%%
, G.Rule_Set
) THEN Clicked%%
= 1: G.SetValues
= _SETBIT(G.SetValues
, 0) IF Set_SelectedScore
(DUCES
, Who~%%
, G.Rule_Set
) THEN Clicked%%
= 2: G.SetValues
= _SETBIT(G.SetValues
, 1) IF Set_SelectedScore
(TRIPS
, Who~%%
, G.Rule_Set
) THEN Clicked%%
= 3: G.SetValues
= _SETBIT(G.SetValues
, 2) IF Set_SelectedScore
(QUADS
, Who~%%
, G.Rule_Set
) THEN Clicked%%
= 4: G.SetValues
= _SETBIT(G.SetValues
, 3) IF Set_SelectedScore
(QUINC
, Who~%%
, G.Rule_Set
) THEN Clicked%%
= 5: G.SetValues
= _SETBIT(G.SetValues
, 4) IF Set_SelectedScore
(SEXTE
, Who~%%
, G.Rule_Set
) THEN Clicked%%
= 6: G.SetValues
= _SETBIT(G.SetValues
, 5) 'if player clicks accept make sure they have selected a scoring location
IF Selection%%
= 7 AND Clicked%%
> 0 THEN Result%%
= -2: ExitFlag%%
= TRUE
IF Selection%%
= 8 THEN 'resets selection Reset_SelectedScore Clicked%%, Who~%%, G.Rule_Set
G.SetValues
= _RESETBIT(G.SetValues
, Clicked%%
- 1) Clicked%% = FALSE
Result%% = TRUE: ExitFlag%% = TRUE 'hits cancel
Reset_SelectedScore Clicked%%, Who~%%, G.Rule_Set
G.SetValues
= _RESETBIT(G.SetValues
, Clicked%%
- 1) Clicked%% = FALSE
Result%% = 1: ExitFlag%% = TRUE 'switch to lower card
Reset_SelectedScore Clicked%%, Who~%%, G.Rule_Set
G.SetValues
= _RESETBIT(G.SetValues
, Clicked%%
- 1) Clicked%% = FALSE
Button_Down_Lock 'hold program while button is down to help prevent 'skipping'
Create_ClickLayer 0
Show_Upper_Card = Result%%
ClearLayer Layer(1)
Create_ClickLayer 2
Display_LowerCard 0, 0, 1, Who~%%
IF Set_SelectedScore
(THREEOFKIND
, Who~%%
, G.Rule_Set
) THEN Clicked%%
= 7: G.SetValues
= _SETBIT(G.SetValues
, 7) IF Set_SelectedScore
(FOUROFKIND
, Who~%%
, G.Rule_Set
) THEN Clicked%%
= 8: G.SetValues
= _SETBIT(G.SetValues
, 8) IF Set_SelectedScore
(FULLHOUSE
, Who~%%
, G.Rule_Set
) THEN Clicked%%
= 9: G.SetValues
= _SETBIT(G.SetValues
, 9) IF Set_SelectedScore
(SMSTRAIGHT
, Who~%%
, G.Rule_Set
) THEN Clicked%%
= 10: G.SetValues
= _SETBIT(G.SetValues
, 10) IF Set_SelectedScore
(LGSTRAIGHT
, Who~%%
, G.Rule_Set
) THEN Clicked%%
= 11: G.SetValues
= _SETBIT(G.SetValues
, 11) IF Set_SelectedScore
(YAHTZEE
, Who~%%
, G.Rule_Set
) THEN Clicked%%
= 12: G.SetValues
= _SETBIT(G.SetValues
, 12) IF Set_SelectedScore
(CHANCE
, Who~%%
, G.Rule_Set
) THEN Clicked%%
= 13: G.SetValues
= _SETBIT(G.SetValues
, 13) 'if player clicks accept make sure they have selected a scoring location
IF Selection%%
= 8 AND Clicked%%
> 0 THEN Result%%
= -2: ExitFlag%%
= TRUE
Reset_SelectedScore Clicked%%, Who~%%, G.Rule_Set
G.SetValues
= _RESETBIT(G.SetValues
, Clicked%%
) Clicked%% = 0
ExitFlag%% = TRUE: Result%% = TRUE 'cancel
Reset_SelectedScore Clicked%%, Who~%%, G.Rule_Set
G.SetValues
= _RESETBIT(G.SetValues
, Clicked%%
) Result%% = 2: ExitFlag%% = TRUE 'switch to upper card
Reset_SelectedScore Clicked%%, Who~%%, G.Rule_Set
G.SetValues
= _RESETBIT(G.SetValues
, Clicked%%
) Clicked%% = FALSE
Button_Down_Lock 'hold program while button is down to help prevent 'skipping'
Create_ClickLayer 0
Show_Lower_Card = Result%%
ClearLayer Layer(1)
GrandTotal% = PCU(Who~%%).Total + PCL(who%%).Total
Clear_Scores
Local(1).Who = Nick(0)
Local(1).Score = GrandTotal%
Local(1).Rules = G.Rule_Set
G.FirstGame = 0
Start%% = Return_Local_Rank(GrandTotal%) 'where is player being placed in score list
Local(i%% + 1) = Local(i%%)
Local(Start%%).Who = Nick(0)
Local(Start%%).Rules = G.Rule_Set
Local(Start%%).Score = GrandTotal%
'simple but slow sort
FOR j~%%
= i%%
+ 1 TO 255 IF Online
(j~%%
).Score
< Online
(i~%%
).Score
THEN SWAP Online
(j~%%
), Online
(i~%%
)
Send Client, "[GAME GET]TestScores.txt" 'the command to get the data back from the server.
OK$ = Verify$
'All is good
DataWeGot$
= MID$(OK$
, 5) 'the data is attached after the [OK]. Like this, we got it. DisplayError OK$ 'pop up an error message telling us what went wrong.
END 'However we want to handle an error when trying to put data to the server.
Online(0).Who = Nick$(0)
Online(0).Rules = 0
Online(0).Score = PCU(Who~%%).Total + PCL(who%%).Total
'bump scores down, oldest score falls off. not too keen on this maybe some day
'I could adjust the score file to handle a larger number of scores.
Online(i~%% + 1) = Online(i~%%)
Online(0).Who = ""
Online(0).Rules = 0
Online(0).Score = 0
DataToPut$ = Temp$
'TO PUT INFORMATION TO THE SERVER:
Send Client
, "[GAME PUT]TestScores.TXT" + CHR$(0) + DataToPut$
'put the data to filename.ext on the server OK$ = Verify$
'All is good
DisplayError OK$ 'pop up an error message telling us what went wrong.
END 'However we want to handle an error when trying to put data to the server.
SUB Create_ClickLayer
(Scren%%
) CASE 0 'main game wscreen 'shaker cup
'upper score card
'lower score card
'dice
CASE 1 'upper score card screen LINE (230, 150 + (32 * i%%
) + i%%
)-STEP(63, 31), _RGB32(1 + i%%
, 0, 0), BF
CASE 2 'lower score card screen CASE 4 'Nick name selection screen C%% = C%% + 1
LINE (85 + 35 * j%%
+ j%%
, 158 + 50 * i%%
)-STEP(19, 25), _RGB32(C%%
, 0, 0), BF
C%% = C%% + 1
LINE (85 + 35 * j%%
+ j%%
, 158 + 50 * i%%
)-STEP(19, 25), _RGB32(C%%
, 0, 0), BF
SUB Display_Dice
(X%
, Y%
) IF DieArray
(i%%
+ 1).Locked
= FALSE
THEN _PUTIMAGE (X%
+ i%%
* 60, Y%
)-STEP(52, 50), Layer
(8), Layer
(1), (23 + DieArray
(i%%
+ 1).Value
* 54, 0)-STEP(52, 50) _PUTIMAGE (X%
+ i%%
* 60, Y%
)-STEP(52, 50), Layer
(8), Layer
(1), (23 + DieArray
(i%%
+ 1).Value
* 54, 55)-STEP(52, 50)
SUB Display_UpperCard
(X%
, Y%
, Scale!
, Who~%%
) Display_UpperScores Layer(10), Who~%%
_PUTIMAGE (X%
, Y%
)-STEP(639 * Scale!
, 474 * Scale!
), Layer
(10), Layer
(1)
SUB Display_LowerCard
(X%
, Y%
, Scale!
, Who~%%
) Display_LowerScores Layer(10), Who~%%
_PUTIMAGE (X%
, Y%
)-STEP(639 * Scale!
, 474 * Scale!
), Layer
(10), Layer
(1)
SUB Display_UpperScores
(L&
, Who~%%
)
SUB Display_LowerScores
(L&
, Who~%%
) ' _PRINTSTRING (260 - 12 * (LEN(LTRIM$(STR$(UpperTotal(Who~%%)))) / 1.6), 298), LTRIM$(STR$(UpperTotal(Who~%%))), L&
GrandTotal% = PCU(Who~%%).Total + PCL(who%%).Total
'fill in card
GrandTotal% = PCU(Who~%%).Total + PCL(who%%).Total
' COLOR _RGB32(255)
'display top 5 scores
SUB Place_ShakerCup
(X%
, Y%
)
'Taken from the QB64 Wiki.
DIM Frac_Value
AS LONG: Frac_Value
= Value_From_0_To_1
* 65536 'Used to avoid slow floating point calculations O = Buffer.OFFSET 'We start at this offset
O_Last
= Buffer.OFFSET
+ _WIDTH(Image
) * _HEIGHT(Image
) * 4 'We stop when we get to this offset 'use on error free code ONLY!
O = O + 4
'turn checking back on when done!
DarkenImage tmp&, n!
DarkenImage tmp&, n!
DarkenImage tmp&, n!
DarkenImage tmp&, n!
Display_Offset%% = 0
'setup the static parts of high score list on layer 10---------
_PRINTSTRING (320 - (39 * 4), 38), " Name Rules Score", Layer
(10) '---------------------------------------------------------------
_PUTIMAGE (498, 60 + Display_Offset%%
* 3.8), Layer
(10), Layer
(1), (610, 60)-STEP(20, 60) i%% = j%% + Display_Offset%%
NickString$
= "#" + N$
+ "-" + RTRIM$(Local
(i%%
).Who
) _PRINTSTRING (320 - 39 * 4, 44 + 18 * j%%
), NickString$
, Layer
(1) _PRINTSTRING (472 - 8 * LEN(ScoreString$
), 44 + 18 * j%%
), ScoreString$
, Layer
(1) ClearLayer Layer(1)
Button_Down_Lock
ExitFlag%% = TRUE
Display_Offset%% = Display_Offset%% - 1
Display_Offset%% = Display_Offset%% + 1
IF Display_Offset%%
> 80 THEN Display_Offset%%
= 80 IF Display_Offset%%
< 0 THEN Display_Offset%%
= 0
_FONT FFX&
, Layer
(10) 'restore font to layer 10 ClearLayer Layer(10) 'clean layer 10 up
Display_Offset% = 0
'setup the static parts of high score list on layer 10---------
_PRINTSTRING (320 - (39 * 4), 38), " Name Rules Score", Layer
(10) '---------------------------------------------------------------
_PUTIMAGE (498, 60 + Display_Offset%
* 1.3), Layer
(10), Layer
(1), (610, 60)-STEP(20, 60) I~%% = J~%% + Display_Offset%
NickString$
= "#" + N$
+ "-" + RTRIM$(Online
(I~%%
).Who
) _PRINTSTRING (320 - 39 * 4, 44 + 18 * J~%%
), NickString$
, Layer
(1) _PRINTSTRING (472 - 8 * LEN(ScoreString$
), 44 + 18 * J~%%
), ScoreString$
, Layer
(1) ClearLayer Layer(1)
ExitFlag%% = TRUE
Display_Offset% = Display_Offset% - 1
Display_Offset% = Display_Offset% + 1
IF Display_Offset%
> 235 THEN Display_Offset%
= 235 IF Display_Offset%
< 0 THEN Display_Offset%
= 0
_FONT FFX&
, Layer
(10) 'restore font to layer 10 ClearLayer Layer(10) 'clean layer 10 up
C1~%% = 2.55 * G.BGMVol
C2~%% = 2.55 * G.SFXVol
'-----------Background Music selection---------------
'-----------------------------------------------------
'-------------Hi_lite done button---------------------
'-----------------------------------------------------
_PUTIMAGE (60 + (3 * G.BGMVol
), 128), Layer
(10), Layer
(1), (610, 60)-STEP(20, 60) _PUTIMAGE (60 + (3 * G.SFXVol
), 320), Layer
(10), Layer
(1), (610, 60)-STEP(20, 60)
Sound_Adjust%% = TRUE
Sound_Adjust%% = -2
ExitFlag%% = TRUE
G.Current_BGM = 2
G.Current_BGM = 3
G.Current_BGM = 4
G.Current_BGM = 5
Sound_Adjust%% = FALSE
ClearLayer Layer(1)
FUNCTION LoadFFX&
(Foff&
, Size&
, Fize%%
) LoadFFX&
= _LOADFONT("temp.dat", Fize%%
, "monospace")
SUB LoadData
(Foff&
, Size&
)
SUB DisplayError
(ErrorMessage$
) E$ = ErrorMessage$ 'back up the string so we don't corrupt it any way.
_KEYCLEAR 'clear the buffer before we start accepting stray input as being part of our login
LINE (30, 190)-(90, 225), DarkGray
, BF
LINE (33, 193)-(87, 222), Green
, BF
LINE (111, 190)-(170, 225), DarkGray
, BF
LINE (113, 193)-(167, 222), Red
, BF
ViewWidth
= _WIDTH - 13 - _FONTWIDTH '(_WIDTH -7, -6 from above for our print box area) ViewHeight = 179 - 31 '(again, from the 179, 31 above)
IF U
< 0 THEN U
= 0 'we can't have negative lines to print to!
j1 = 0 'back up to our next valid breakpoint.
j = j - 1: j1 = j1 + 1
CASE " ", ".", ";", "-", "!", "?":
EXIT DO 'valid end of line breaks. IF j1
>= ViewWidth
THEN j
= j
+ j1: j1
= 0 'if we have such a long word that we can't break it
'(perhaps like a html link), then print as much of it on one line as we can and carry on
'with business like usual.
i = i + 1
p1 = (U - i) / 2
FOR p
= 0 TO U
'center the text as much as possible inside our error box
count
= (count
+ 1) MOD 2
oldmouse = mb
count = count + 1
Client
= _OPENCLIENT("TCP/IP:7993:172.93.60.23") 'attempt to join as client OK$ = Verify$
Detail$ = "[ERROR]Host not responding."
LogIn = 0
_KEYCLEAR 'clear the buffer before we start accepting stray input as being part of our login LINE (20, 40)-(180, 200), DarkGray
, BF
LINE (23, 68)-(177, 92), DarkGray
, BF
LINE (23, 128)-(172, 152), DarkGray
, BF
LINE (25, 70)-(175, 90), Black
, BF
LINE (25, 130)-(175, 150), Black
, BF
LINE (20, 210)-(100, 230), DarkGray
, BF
LINE (22, 212)-(98, 228), Green
, BF
LINE (101, 210)-(180, 230), DarkGray
, BF
LINE (103, 212)-(178, 228), Red
, BF
count
= (count
+ 1) MOD 30 CASE 9, 13 'tab or enter to toggle between the two fields. CASE 27 'Escape quits before we login Detail$ = "[ERROR]User Exited Log In Manually"
CASE 32 TO 255 'visable characters
IF my
>= 210 AND my
<= 230 THEN 'we're in the right X/Y position 'Run log in code
Send Client, "[LOG IN]" + n$ + "," + p$ 'Register a new account
OK$ = Verify$
Detail$ = OK$
GOTO function_exit
'Failure 'Run register code
Send Client, "[REGISTER]" + n$ + "," + p$ 'Login from an existing account
OK$ = Verify$
Detail$ = OK$
S = 0
S = -1
oldmouse = mb
function_exit: 'Safely restore our settings.
PlayerName$ = n$
OUT$
= CHR$(2) 'an initial byte to say, "We're sending data."
r$ = r$ + In
In = "" 'Is there a message waiting for us, after we processed one message?
What$
= MID$(r$
, 9) '8 bytes for the length In
= MID$(r$
, length
+ 1)
Receive Client, OK$ 'Get the confirmation message.
_LIMIT 10 'Use low CPU while waiting. No need for a high number here... Be patient and let the server have time to respond. Checking 10 times a second is more than enough to get an [OK] or [ERROR] message. Verify$ = OK$