Js Implementation of big turntable lottery game instances

Source: Internet
Author: User

Js Implementation of big turntable lottery game instances

The example in this article describes how js implements a big turntable lottery game. Share it with you for your reference. The specific implementation method is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN"

Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>

<Html xmlns = "http://www.w3.org/1999/xhtml">

<Head>

<Title> js lottery </title>

<Style type = "text/css">

Td {width: 50px; height: 50px; border: 3px solid # ccc; text-align: center; vertical-align: middle}

</Style>

</Head>

<Body>

<Table id = "tb">

<Tr>

<Td> 1 </td> <td> 2 </td> <td> 3 </td> <td> 4 </td> <td> 5 </td>

</Tr>

<Tr>

<Td> 16 </td> <td> 6 </td>

</Tr>

<Tr>

<Td> 15 </td> <td> 7 </td>

</Tr>

<Tr>

<Td> 14 </td> <td> 8 </td>

</Tr>

<Tr>

<Td> 13 </td> <td> 12 </td> <td> 11 </td> <td> 10 </td> <td> 9 </td>

</Tr>

</Table>

<P> </p>

Enter one of the integers from 1 to 16, <input id = "txtnum" value = "12" type = "text"/> <input type = "button" value = "start" onclick = "StartGame "() "/>

<Script type = "text/javascript">

/*

* Delete spaces between the left and right sides.

*/

Function Trim (str ){

Return str. replace (/(^ \ s *) | (\ s * $)/g ,"");

}

/*

* Define an array

*/

Function GetSide (m, n ){

// Initialize the Array

Var arr = [];

For (var I = 0; I <m; I ++ ){

Arr. push ([]);

For (var j = 0; j <n; j ++ ){

Arr [I] [j] = I * n + j;

}

}

// Obtain the outermost circle of the array

Var resultArr = [];

Var tempX = 0,

TempY = 0,

Direction = "Along ",

Count = 0;

While (tempX> = 0 & tempX <n & tempY> = 0 & tempY <m & count <m * n)

{

Count ++;

ResultArr. push ([tempY, tempX]);

If (direction = "Along "){

If (tempX = N-1)

TempY ++;

Else

TempX ++;

If (tempX = n-1 & tempY = m-1)

Direction = "Inverse"

}

Else {

If (tempX = 0)

TempY --;

Else

TempX --;

If (tempX = 0 & tempY = 0)

Break;

}

}

Return resultArr;

}

Var index = 0, // the current position in the bright area

PrevIndex = 0, // the previous position

Speed = 300, // initial Speed

Time, // define the object

Arr = GetSide (5, 5), // initialize the Array

EndIndex = 0, // determines where the speed slows down

Tb = document. getElementById ("tb"), // get the tb object

Cycle = 0, // Number of rotated circles

EndCycle = 0, // calculate the number of circles

Flag = false, // indicates the stop rotation.

Quick = 0; // Acceleration

Function StartGame (){

Cycle = 0;

Flag = false;

EndIndex = Math. floor (Math. random () * 16 );

// EndCycle = Math. floor (Math. random () * 4 );

EndCycle = 1;

Time = setInterval (Star, Speed );

}

Function Star (num ){

// Variable Speed

If (flag = false ){

// Start acceleration in five cells

If (quick = 5 ){

ClearInterval (Time );

Speed = 50;

Time = setInterval (Star, Speed );

}

// Run N laps to slow down

If (cycle = EndCycle + 1 & index = EndIndex ){

ClearInterval (Time );

Speed = 300;

Flag = true; // trigger end

Time = setInterval (Star, Speed );

}

}

If (index> = arr. length ){

Index = 0;

Cycle ++;

}

// Stop turning and select the number

If (flag = true & index = parseInt (Trim (document. getElementById ("txtnum"). value)-1 ){

Quick = 0;

ClearInterval (Time );

}

Tb. rows [arr [index] [0]. cells [arr [index] [1]. style. border = "3px solid red ";

If (index> 0)

PrevIndex = index-1;

Else {

PrevIndex = arr. length-1;

}

Tb. rows [arr [prevIndex] [0]. cells [arr [prevIndex] [1]. style. border = "3px solid # ccc ";

Index ++;

Quick ++;

}

/*

Window. onload = function (){

Time = setInterval (Star, Speed );

}

*/

</Script>

</Body>

</Html>

I hope this article will help you design javascript programs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.