Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
alsunj
/
blackjack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ce885967
authored
May 02, 2023
by
alsunj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
3c1094d6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
scripts/C#/Gamescripts/DeckScript.cs
scripts/C#/Gamescripts/DeckScript.cs
0 → 100644
View file @
ce885967
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Globalization
;
using
UnityEngine
;
public
class
DeckScript
:
MonoBehaviour
{
// Get cards form unity for what we give them values
public
Sprite
[]
cardSprites
;
// Array for shuffled card values
int
[]
cardValues
=
new
int
[
53
];
int
currentIndex
=
0
;
void
Start
()
{
GetCardValues
();
}
// Update is called once per frame
void
GetCardValues
()
{
int
num
=
0
;
// Loop to assign values
for
(
int
i
=
0
;
i
<
cardSprites
.
Length
;
i
++)
{
num
=
i
;
// Count up to the amount of cards, 52
num
%=
13
;
// Kui kaardi vrtus lheb le 10 siis mra ta 10ks
if
(
num
>
10
||
num
==
0
)
{
num
=
10
;
}
cardValues
[
i
]
=
num
++;
}
}
public
void
Shuffle
()
{
// Tavaline massiivi andmete vahetaja
for
(
int
i
=
cardSprites
.
Length
-
1
;
i
>
0
;
--
i
)
{
int
j
=
Mathf
.
FloorToInt
(
Random
.
Range
(
0.0f
,
1.0f
)
*
(
cardSprites
.
Length
-
1
))
+
1
;
Sprite
face
=
cardSprites
[
i
];
cardSprites
[
i
]
=
cardSprites
[
j
];
cardSprites
[
j
]
=
face
;
int
value
=
cardValues
[
i
];
cardValues
[
i
]
=
cardValues
[
j
];
cardValues
[
j
]
=
value
;
}
currentIndex
=
1
;
}
// give out next card
public
int
DealCard
(
CardScript
cardScript
)
{
cardScript
.
SetSprite
(
cardSprites
[
currentIndex
]);
cardScript
.
SetValue
(
cardValues
[
currentIndex
]);
currentIndex
++;
return
cardScript
.
GetValueOfCard
();
}
public
Sprite
GetCardBack
()
{
return
cardSprites
[
0
];
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment