-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.js
125 lines (100 loc) · 3.14 KB
/
Main.js
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
var board; //this is a 2 dimensional array to represent the game board
var matrixSize; //Stratego games are to be played in 10x10 boards, this should always be initialized to 10
//var myUnits; //An array of the units stored by player1 (person)
//var hisUnits; //An array of the units stored by the computer player
var Units; //stores the list of units for all players
var isSinglePlay = true;
var isPlayer1 = true;
var isPlaying = false;
/*
This runs at program startup
*/
function view_onOpen(){
setupBoard();
loadImages();
boardArea.maxContentItems= 150;
//AddMenuFlip();
//boardArea.contentFlags = gddContentFlagHaveDetails | gddContentFlagManualLayout;
//boardArea.contentFlags = gddContentFlagHaveDetails;
DisplayMainMenu();
};
/**********************************************************
Data initialization
*********************************************************/
/*
After images are loaded and a setup is loaded, computer can take the setup values here
*/
function setupComputerPlayer(playerUnits){
//alert(playerUnits);
Units[1] = new Array(40);
for (var i = 0; i < 40; i++){
Units[1][i] = new soldier(playerUnits[i].value);
Units[1][i].setSoldierLocation(playerUnits[i].x,playerUnits[i].y);
board[Units[1][i].x][Units[1][i].y] = -Units[1][i].value -1;
}
};
function restart(){
//multiplayer
friend_user_id = "";
isReady = false;
isFriendReady = false;
hasSentUnits = false;
numReceivedUnits = 0;
//main
isSinglePlay = true;
isPlayer1 = true;
isPlaying = false;
//turn
totalTurns = 0;
playerTurn = 0; //0 means positive (blue), 1 negative (red)
gameOver = false;
//canResetImg = false;
//setupPage
isWaiting = false;
//displayTurn
isUnitSelected = false;
//ScoreDisplay
isFirstPrint = true;
lblScore.innerText = "";
//BoardFlip
DisableFlip(); //user cannot flip board items at this point
//DisableMenuFlip();
//CancelHandler
isCancelPrompt = false;
lblWarning.innerText = "";
};
/***********************************************************************
Display functions
***********************************************************************/
function DisplayMainMenu(){
restart(); //reset any variables that may have been changed during play
boardArea.removeAllContentItems();
boardArea.contentFlags = gddContentFlagHaveDetails| gddContentFlagManualLayout;
AddButtonImgManual(imgSinglePlay, OnSinglePlay, null, 35, 85, 105, 35 );
AddButtonImgManual(imgMultiPlay, OnMultiPlay, null, 35, 125, 105, 35 );
AddImageManual(imgMain, 35, 0, 105, 65);
};
/***************************************************************
Event handlers
*************************************************************/
/*
Called when the single player button is clicked
*/
function OnSinglePlay(item){
//alert("You chose single player mode");
isSinglePlay = true;
isPlaying = true;
Units = new Array(2);
DisplayAskForDifficulty();
//boardArea.contentFlags = gddContentFlagHaveDetails | gddContentFlagManualLayout;
//drawSetupPage();
};
/*
Called when the multi player button is clicked
*/
function OnMultiPlay(item){
//alert("You chose multi player mode");
isSinglePlay = false;
Units = new Array(2);
DrawFriends();
}